ICU-96 [CODE REVIEW] /* THIS WOULD BE AN API CHANGE - WE HAD TO REMOVE IT FROM COMMON AND PUT IN UCOL.CPP */ We needed u_strncmpCodePointOrder for identical comparison
X-SVN-Rev: 4735
This commit is contained in:
parent
cd8a95d0cf
commit
eb53dfe572
@ -189,29 +189,6 @@ u_strcmp(const UChar *s1,
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
u_strcmpCodePointOrder(const UChar *s1, const UChar *s2);
|
||||
|
||||
|
||||
/**
|
||||
* Compare two Unicode strings in code point order.
|
||||
* This is different in UTF-16 from u_strcmp() if supplementary characters are present:
|
||||
* In UTF-16, supplementary characters (with code points U+10000 and above) are
|
||||
* stored with pairs of surrogate code units. These have values from 0xd800 to
|
||||
* 0xdfff, which means that they compare as less than some other BMP characters
|
||||
* like U+feff. This function compares Unicode strings in code point order.
|
||||
* If eihter of the UTF-16 strings is malformed (i.e., it contains unpaired
|
||||
* surrogates), then the result is not defined.
|
||||
* Compares at most <TT>n</TT> characters.
|
||||
*
|
||||
* @param s1 A string to compare.
|
||||
* @param s2 A string to compare.
|
||||
* @param n The maximum number of characters to compare.
|
||||
* @return a negative/zero/positive integer corresponding to whether
|
||||
* the first string is less than/equal to/greater than the second one
|
||||
* in code point order
|
||||
* @draft
|
||||
*/
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n);
|
||||
|
||||
/**
|
||||
* Compare two ustrings for bitwise equality.
|
||||
* Compares at most <TT>n</TT> characters.
|
||||
|
@ -328,15 +328,14 @@ u_strcmp(const UChar *s1,
|
||||
}
|
||||
}
|
||||
|
||||
static const UChar utf16Fixup[32]={
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0x2000, 0xf800, 0xf800, 0xf800, 0xf800
|
||||
};
|
||||
|
||||
/* String compare in code point order - u_strcmp() compares in code unit order. */
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
u_strcmpCodePointOrder(const UChar *s1, const UChar *s2) {
|
||||
static const UChar utf16Fixup[32]={
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0x2000, 0xf800, 0xf800, 0xf800, 0xf800
|
||||
};
|
||||
UChar c1, c2;
|
||||
int32_t diff;
|
||||
|
||||
@ -357,33 +356,6 @@ u_strcmpCodePointOrder(const UChar *s1, const UChar *s2) {
|
||||
}
|
||||
}
|
||||
|
||||
/* String compare in code point order - u_strcmp() compares in code unit order. */
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n) {
|
||||
UChar c1, c2;
|
||||
int32_t diff;
|
||||
|
||||
/* rotate each code unit's value so that surrogates get the highest values */
|
||||
if(n > 0) {
|
||||
for(;;) {
|
||||
c1=*s1;
|
||||
c1+=utf16Fixup[c1>>11]; /* additional "fix-up" line */
|
||||
c2=*s2;
|
||||
c2+=utf16Fixup[c2>>11]; /* additional "fix-up" line */
|
||||
|
||||
/* now c1 and c2 are in UTF-32-compatible order */
|
||||
diff=(int32_t)c1-(int32_t)c2;
|
||||
if(diff!=0 || --n == 0) {
|
||||
return diff;
|
||||
}
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t
|
||||
u_strncmp(const UChar *s1,
|
||||
const UChar *s2,
|
||||
|
@ -54,11 +54,10 @@ extern "C" UBool checkFCD(const UChar*, int32_t, UErrorCode*);
|
||||
|
||||
/* Fixup table a la Markus */
|
||||
/* see http://www.ibm.com/software/developer/library/utf16.html for further explanation */
|
||||
static uint8_t utf16fixup[32] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0x20, 0xf8, 0xf8, 0xf8, 0xf8
|
||||
static const UChar utf16Fixup[32]={
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0x2000, 0xf800, 0xf800, 0xf800, 0xf800
|
||||
};
|
||||
|
||||
static UBool U_CALLCONV
|
||||
@ -4342,6 +4341,32 @@ U_CAPI UBool isTailored(const UCollator *coll, const UChar u, UErrorCode *status
|
||||
}
|
||||
}
|
||||
|
||||
/* String compare in code point order - u_strcmp() compares in code unit order. */
|
||||
U_CFUNC int32_t
|
||||
u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n) {
|
||||
UChar c1, c2;
|
||||
int32_t diff;
|
||||
|
||||
/* rotate each code unit's value so that surrogates get the highest values */
|
||||
if(n > 0) {
|
||||
for(;;) {
|
||||
c1=*s1;
|
||||
c1+=utf16Fixup[c1>>11]; /* additional "fix-up" line */
|
||||
c2=*s2;
|
||||
c2+=utf16Fixup[c2>>11]; /* additional "fix-up" line */
|
||||
|
||||
/* now c1 and c2 are in UTF-32-compatible order */
|
||||
diff=(int32_t)c1-(int32_t)c2;
|
||||
if(diff!=0 || --n == 0) {
|
||||
return diff;
|
||||
}
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user