ICU-1036 use new internal case mapping functions

X-SVN-Rev: 8128
This commit is contained in:
Alan Liu 2002-03-19 22:09:07 +00:00
parent ab87e7e116
commit 7b4512d90f
2 changed files with 28 additions and 22 deletions

View File

@ -75,32 +75,35 @@ void LowercaseTransliterator::handleTransliterate(Replaceable& text,
UnicodeString original;
text.extractBetween(offsets.contextStart, offsets.contextLimit, original);
UCharIterator iter;
uiter_setReplaceable(&iter, &text);
iter.start = offsets.contextStart;
iter.limit = offsets.contextLimit;
// Walk through original string
// If there is a case change, modify corresponding position in replaceable
int32_t i = textPos - offsets.contextStart;
int32_t limit = offsets.limit - offsets.contextStart;
UChar32 cp, bufferCH;
UChar32 cp;
int32_t oldLen;
for (; i < limit; ) {
UErrorCode status = U_ZERO_ERROR;
int32_t s = i;
bufferCH = original.char32At(s);
UTF_GET_CHAR(original.getBuffer(), 0, i, original.length(), cp);
oldLen = UTF_CHAR_LENGTH(cp);
i += oldLen;
int32_t len = u_strToLower(buffer, u_getMaxCaseExpansion(), original.getBuffer()+s, i-s, loc.getName(), &status);
/* Skip checking of status code here because the buffer should not have overflowed. */
UTF_GET_CHAR(buffer, 0, 0, len, cp);
if ( bufferCH != cp ) {
UnicodeString temp(buffer);
iter.index = i; // Point _past_ current char
int32_t newLen = u_internalToLower(cp, &iter, buffer, u_getMaxCaseExpansion(), loc.getName());
if (newLen >= 0) {
UnicodeString temp(buffer, newLen);
text.handleReplaceBetween(textPos, textPos + oldLen, temp);
if (len != oldLen) {
textPos += len;
offsets.limit += len - oldLen;
offsets.contextLimit += len - oldLen;
if (newLen != oldLen) {
textPos += newLen;
offsets.limit += newLen - oldLen;
offsets.contextLimit += newLen - oldLen;
continue;
}
}

View File

@ -77,33 +77,36 @@ void UppercaseTransliterator::handleTransliterate(Replaceable& text,
UnicodeString original;
text.extractBetween(offsets.contextStart, offsets.contextLimit, original);
UCharIterator iter;
uiter_setReplaceable(&iter, &text);
iter.start = offsets.contextStart;
iter.limit = offsets.contextLimit;
// Walk through original string
// If there is a case change, modify corresponding position in replaceable
int32_t i = textPos - offsets.contextStart;
int32_t limit = offsets.limit - offsets.contextStart;
UChar32 cp, bufferCH;
UChar32 cp;
int32_t oldLen;
for (; i < limit; ) {
UErrorCode status = U_ZERO_ERROR;
int32_t s = i;
bufferCH = original.char32At(s);
UTF_GET_CHAR(original.getBuffer(), 0, i, original.length(), cp);
oldLen = UTF_CHAR_LENGTH(cp);
i += oldLen;
int32_t len = u_strToUpper(buffer, u_getMaxCaseExpansion(), original.getBuffer()+s, i-s, loc.getName(), &status);
/* Skip checking of status code here because the buffer should not have overflowed. */
UTF_GET_CHAR(buffer, 0, 0, len, cp);
if (bufferCH != cp) {
UnicodeString temp(buffer);
iter.index = i; // Point _past_ current char
int32_t newLen = u_internalToUpper(cp, &iter, buffer, u_getMaxCaseExpansion(), loc.getName());
if (newLen >= 0) {
UnicodeString temp(buffer, newLen);
text.handleReplaceBetween(textPos, textPos + oldLen, temp);
if (len != oldLen) {
textPos += len;
offsets.limit += len - oldLen;
offsets.contextLimit += len - oldLen;
if (newLen != oldLen) {
textPos += newLen;
offsets.limit += newLen - oldLen;
offsets.contextLimit += newLen - oldLen;
continue;
}
}