ICU-1036 simplify internal string case mapping functions for more common code - remove growBuffer

X-SVN-Rev: 7717
This commit is contained in:
Markus Scherer 2002-02-20 02:09:42 +00:00
parent 4da9ea84da
commit 1ef813cb29
3 changed files with 41 additions and 51 deletions

View File

@ -2729,12 +2729,6 @@ private:
int32_t **pBufferToDelete = 0,
UBool forceClone = FALSE);
// UGrowBuffer function for string case mapping and similar
static UBool U_CALLCONV
growBuffer(void *context,
UChar **buffer, int32_t *pCapacity, int32_t reqCapacity,
int32_t length);
// common function for case mappings
UnicodeString &
caseMap(const Locale& locale,

View File

@ -1039,23 +1039,6 @@ UnicodeString::foldCase(uint32_t options) {
return caseMap(Locale::getDefault(), options, FOLD_CASE);
}
// static helper function for string case mapping
// called by u_internalStrToUpper/Lower()
UBool U_CALLCONV
UnicodeString::growBuffer(void *context,
UChar **buffer, int32_t *pCapacity, int32_t reqCapacity,
int32_t length) {
UnicodeString *me = (UnicodeString *)context;
me->fLength = length;
if(me->cloneArrayIfNeeded(reqCapacity)) {
*buffer = me->fArray;
*pCapacity = me->fCapacity;
return TRUE;
} else {
return FALSE;
}
}
UnicodeString &
UnicodeString::caseMap(const Locale& locale,
uint32_t options,
@ -1082,32 +1065,33 @@ UnicodeString::caseMap(const Locale& locale,
capacity = US_STACKBUF_SIZE;
}
} else {
capacity = fLength + 2;
capacity = fLength + 20;
}
if(!cloneArrayIfNeeded(capacity, capacity, FALSE, &bufferToDelete, TRUE)) {
return *this;
}
UErrorCode errorCode = U_ZERO_ERROR;
if(toWhichCase==TO_LOWER) {
fLength = u_internalStrToLower(fArray, fCapacity,
oldArray, oldLength,
locale.getName(),
growBuffer, this,
&errorCode);
} else if(toWhichCase==TO_UPPER) {
fLength = u_internalStrToUpper(fArray, fCapacity,
oldArray, oldLength,
locale.getName(),
growBuffer, this,
&errorCode);
} else {
fLength = u_internalStrFoldCase(fArray, fCapacity,
oldArray, oldLength,
options,
growBuffer, this,
&errorCode);
}
// Case-map, and if the result is too long, then reallocate and repeat.
UErrorCode errorCode;
do {
errorCode = U_ZERO_ERROR;
if(toWhichCase==TO_LOWER) {
fLength = u_internalStrToLower(fArray, fCapacity,
oldArray, oldLength,
locale.getName(),
&errorCode);
} else if(toWhichCase==TO_UPPER) {
fLength = u_internalStrToUpper(fArray, fCapacity,
oldArray, oldLength,
locale.getName(),
&errorCode);
} else {
fLength = u_internalStrFoldCase(fArray, fCapacity,
oldArray, oldLength,
options,
&errorCode);
}
} while(errorCode==U_BUFFER_OVERFLOW_ERROR && cloneArrayIfNeeded(fLength, fLength, FALSE));
delete [] bufferToDelete;
if(U_FAILURE(errorCode)) {

View File

@ -684,13 +684,13 @@ u_strCaseMap(UChar *dest, int32_t destCapacity,
if(toWhichCase==TO_LOWER) {
destLength=u_internalStrToLower(temp, destCapacity, src, srcLength,
locale, NULL, NULL, pErrorCode);
locale, pErrorCode);
} else if(toWhichCase==TO_UPPER) {
destLength=u_internalStrToUpper(temp, destCapacity, src, srcLength,
locale, NULL, NULL, pErrorCode);
locale, pErrorCode);
} else {
destLength=u_internalStrFoldCase(temp, destCapacity, src, srcLength,
options, NULL, NULL, pErrorCode);
options, pErrorCode);
}
if(temp!=dest) {
/* copy the result string to the destination buffer */
@ -770,7 +770,10 @@ u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options) {
c=UTF16_GET_PAIR_VALUE(c, uc);
++s1;
}
len1=u_internalFoldCase(c, t1, options);
len1=u_internalFoldCase(c, t1, 32, options);
if(len1<0) {
len1=-len1;
}
pos1=0;
} else if(pos2>=len2 && *s2==0) {
return 0;
@ -785,7 +788,10 @@ u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options) {
c=UTF16_GET_PAIR_VALUE(c, uc);
++s2;
}
len2=u_internalFoldCase(c, t2, options);
len2=u_internalFoldCase(c, t2, 32, options);
if(len2<0) {
len2=-len2;
}
pos2=0;
} else {
return 1;
@ -855,7 +861,10 @@ u_internalStrcasecmp(const UChar *s1, int32_t length1,
} else {
--length1;
}
len1=u_internalFoldCase(c, t1, options);
len1=u_internalFoldCase(c, t1, 32, options);
if(len1<0) {
len1=-len1;
}
pos1=0;
} else if(pos2>=len2 && length2<=0) {
return 0;
@ -873,7 +882,10 @@ u_internalStrcasecmp(const UChar *s1, int32_t length1,
} else {
--length2;
}
len2=u_internalFoldCase(c, t2, options);
len2=u_internalFoldCase(c, t2, 32, options);
if(len2<0) {
len2=-len2;
}
pos2=0;
} else {
return 1;