X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..2ca993e82fb37b597a3c73ecd1586a139a6579c5:/icuSources/common/unorm.cpp diff --git a/icuSources/common/unorm.cpp b/icuSources/common/unorm.cpp index 8b685ea6..f0a026f6 100644 --- a/icuSources/common/unorm.cpp +++ b/icuSources/common/unorm.cpp @@ -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 */