]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/unorm.cpp
ICU-551.24.tar.gz
[apple/icu.git] / icuSources / common / unorm.cpp
index 8b685ea600f7aa7c709329d19fef1c69aeba03bb..f0a026f66961242815dc3cac9bde2e08a8a631ec 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ******************************************************************************
-* Copyright (c) 1996-2010, International Business Machines
+* Copyright (c) 1996-2014, International Business Machines
 * Corporation and others. All Rights Reserved.
 ******************************************************************************
 * File unorm.cpp
@@ -37,8 +37,6 @@
 #include "uprops.h"
 #include "ustr_imp.h"
 
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
 U_NAMESPACE_USE
 
 /* quick check functions ---------------------------------------------------- */
@@ -114,28 +112,15 @@ unorm_normalize(const UChar *src, int32_t srcLength,
 /* iteration functions ------------------------------------------------------ */
 
 static int32_t
-unorm_iterate(UCharIterator *src, UBool forward,
+_iterate(UCharIterator *src, UBool forward,
               UChar *dest, int32_t destCapacity,
-              UNormalizationMode mode, int32_t options,
+              const Normalizer2 *n2,
               UBool doNormalize, UBool *pNeededToNormalize,
               UErrorCode *pErrorCode) {
-    const Normalizer2 *n2=Normalizer2Factory::getInstance(mode, *pErrorCode);
-    const UnicodeSet *uni32;
-    if(options&UNORM_UNICODE_3_2) {
-        uni32=uniset_getUnicode32Instance(*pErrorCode);
-    } else {
-        uni32=NULL;  // unused
-    }
-    FilteredNormalizer2 fn2(*n2, *uni32);
-    if(options&UNORM_UNICODE_3_2) {
-        n2=&fn2;
-    }
     if(U_FAILURE(*pErrorCode)) {
         return 0;
     }
-    if( destCapacity<0 || (dest==NULL && destCapacity>0) ||
-        src==NULL
-    ) {
+    if(destCapacity<0 || (dest==NULL && destCapacity>0) || src==NULL) {
         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
         return 0;
     }
@@ -186,6 +171,26 @@ unorm_iterate(UCharIterator *src, UBool forward,
     }
 }
 
+static int32_t
+unorm_iterate(UCharIterator *src, UBool forward,
+              UChar *dest, int32_t destCapacity,
+              UNormalizationMode mode, int32_t options,
+              UBool doNormalize, UBool *pNeededToNormalize,
+              UErrorCode *pErrorCode) {
+    const Normalizer2 *n2=Normalizer2Factory::getInstance(mode, *pErrorCode);
+    if(options&UNORM_UNICODE_3_2) {
+        const UnicodeSet *uni32 = uniset_getUnicode32Instance(*pErrorCode);
+        if(U_FAILURE(*pErrorCode)) {
+            return 0;
+        }
+        FilteredNormalizer2 fn2(*n2, *uni32);
+        return _iterate(src, forward, dest, destCapacity,
+            &fn2, doNormalize, pNeededToNormalize, pErrorCode);
+    }
+    return _iterate(src, forward, dest, destCapacity,
+            n2, doNormalize, pNeededToNormalize, pErrorCode);
+}
+
 U_CAPI int32_t U_EXPORT2
 unorm_previous(UCharIterator *src,
                UChar *dest, int32_t destCapacity,
@@ -214,30 +219,17 @@ unorm_next(UCharIterator *src,
 
 /* Concatenation of normalized strings -------------------------------------- */
 
-U_CAPI int32_t U_EXPORT2
-unorm_concatenate(const UChar *left, int32_t leftLength,
+static int32_t
+_concatenate(const UChar *left, int32_t leftLength,
                   const UChar *right, int32_t rightLength,
                   UChar *dest, int32_t destCapacity,
-                  UNormalizationMode mode, int32_t options,
+                  const Normalizer2 *n2,
                   UErrorCode *pErrorCode) {
-    const Normalizer2 *n2=Normalizer2Factory::getInstance(mode, *pErrorCode);
-    const UnicodeSet *uni32;
-    if(options&UNORM_UNICODE_3_2) {
-        uni32=uniset_getUnicode32Instance(*pErrorCode);
-    } else {
-        uni32=NULL;  // unused
-    }
-    FilteredNormalizer2 fn2(*n2, *uni32);
-    if(options&UNORM_UNICODE_3_2) {
-        n2=&fn2;
-    }
     if(U_FAILURE(*pErrorCode)) {
         return 0;
     }
-    if( destCapacity<0 || (dest==NULL && destCapacity>0) ||
-        left==NULL || leftLength<-1 ||
-        right==NULL || rightLength<-1
-    ) {
+    if(destCapacity<0 || (dest==NULL && destCapacity>0) ||
+        left==NULL || leftLength<-1 || right==NULL || rightLength<-1) {
         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
         return 0;
     }
@@ -263,4 +255,24 @@ unorm_concatenate(const UChar *left, int32_t leftLength,
            extract(dest, destCapacity, *pErrorCode);
 }
 
+U_CAPI int32_t U_EXPORT2
+unorm_concatenate(const UChar *left, int32_t leftLength,
+                  const UChar *right, int32_t rightLength,
+                  UChar *dest, int32_t destCapacity,
+                  UNormalizationMode mode, int32_t options,
+                  UErrorCode *pErrorCode) {
+    const Normalizer2 *n2=Normalizer2Factory::getInstance(mode, *pErrorCode);
+    if(options&UNORM_UNICODE_3_2) {
+        const UnicodeSet *uni32 = uniset_getUnicode32Instance(*pErrorCode);
+        if(U_FAILURE(*pErrorCode)) {
+            return 0;
+        }
+        FilteredNormalizer2 fn2(*n2, *uni32);
+        return _concatenate(left, leftLength, right, rightLength,
+            dest, destCapacity, &fn2, pErrorCode);
+    }
+    return _concatenate(left, leftLength, right, rightLength,
+        dest, destCapacity, n2, pErrorCode);
+}
+
 #endif /* #if !UCONFIG_NO_NORMALIZATION */