Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / icu / source / common / ubrk.cpp
index b3e8a61..a0002c2 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ********************************************************************************
-*   Copyright (C) 1996-2008, International Business Machines
+*   Copyright (C) 1996-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ********************************************************************************
 */
@@ -123,25 +123,31 @@ ubrk_openRules(  const UChar        *rules,
 U_CAPI UBreakIterator * U_EXPORT2
 ubrk_safeClone(
           const UBreakIterator *bi,
-          void *stackBuffer,
+          void * /*stackBuffer*/,
           int32_t *pBufferSize,
           UErrorCode *status)
 {
     if (status == NULL || U_FAILURE(*status)){
-        return 0;
+        return NULL;
     }
-    if (!pBufferSize || !bi){
+    if (bi == NULL) {
        *status = U_ILLEGAL_ARGUMENT_ERROR;
-        return 0;
+        return NULL;
+    }
+    if (pBufferSize != NULL) {
+        int32_t inputSize = *pBufferSize;
+        *pBufferSize = 1;
+        if (inputSize == 0) {
+            return NULL;  // preflighting for deprecated functionality
+        }
     }
-    // Clear any incoming Safe Clone Allocated warning.
-    //  Propagating this through to our return would really
-    //  confuse our caller.
-    if (*status==U_SAFECLONE_ALLOCATED_WARNING) {
-        *status = U_ZERO_ERROR;
+    BreakIterator *newBI = ((BreakIterator *)bi)->clone();
+    if (newBI == NULL) {
+        *status = U_MEMORY_ALLOCATION_ERROR;
+    } else {
+        *status = U_SAFECLONE_ALLOCATED_WARNING;
     }
-    return (UBreakIterator *)(((BreakIterator*)bi)->
-        createBufferClone(stackBuffer, *pBufferSize, *status));
+    return (UBreakIterator *)newBI;
 }
 
 
@@ -149,15 +155,7 @@ ubrk_safeClone(
 U_CAPI void U_EXPORT2
 ubrk_close(UBreakIterator *bi)
 {
-    BreakIterator *ubi = (BreakIterator*) bi;
-    if (ubi) {
-        if (ubi->isBufferClone()) {
-            ubi->~BreakIterator();
-            *(uint32_t *)ubi = 0xdeadbeef;
-        } else {
-            delete ubi;
-        }
-    }
+    delete (BreakIterator *)bi;
 }
 
 U_CAPI void U_EXPORT2
@@ -166,18 +164,11 @@ ubrk_setText(UBreakIterator* bi,
              int32_t         textLength,
              UErrorCode*     status)
 {
-    if (bi == NULL) {
-        if (U_SUCCESS(*status)) {
-            *status = U_ILLEGAL_ARGUMENT_ERROR;
-        }
-        return;
-    }
-
     BreakIterator *brit = (BreakIterator *)bi;
     UText  ut = UTEXT_INITIALIZER;
     utext_openUChars(&ut, text, textLength, status);
     brit->setText(&ut, *status);
-    // A stack allocated UText wrapping a UCHar * string
+    // A stack allocated UText wrapping a UChar * string
     //   can be dumped without explicitly closing it.
 }
 
@@ -188,13 +179,6 @@ ubrk_setUText(UBreakIterator *bi,
              UText          *text,
              UErrorCode     *status)
 {
-    if (bi == NULL) {
-        if (U_SUCCESS(*status)) {
-            *status = U_ILLEGAL_ARGUMENT_ERROR;
-        }
-        return;
-    }
-
     RuleBasedBreakIterator *brit = (RuleBasedBreakIterator *)bi;
     brit->RuleBasedBreakIterator::setText(text, *status);
 }
@@ -304,4 +288,14 @@ ubrk_getLocaleByType(const UBreakIterator *bi,
 }
 
 
+void ubrk_refreshUText(UBreakIterator *bi,
+                       UText          *text,
+                       UErrorCode     *status)
+{
+    BreakIterator *bii = reinterpret_cast<BreakIterator *>(bi);
+    bii->refreshInputText(text, *status);
+}
+
+
+
 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */