]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/uenum.c
ICU-8.11.4.tar.gz
[apple/icu.git] / icuSources / common / uenum.c
index 26fb812496ec8e8ea94e97786fa63b942d71eed8..549769c449df2758248dd0ec2c428b01d21309fa 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2002, International Business Machines
+*   Copyright (C) 2002-2004, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -14,6 +14,7 @@
 *   created by: Vladimir Weinstein
 */
 
+#include "unicode/putil.h"
 #include "uenumimp.h"
 #include "cmemory.h"
 
@@ -87,24 +88,25 @@ uenum_unextDefault(UEnumeration* en,
             int32_t* resultLength,
             UErrorCode* status)
 {
+    UChar *ustr = NULL;
+    int32_t len = 0;
     if (en->next != NULL) {
-        UChar *tempUCharVal;
-        const char *tempCharVal = en->next(en, resultLength, status);
-               if (tempCharVal == NULL) {
-                   return NULL;
-               }
-        tempUCharVal = (UChar*)
-            _getBuffer(en, (*resultLength+1) * sizeof(UChar));
-        if (!tempUCharVal) {
-            *status = U_MEMORY_ALLOCATION_ERROR;
-            return NULL;
+        const char *cstr = en->next(en, &len, status);
+        if (cstr != NULL) {
+            ustr = (UChar*) _getBuffer(en, (len+1) * sizeof(UChar));
+            if (ustr == NULL) {
+                *status = U_MEMORY_ALLOCATION_ERROR;
+            } else {
+                u_charsToUChars(cstr, ustr, len+1);
+            }
         }
-        u_charsToUChars(tempCharVal, tempUCharVal, *resultLength + 1);
-        return tempUCharVal;
     } else {
         *status = U_UNSUPPORTED_ERROR;
-        return NULL;
     }
+    if (resultLength) {
+        *resultLength = len;
+    }
+    return ustr;
 }
 
 /* Don't call this directly. Only uenum_next should be calling this. */
@@ -116,9 +118,9 @@ uenum_nextDefault(UEnumeration* en,
     if (en->uNext != NULL) {
         char *tempCharVal;
         const UChar *tempUCharVal = en->uNext(en, resultLength, status);
-               if (tempUCharVal == NULL) {
-                   return NULL;
-               }
+        if (tempUCharVal == NULL) {
+            return NULL;
+        }
         tempCharVal = (char*)
             _getBuffer(en, (*resultLength+1) * sizeof(char));
         if (!tempCharVal) {