aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/common/ucasemap.cpp
diff options
context:
space:
mode:
authormcheshkov <mcheshkov@yandex-team.ru>2022-02-10 16:46:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:15 +0300
commite9d19cec64684c9c1e6b0c98297e5b895cf904fe (patch)
tree2768b1223e96a8a0610a93d18425d9647c1123c8 /contrib/libs/icu/common/ucasemap.cpp
parent60040c91ffe701a84689b2c6310ff845e65cff42 (diff)
downloadydb-e9d19cec64684c9c1e6b0c98297e5b895cf904fe.tar.gz
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/icu/common/ucasemap.cpp')
-rw-r--r--contrib/libs/icu/common/ucasemap.cpp1168
1 files changed, 584 insertions, 584 deletions
diff --git a/contrib/libs/icu/common/ucasemap.cpp b/contrib/libs/icu/common/ucasemap.cpp
index ed72bda828..d78702cd6f 100644
--- a/contrib/libs/icu/common/ucasemap.cpp
+++ b/contrib/libs/icu/common/ucasemap.cpp
@@ -1,4 +1,4 @@
-// © 2016 and later: Unicode, Inc. and others.
+// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
@@ -8,7 +8,7 @@
*
*******************************************************************************
* file name: ucasemap.cpp
-* encoding: UTF-8
+* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
@@ -20,11 +20,11 @@
#include "unicode/utypes.h"
#include "unicode/brkiter.h"
-#include "unicode/bytestream.h"
-#include "unicode/casemap.h"
-#include "unicode/edits.h"
-#include "unicode/stringoptions.h"
-#include "unicode/stringpiece.h"
+#include "unicode/bytestream.h"
+#include "unicode/casemap.h"
+#include "unicode/edits.h"
+#include "unicode/stringoptions.h"
+#include "unicode/stringpiece.h"
#include "unicode/ubrk.h"
#include "unicode/uloc.h"
#include "unicode/ustring.h"
@@ -35,43 +35,43 @@
#include "unicode/utf.h"
#include "unicode/utf8.h"
#include "unicode/utf16.h"
-#include "bytesinkutil.h"
+#include "bytesinkutil.h"
#include "cmemory.h"
#include "cstring.h"
-#include "uassert.h"
+#include "uassert.h"
#include "ucase.h"
-#include "ucasemap_imp.h"
+#include "ucasemap_imp.h"
#include "ustr_imp.h"
U_NAMESPACE_USE
/* UCaseMap service object -------------------------------------------------- */
-UCaseMap::UCaseMap(const char *localeID, uint32_t opts, UErrorCode *pErrorCode) :
-#if !UCONFIG_NO_BREAK_ITERATION
- iter(NULL),
-#endif
- caseLocale(UCASE_LOC_UNKNOWN), options(opts) {
- ucasemap_setLocale(this, localeID, pErrorCode);
-}
-
-UCaseMap::~UCaseMap() {
-#if !UCONFIG_NO_BREAK_ITERATION
- delete iter;
-#endif
-}
-
+UCaseMap::UCaseMap(const char *localeID, uint32_t opts, UErrorCode *pErrorCode) :
+#if !UCONFIG_NO_BREAK_ITERATION
+ iter(NULL),
+#endif
+ caseLocale(UCASE_LOC_UNKNOWN), options(opts) {
+ ucasemap_setLocale(this, localeID, pErrorCode);
+}
+
+UCaseMap::~UCaseMap() {
+#if !UCONFIG_NO_BREAK_ITERATION
+ delete iter;
+#endif
+}
+
U_CAPI UCaseMap * U_EXPORT2
ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode) {
if(U_FAILURE(*pErrorCode)) {
return NULL;
}
- UCaseMap *csm = new UCaseMap(locale, options, pErrorCode);
+ UCaseMap *csm = new UCaseMap(locale, options, pErrorCode);
if(csm==NULL) {
- *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ *pErrorCode = U_MEMORY_ALLOCATION_ERROR;
return NULL;
- } else if (U_FAILURE(*pErrorCode)) {
- delete csm;
+ } else if (U_FAILURE(*pErrorCode)) {
+ delete csm;
return NULL;
}
return csm;
@@ -79,7 +79,7 @@ ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode) {
U_CAPI void U_EXPORT2
ucasemap_close(UCaseMap *csm) {
- delete csm;
+ delete csm;
}
U_CAPI const char * U_EXPORT2
@@ -97,13 +97,13 @@ ucasemap_setLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode) {
if(U_FAILURE(*pErrorCode)) {
return;
}
- if (locale != NULL && *locale == 0) {
- csm->locale[0] = 0;
- csm->caseLocale = UCASE_LOC_ROOT;
- return;
- }
+ if (locale != NULL && *locale == 0) {
+ csm->locale[0] = 0;
+ csm->caseLocale = UCASE_LOC_ROOT;
+ return;
+ }
- int32_t length=uloc_getName(locale, csm->locale, (int32_t)sizeof(csm->locale), pErrorCode);
+ int32_t length=uloc_getName(locale, csm->locale, (int32_t)sizeof(csm->locale), pErrorCode);
if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR || length==sizeof(csm->locale)) {
*pErrorCode=U_ZERO_ERROR;
/* we only really need the language code for case mappings */
@@ -113,59 +113,59 @@ ucasemap_setLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode) {
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
}
if(U_SUCCESS(*pErrorCode)) {
- csm->caseLocale=UCASE_LOC_UNKNOWN;
- csm->caseLocale = ucase_getCaseLocale(csm->locale);
+ csm->caseLocale=UCASE_LOC_UNKNOWN;
+ csm->caseLocale = ucase_getCaseLocale(csm->locale);
} else {
csm->locale[0]=0;
- csm->caseLocale = UCASE_LOC_ROOT;
+ csm->caseLocale = UCASE_LOC_ROOT;
}
}
U_CAPI void U_EXPORT2
-ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode) {
- if(U_FAILURE(*pErrorCode)) {
- return;
- }
+ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode) {
+ if(U_FAILURE(*pErrorCode)) {
+ return;
+ }
csm->options=options;
}
/* UTF-8 string case mappings ----------------------------------------------- */
-/* TODO(markus): Move to a new, separate utf8case.cpp file. */
-
-namespace {
+/* TODO(markus): Move to a new, separate utf8case.cpp file. */
+namespace {
+
/* append a full case mapping result, see UCASE_MAX_STRING_LENGTH */
-inline UBool
-appendResult(int32_t cpLength, int32_t result, const UChar *s,
- ByteSink &sink, uint32_t options, icu::Edits *edits, UErrorCode &errorCode) {
- U_ASSERT(U_SUCCESS(errorCode));
+inline UBool
+appendResult(int32_t cpLength, int32_t result, const UChar *s,
+ ByteSink &sink, uint32_t options, icu::Edits *edits, UErrorCode &errorCode) {
+ U_ASSERT(U_SUCCESS(errorCode));
/* decode the result */
if(result<0) {
/* (not) original code point */
- if(edits!=NULL) {
- edits->addUnchanged(cpLength);
- }
- if((options & U_OMIT_UNCHANGED_TEXT) == 0) {
- ByteSinkUtil::appendCodePoint(cpLength, ~result, sink);
+ if(edits!=NULL) {
+ edits->addUnchanged(cpLength);
}
+ if((options & U_OMIT_UNCHANGED_TEXT) == 0) {
+ ByteSinkUtil::appendCodePoint(cpLength, ~result, sink);
+ }
} else {
- if(result<=UCASE_MAX_STRING_LENGTH) {
- // string: "result" is the UTF-16 length
- return ByteSinkUtil::appendChange(cpLength, s, result, sink, edits, errorCode);
+ if(result<=UCASE_MAX_STRING_LENGTH) {
+ // string: "result" is the UTF-16 length
+ return ByteSinkUtil::appendChange(cpLength, s, result, sink, edits, errorCode);
} else {
- ByteSinkUtil::appendCodePoint(cpLength, result, sink, edits);
+ ByteSinkUtil::appendCodePoint(cpLength, result, sink, edits);
}
}
- return TRUE;
+ return TRUE;
}
-// See unicode/utf8.h U8_APPEND_UNSAFE().
-inline uint8_t getTwoByteLead(UChar32 c) { return (uint8_t)((c >> 6) | 0xc0); }
-inline uint8_t getTwoByteTrail(UChar32 c) { return (uint8_t)((c & 0x3f) | 0x80); }
+// See unicode/utf8.h U8_APPEND_UNSAFE().
+inline uint8_t getTwoByteLead(UChar32 c) { return (uint8_t)((c >> 6) | 0xc0); }
+inline uint8_t getTwoByteTrail(UChar32 c) { return (uint8_t)((c & 0x3f) | 0x80); }
-UChar32 U_CALLCONV
+UChar32 U_CALLCONV
utf8_caseContextIterator(void *context, int8_t dir) {
UCaseContext *csc=(UCaseContext *)context;
UChar32 c;
@@ -197,290 +197,290 @@ utf8_caseContextIterator(void *context, int8_t dir) {
return U_SENTINEL;
}
-/**
- * caseLocale >= 0: Lowercases [srcStart..srcLimit[ but takes context [0..srcLength[ into account.
- * caseLocale < 0: Case-folds [srcStart..srcLimit[.
+/**
+ * caseLocale >= 0: Lowercases [srcStart..srcLimit[ but takes context [0..srcLength[ into account.
+ * caseLocale < 0: Case-folds [srcStart..srcLimit[.
*/
-void toLower(int32_t caseLocale, uint32_t options,
- const uint8_t *src, UCaseContext *csc, int32_t srcStart, int32_t srcLimit,
- icu::ByteSink &sink, icu::Edits *edits, UErrorCode &errorCode) {
- const int8_t *latinToLower;
- if (caseLocale == UCASE_LOC_ROOT ||
- (caseLocale >= 0 ?
- !(caseLocale == UCASE_LOC_TURKISH || caseLocale == UCASE_LOC_LITHUANIAN) :
- (options & _FOLD_CASE_OPTIONS_MASK) == U_FOLD_CASE_DEFAULT)) {
- latinToLower = LatinCase::TO_LOWER_NORMAL;
- } else {
- latinToLower = LatinCase::TO_LOWER_TR_LT;
- }
- const UTrie2 *trie = ucase_getTrie();
- int32_t prev = srcStart;
- int32_t srcIndex = srcStart;
- for (;;) {
- // fast path for simple cases
- int32_t cpStart;
- UChar32 c;
- for (;;) {
- if (U_FAILURE(errorCode) || srcIndex >= srcLimit) {
- c = U_SENTINEL;
- break;
- }
- uint8_t lead = src[srcIndex++];
- if (lead <= 0x7f) {
- int8_t d = latinToLower[lead];
- if (d == LatinCase::EXC) {
- cpStart = srcIndex - 1;
- c = lead;
- break;
- }
- if (d == 0) { continue; }
- ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev,
- sink, options, edits, errorCode);
- char ascii = (char)(lead + d);
- sink.Append(&ascii, 1);
- if (edits != nullptr) {
- edits->addReplace(1, 1);
- }
- prev = srcIndex;
- continue;
- } else if (lead < 0xe3) {
- uint8_t t;
- if (0xc2 <= lead && lead <= 0xc5 && srcIndex < srcLimit &&
- (t = src[srcIndex] - 0x80) <= 0x3f) {
- // U+0080..U+017F
- ++srcIndex;
- c = ((lead - 0xc0) << 6) | t;
- int8_t d = latinToLower[c];
- if (d == LatinCase::EXC) {
- cpStart = srcIndex - 2;
- break;
- }
- if (d == 0) { continue; }
- ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 2 - prev,
- sink, options, edits, errorCode);
- ByteSinkUtil::appendTwoBytes(c + d, sink);
- if (edits != nullptr) {
- edits->addReplace(2, 2);
- }
- prev = srcIndex;
- continue;
- }
- } else if ((lead <= 0xe9 || lead == 0xeb || lead == 0xec) &&
- (srcIndex + 2) <= srcLimit &&
- U8_IS_TRAIL(src[srcIndex]) && U8_IS_TRAIL(src[srcIndex + 1])) {
- // most of CJK: no case mappings
- srcIndex += 2;
- continue;
+void toLower(int32_t caseLocale, uint32_t options,
+ const uint8_t *src, UCaseContext *csc, int32_t srcStart, int32_t srcLimit,
+ icu::ByteSink &sink, icu::Edits *edits, UErrorCode &errorCode) {
+ const int8_t *latinToLower;
+ if (caseLocale == UCASE_LOC_ROOT ||
+ (caseLocale >= 0 ?
+ !(caseLocale == UCASE_LOC_TURKISH || caseLocale == UCASE_LOC_LITHUANIAN) :
+ (options & _FOLD_CASE_OPTIONS_MASK) == U_FOLD_CASE_DEFAULT)) {
+ latinToLower = LatinCase::TO_LOWER_NORMAL;
+ } else {
+ latinToLower = LatinCase::TO_LOWER_TR_LT;
+ }
+ const UTrie2 *trie = ucase_getTrie();
+ int32_t prev = srcStart;
+ int32_t srcIndex = srcStart;
+ for (;;) {
+ // fast path for simple cases
+ int32_t cpStart;
+ UChar32 c;
+ for (;;) {
+ if (U_FAILURE(errorCode) || srcIndex >= srcLimit) {
+ c = U_SENTINEL;
+ break;
}
- cpStart = --srcIndex;
- U8_NEXT(src, srcIndex, srcLimit, c);
- if (c < 0) {
- // ill-formed UTF-8
- continue;
- }
- uint16_t props = UTRIE2_GET16(trie, c);
- if (UCASE_HAS_EXCEPTION(props)) { break; }
- int32_t delta;
- if (!UCASE_IS_UPPER_OR_TITLE(props) || (delta = UCASE_GET_DELTA(props)) == 0) {
- continue;
- }
- ByteSinkUtil::appendUnchanged(src + prev, cpStart - prev,
- sink, options, edits, errorCode);
- ByteSinkUtil::appendCodePoint(srcIndex - cpStart, c + delta, sink, edits);
- prev = srcIndex;
- }
- if (c < 0) {
- break;
+ uint8_t lead = src[srcIndex++];
+ if (lead <= 0x7f) {
+ int8_t d = latinToLower[lead];
+ if (d == LatinCase::EXC) {
+ cpStart = srcIndex - 1;
+ c = lead;
+ break;
+ }
+ if (d == 0) { continue; }
+ ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev,
+ sink, options, edits, errorCode);
+ char ascii = (char)(lead + d);
+ sink.Append(&ascii, 1);
+ if (edits != nullptr) {
+ edits->addReplace(1, 1);
+ }
+ prev = srcIndex;
+ continue;
+ } else if (lead < 0xe3) {
+ uint8_t t;
+ if (0xc2 <= lead && lead <= 0xc5 && srcIndex < srcLimit &&
+ (t = src[srcIndex] - 0x80) <= 0x3f) {
+ // U+0080..U+017F
+ ++srcIndex;
+ c = ((lead - 0xc0) << 6) | t;
+ int8_t d = latinToLower[c];
+ if (d == LatinCase::EXC) {
+ cpStart = srcIndex - 2;
+ break;
+ }
+ if (d == 0) { continue; }
+ ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 2 - prev,
+ sink, options, edits, errorCode);
+ ByteSinkUtil::appendTwoBytes(c + d, sink);
+ if (edits != nullptr) {
+ edits->addReplace(2, 2);
+ }
+ prev = srcIndex;
+ continue;
+ }
+ } else if ((lead <= 0xe9 || lead == 0xeb || lead == 0xec) &&
+ (srcIndex + 2) <= srcLimit &&
+ U8_IS_TRAIL(src[srcIndex]) && U8_IS_TRAIL(src[srcIndex + 1])) {
+ // most of CJK: no case mappings
+ srcIndex += 2;
+ continue;
+ }
+ cpStart = --srcIndex;
+ U8_NEXT(src, srcIndex, srcLimit, c);
+ if (c < 0) {
+ // ill-formed UTF-8
+ continue;
+ }
+ uint16_t props = UTRIE2_GET16(trie, c);
+ if (UCASE_HAS_EXCEPTION(props)) { break; }
+ int32_t delta;
+ if (!UCASE_IS_UPPER_OR_TITLE(props) || (delta = UCASE_GET_DELTA(props)) == 0) {
+ continue;
+ }
+ ByteSinkUtil::appendUnchanged(src + prev, cpStart - prev,
+ sink, options, edits, errorCode);
+ ByteSinkUtil::appendCodePoint(srcIndex - cpStart, c + delta, sink, edits);
+ prev = srcIndex;
}
- // slow path
- const UChar *s;
- if (caseLocale >= 0) {
- csc->cpStart = cpStart;
- csc->cpLimit = srcIndex;
- c = ucase_toFullLower(c, utf8_caseContextIterator, csc, &s, caseLocale);
+ if (c < 0) {
+ break;
+ }
+ // slow path
+ const UChar *s;
+ if (caseLocale >= 0) {
+ csc->cpStart = cpStart;
+ csc->cpLimit = srcIndex;
+ c = ucase_toFullLower(c, utf8_caseContextIterator, csc, &s, caseLocale);
} else {
- c = ucase_toFullFolding(c, &s, options);
+ c = ucase_toFullFolding(c, &s, options);
}
- if (c >= 0) {
- ByteSinkUtil::appendUnchanged(src + prev, cpStart - prev,
- sink, options, edits, errorCode);
- appendResult(srcIndex - cpStart, c, s, sink, options, edits, errorCode);
- prev = srcIndex;
- }
- }
- ByteSinkUtil::appendUnchanged(src + prev, srcIndex - prev,
- sink, options, edits, errorCode);
-}
-
-void toUpper(int32_t caseLocale, uint32_t options,
- const uint8_t *src, UCaseContext *csc, int32_t srcLength,
- icu::ByteSink &sink, icu::Edits *edits, UErrorCode &errorCode) {
- const int8_t *latinToUpper;
- if (caseLocale == UCASE_LOC_TURKISH) {
- latinToUpper = LatinCase::TO_UPPER_TR;
- } else {
- latinToUpper = LatinCase::TO_UPPER_NORMAL;
+ if (c >= 0) {
+ ByteSinkUtil::appendUnchanged(src + prev, cpStart - prev,
+ sink, options, edits, errorCode);
+ appendResult(srcIndex - cpStart, c, s, sink, options, edits, errorCode);
+ prev = srcIndex;
+ }
}
- const UTrie2 *trie = ucase_getTrie();
- int32_t prev = 0;
- int32_t srcIndex = 0;
- for (;;) {
- // fast path for simple cases
- int32_t cpStart;
- UChar32 c;
- for (;;) {
- if (U_FAILURE(errorCode) || srcIndex >= srcLength) {
- c = U_SENTINEL;
- break;
- }
- uint8_t lead = src[srcIndex++];
- if (lead <= 0x7f) {
- int8_t d = latinToUpper[lead];
- if (d == LatinCase::EXC) {
- cpStart = srcIndex - 1;
- c = lead;
- break;
- }
- if (d == 0) { continue; }
- ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev,
- sink, options, edits, errorCode);
- char ascii = (char)(lead + d);
- sink.Append(&ascii, 1);
- if (edits != nullptr) {
- edits->addReplace(1, 1);
- }
- prev = srcIndex;
- continue;
- } else if (lead < 0xe3) {
- uint8_t t;
- if (0xc2 <= lead && lead <= 0xc5 && srcIndex < srcLength &&
- (t = src[srcIndex] - 0x80) <= 0x3f) {
- // U+0080..U+017F
- ++srcIndex;
- c = ((lead - 0xc0) << 6) | t;
- int8_t d = latinToUpper[c];
- if (d == LatinCase::EXC) {
- cpStart = srcIndex - 2;
- break;
- }
- if (d == 0) { continue; }
- ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 2 - prev,
- sink, options, edits, errorCode);
- ByteSinkUtil::appendTwoBytes(c + d, sink);
- if (edits != nullptr) {
- edits->addReplace(2, 2);
- }
- prev = srcIndex;
- continue;
- }
- } else if ((lead <= 0xe9 || lead == 0xeb || lead == 0xec) &&
- (srcIndex + 2) <= srcLength &&
- U8_IS_TRAIL(src[srcIndex]) && U8_IS_TRAIL(src[srcIndex + 1])) {
- // most of CJK: no case mappings
- srcIndex += 2;
- continue;
- }
- cpStart = --srcIndex;
- U8_NEXT(src, srcIndex, srcLength, c);
- if (c < 0) {
- // ill-formed UTF-8
- continue;
- }
- uint16_t props = UTRIE2_GET16(trie, c);
- if (UCASE_HAS_EXCEPTION(props)) { break; }
- int32_t delta;
- if (UCASE_GET_TYPE(props) != UCASE_LOWER || (delta = UCASE_GET_DELTA(props)) == 0) {
- continue;
- }
- ByteSinkUtil::appendUnchanged(src + prev, cpStart - prev,
- sink, options, edits, errorCode);
- ByteSinkUtil::appendCodePoint(srcIndex - cpStart, c + delta, sink, edits);
- prev = srcIndex;
- }
- if (c < 0) {
- break;
- }
- // slow path
- csc->cpStart = cpStart;
- csc->cpLimit = srcIndex;
- const UChar *s;
- c = ucase_toFullUpper(c, utf8_caseContextIterator, csc, &s, caseLocale);
- if (c >= 0) {
- ByteSinkUtil::appendUnchanged(src + prev, cpStart - prev,
- sink, options, edits, errorCode);
- appendResult(srcIndex - cpStart, c, s, sink, options, edits, errorCode);
- prev = srcIndex;
- }
+ ByteSinkUtil::appendUnchanged(src + prev, srcIndex - prev,
+ sink, options, edits, errorCode);
+}
+
+void toUpper(int32_t caseLocale, uint32_t options,
+ const uint8_t *src, UCaseContext *csc, int32_t srcLength,
+ icu::ByteSink &sink, icu::Edits *edits, UErrorCode &errorCode) {
+ const int8_t *latinToUpper;
+ if (caseLocale == UCASE_LOC_TURKISH) {
+ latinToUpper = LatinCase::TO_UPPER_TR;
+ } else {
+ latinToUpper = LatinCase::TO_UPPER_NORMAL;
}
- ByteSinkUtil::appendUnchanged(src + prev, srcIndex - prev,
- sink, options, edits, errorCode);
+ const UTrie2 *trie = ucase_getTrie();
+ int32_t prev = 0;
+ int32_t srcIndex = 0;
+ for (;;) {
+ // fast path for simple cases
+ int32_t cpStart;
+ UChar32 c;
+ for (;;) {
+ if (U_FAILURE(errorCode) || srcIndex >= srcLength) {
+ c = U_SENTINEL;
+ break;
+ }
+ uint8_t lead = src[srcIndex++];
+ if (lead <= 0x7f) {
+ int8_t d = latinToUpper[lead];
+ if (d == LatinCase::EXC) {
+ cpStart = srcIndex - 1;
+ c = lead;
+ break;
+ }
+ if (d == 0) { continue; }
+ ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev,
+ sink, options, edits, errorCode);
+ char ascii = (char)(lead + d);
+ sink.Append(&ascii, 1);
+ if (edits != nullptr) {
+ edits->addReplace(1, 1);
+ }
+ prev = srcIndex;
+ continue;
+ } else if (lead < 0xe3) {
+ uint8_t t;
+ if (0xc2 <= lead && lead <= 0xc5 && srcIndex < srcLength &&
+ (t = src[srcIndex] - 0x80) <= 0x3f) {
+ // U+0080..U+017F
+ ++srcIndex;
+ c = ((lead - 0xc0) << 6) | t;
+ int8_t d = latinToUpper[c];
+ if (d == LatinCase::EXC) {
+ cpStart = srcIndex - 2;
+ break;
+ }
+ if (d == 0) { continue; }
+ ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 2 - prev,
+ sink, options, edits, errorCode);
+ ByteSinkUtil::appendTwoBytes(c + d, sink);
+ if (edits != nullptr) {
+ edits->addReplace(2, 2);
+ }
+ prev = srcIndex;
+ continue;
+ }
+ } else if ((lead <= 0xe9 || lead == 0xeb || lead == 0xec) &&
+ (srcIndex + 2) <= srcLength &&
+ U8_IS_TRAIL(src[srcIndex]) && U8_IS_TRAIL(src[srcIndex + 1])) {
+ // most of CJK: no case mappings
+ srcIndex += 2;
+ continue;
+ }
+ cpStart = --srcIndex;
+ U8_NEXT(src, srcIndex, srcLength, c);
+ if (c < 0) {
+ // ill-formed UTF-8
+ continue;
+ }
+ uint16_t props = UTRIE2_GET16(trie, c);
+ if (UCASE_HAS_EXCEPTION(props)) { break; }
+ int32_t delta;
+ if (UCASE_GET_TYPE(props) != UCASE_LOWER || (delta = UCASE_GET_DELTA(props)) == 0) {
+ continue;
+ }
+ ByteSinkUtil::appendUnchanged(src + prev, cpStart - prev,
+ sink, options, edits, errorCode);
+ ByteSinkUtil::appendCodePoint(srcIndex - cpStart, c + delta, sink, edits);
+ prev = srcIndex;
+ }
+ if (c < 0) {
+ break;
+ }
+ // slow path
+ csc->cpStart = cpStart;
+ csc->cpLimit = srcIndex;
+ const UChar *s;
+ c = ucase_toFullUpper(c, utf8_caseContextIterator, csc, &s, caseLocale);
+ if (c >= 0) {
+ ByteSinkUtil::appendUnchanged(src + prev, cpStart - prev,
+ sink, options, edits, errorCode);
+ appendResult(srcIndex - cpStart, c, s, sink, options, edits, errorCode);
+ prev = srcIndex;
+ }
+ }
+ ByteSinkUtil::appendUnchanged(src + prev, srcIndex - prev,
+ sink, options, edits, errorCode);
}
-} // namespace
-
+} // namespace
+
#if !UCONFIG_NO_BREAK_ITERATION
-U_CFUNC void U_CALLCONV
-ucasemap_internalUTF8ToTitle(
- int32_t caseLocale, uint32_t options, BreakIterator *iter,
- const uint8_t *src, int32_t srcLength,
- ByteSink &sink, icu::Edits *edits,
- UErrorCode &errorCode) {
- if (!ustrcase_checkTitleAdjustmentOptions(options, errorCode)) {
- return;
+U_CFUNC void U_CALLCONV
+ucasemap_internalUTF8ToTitle(
+ int32_t caseLocale, uint32_t options, BreakIterator *iter,
+ const uint8_t *src, int32_t srcLength,
+ ByteSink &sink, icu::Edits *edits,
+ UErrorCode &errorCode) {
+ if (!ustrcase_checkTitleAdjustmentOptions(options, errorCode)) {
+ return;
}
/* set up local variables */
UCaseContext csc=UCASECONTEXT_INITIALIZER;
csc.p=(void *)src;
csc.limit=srcLength;
- int32_t prev=0;
- UBool isFirstIndex=TRUE;
+ int32_t prev=0;
+ UBool isFirstIndex=TRUE;
/* titlecasing loop */
while(prev<srcLength) {
/* find next index where to titlecase */
- int32_t index;
+ int32_t index;
if(isFirstIndex) {
isFirstIndex=FALSE;
- index=iter->first();
+ index=iter->first();
} else {
- index=iter->next();
+ index=iter->next();
}
- if(index==UBRK_DONE || index>srcLength) {
- index=srcLength;
+ if(index==UBRK_DONE || index>srcLength) {
+ index=srcLength;
}
/*
- * Segment [prev..index[ into 3 parts:
- * a) skipped characters (copy as-is) [prev..titleStart[
- * b) first letter (titlecase) [titleStart..titleLimit[
+ * Segment [prev..index[ into 3 parts:
+ * a) skipped characters (copy as-is) [prev..titleStart[
+ * b) first letter (titlecase) [titleStart..titleLimit[
* c) subsequent characters (lowercase) [titleLimit..index[
*/
- if(prev<index) {
- /* find and copy skipped characters [prev..titleStart[ */
- int32_t titleStart=prev;
- int32_t titleLimit=prev;
- UChar32 c;
- U8_NEXT(src, titleLimit, index, c);
- if ((options&U_TITLECASE_NO_BREAK_ADJUSTMENT)==0) {
- // Adjust the titlecasing index to the next cased character,
- // or to the next letter/number/symbol/private use.
- // Stop with titleStart<titleLimit<=index
- // if there is a character to be titlecased,
- // or else stop with titleStart==titleLimit==index.
- UBool toCased = (options&U_TITLECASE_ADJUST_TO_CASED) != 0;
- while (toCased ? UCASE_NONE==ucase_getType(c) : !ustrcase_isLNS(c)) {
+ if(prev<index) {
+ /* find and copy skipped characters [prev..titleStart[ */
+ int32_t titleStart=prev;
+ int32_t titleLimit=prev;
+ UChar32 c;
+ U8_NEXT(src, titleLimit, index, c);
+ if ((options&U_TITLECASE_NO_BREAK_ADJUSTMENT)==0) {
+ // Adjust the titlecasing index to the next cased character,
+ // or to the next letter/number/symbol/private use.
+ // Stop with titleStart<titleLimit<=index
+ // if there is a character to be titlecased,
+ // or else stop with titleStart==titleLimit==index.
+ UBool toCased = (options&U_TITLECASE_ADJUST_TO_CASED) != 0;
+ while (toCased ? UCASE_NONE==ucase_getType(c) : !ustrcase_isLNS(c)) {
titleStart=titleLimit;
- if(titleLimit==index) {
+ if(titleLimit==index) {
break;
}
- U8_NEXT(src, titleLimit, index, c);
- }
- if (prev < titleStart) {
- if (!ByteSinkUtil::appendUnchanged(src+prev, titleStart-prev,
- sink, options, edits, errorCode)) {
- return;
+ U8_NEXT(src, titleLimit, index, c);
+ }
+ if (prev < titleStart) {
+ if (!ByteSinkUtil::appendUnchanged(src+prev, titleStart-prev,
+ sink, options, edits, errorCode)) {
+ return;
}
}
}
@@ -490,58 +490,58 @@ ucasemap_internalUTF8ToTitle(
if(c>=0) {
csc.cpStart=titleStart;
csc.cpLimit=titleLimit;
- const UChar *s;
- c=ucase_toFullTitle(c, utf8_caseContextIterator, &csc, &s, caseLocale);
- if (!appendResult(titleLimit-titleStart, c, s, sink, options, edits, errorCode)) {
- return;
- }
+ const UChar *s;
+ c=ucase_toFullTitle(c, utf8_caseContextIterator, &csc, &s, caseLocale);
+ if (!appendResult(titleLimit-titleStart, c, s, sink, options, edits, errorCode)) {
+ return;
+ }
} else {
// Malformed UTF-8.
- if (!ByteSinkUtil::appendUnchanged(src+titleStart, titleLimit-titleStart,
- sink, options, edits, errorCode)) {
- return;
- }
+ if (!ByteSinkUtil::appendUnchanged(src+titleStart, titleLimit-titleStart,
+ sink, options, edits, errorCode)) {
+ return;
+ }
}
/* Special case Dutch IJ titlecasing */
- if (titleStart+1 < index &&
- caseLocale == UCASE_LOC_DUTCH &&
- (src[titleStart] == 0x0049 || src[titleStart] == 0x0069)) {
- if (src[titleStart+1] == 0x006A) {
- ByteSinkUtil::appendCodePoint(1, 0x004A, sink, edits);
- titleLimit++;
- } else if (src[titleStart+1] == 0x004A) {
- // Keep the capital J from getting lowercased.
- if (!ByteSinkUtil::appendUnchanged(src+titleStart+1, 1,
- sink, options, edits, errorCode)) {
- return;
- }
- titleLimit++;
- }
+ if (titleStart+1 < index &&
+ caseLocale == UCASE_LOC_DUTCH &&
+ (src[titleStart] == 0x0049 || src[titleStart] == 0x0069)) {
+ if (src[titleStart+1] == 0x006A) {
+ ByteSinkUtil::appendCodePoint(1, 0x004A, sink, edits);
+ titleLimit++;
+ } else if (src[titleStart+1] == 0x004A) {
+ // Keep the capital J from getting lowercased.
+ if (!ByteSinkUtil::appendUnchanged(src+titleStart+1, 1,
+ sink, options, edits, errorCode)) {
+ return;
+ }
+ titleLimit++;
+ }
}
-
+
/* lowercase [titleLimit..index[ */
- if(titleLimit<index) {
- if((options&U_TITLECASE_NO_LOWERCASE)==0) {
+ if(titleLimit<index) {
+ if((options&U_TITLECASE_NO_LOWERCASE)==0) {
/* Normal operation: Lowercase the rest of the word. */
- toLower(caseLocale, options,
- src, &csc, titleLimit, index,
- sink, edits, errorCode);
- if(U_FAILURE(errorCode)) {
- return;
- }
+ toLower(caseLocale, options,
+ src, &csc, titleLimit, index,
+ sink, edits, errorCode);
+ if(U_FAILURE(errorCode)) {
+ return;
+ }
} else {
/* Optionally just copy the rest of the word unchanged. */
- if (!ByteSinkUtil::appendUnchanged(src+titleLimit, index-titleLimit,
- sink, options, edits, errorCode)) {
- return;
+ if (!ByteSinkUtil::appendUnchanged(src+titleLimit, index-titleLimit,
+ sink, options, edits, errorCode)) {
+ return;
}
}
}
}
}
- prev=index;
+ prev=index;
}
}
@@ -550,11 +550,11 @@ ucasemap_internalUTF8ToTitle(
U_NAMESPACE_BEGIN
namespace GreekUpper {
-UBool isFollowedByCasedLetter(const uint8_t *s, int32_t i, int32_t length) {
+UBool isFollowedByCasedLetter(const uint8_t *s, int32_t i, int32_t length) {
while (i < length) {
UChar32 c;
U8_NEXT(s, i, length, c);
- int32_t type = ucase_getTypeOrIgnorable(c);
+ int32_t type = ucase_getTypeOrIgnorable(c);
if ((type & UCASE_IGNORABLE) != 0) {
// Case-ignorable, continue with the loop.
} else if (type != UCASE_NONE) {
@@ -567,17 +567,17 @@ UBool isFollowedByCasedLetter(const uint8_t *s, int32_t i, int32_t length) {
}
// Keep this consistent with the UTF-16 version in ustrcase.cpp and the Java version in CaseMap.java.
-void toUpper(uint32_t options,
- const uint8_t *src, int32_t srcLength,
- ByteSink &sink, Edits *edits,
- UErrorCode &errorCode) {
+void toUpper(uint32_t options,
+ const uint8_t *src, int32_t srcLength,
+ ByteSink &sink, Edits *edits,
+ UErrorCode &errorCode) {
uint32_t state = 0;
for (int32_t i = 0; i < srcLength;) {
int32_t nextIndex = i;
UChar32 c;
U8_NEXT(src, nextIndex, srcLength, c);
uint32_t nextState = 0;
- int32_t type = ucase_getTypeOrIgnorable(c);
+ int32_t type = ucase_getTypeOrIgnorable(c);
if ((type & UCASE_IGNORABLE) != 0) {
// c is case-ignorable
nextState |= (state & AFTER_CASED);
@@ -627,7 +627,7 @@ void toUpper(uint32_t options,
(data & HAS_ACCENT) != 0 &&
numYpogegrammeni == 0 &&
(state & AFTER_CASED) == 0 &&
- !isFollowedByCasedLetter(src, nextIndex, srcLength)) {
+ !isFollowedByCasedLetter(src, nextIndex, srcLength)) {
// Keep disjunctive "or" with (only) a tonos.
// We use the same "word boundary" conditions as for the Final_Sigma test.
if (i == nextIndex) {
@@ -645,69 +645,69 @@ void toUpper(uint32_t options,
data &= ~HAS_EITHER_DIALYTIKA;
}
}
-
- UBool change;
- if (edits == nullptr && (options & U_OMIT_UNCHANGED_TEXT) == 0) {
- change = TRUE; // common, simple usage
- } else {
- // Find out first whether we are changing the text.
- U_ASSERT(0x370 <= upper && upper <= 0x3ff); // 2-byte UTF-8, main Greek block
- change = (i + 2) > nextIndex ||
- src[i] != getTwoByteLead(upper) || src[i + 1] != getTwoByteTrail(upper) ||
- numYpogegrammeni > 0;
- int32_t i2 = i + 2;
- if ((data & HAS_EITHER_DIALYTIKA) != 0) {
- change |= (i2 + 2) > nextIndex ||
- src[i2] != (uint8_t)u8"\u0308"[0] ||
- src[i2 + 1] != (uint8_t)u8"\u0308"[1];
- i2 += 2;
- }
- if (addTonos) {
- change |= (i2 + 2) > nextIndex ||
- src[i2] != (uint8_t)u8"\u0301"[0] ||
- src[i2 + 1] != (uint8_t)u8"\u0301"[1];
- i2 += 2;
- }
- int32_t oldLength = nextIndex - i;
- int32_t newLength = (i2 - i) + numYpogegrammeni * 2; // 2 bytes per U+0399
- change |= oldLength != newLength;
- if (change) {
- if (edits != NULL) {
- edits->addReplace(oldLength, newLength);
- }
- } else {
- if (edits != NULL) {
- edits->addUnchanged(oldLength);
- }
- // Write unchanged text?
- change = (options & U_OMIT_UNCHANGED_TEXT) == 0;
- }
+
+ UBool change;
+ if (edits == nullptr && (options & U_OMIT_UNCHANGED_TEXT) == 0) {
+ change = TRUE; // common, simple usage
+ } else {
+ // Find out first whether we are changing the text.
+ U_ASSERT(0x370 <= upper && upper <= 0x3ff); // 2-byte UTF-8, main Greek block
+ change = (i + 2) > nextIndex ||
+ src[i] != getTwoByteLead(upper) || src[i + 1] != getTwoByteTrail(upper) ||
+ numYpogegrammeni > 0;
+ int32_t i2 = i + 2;
+ if ((data & HAS_EITHER_DIALYTIKA) != 0) {
+ change |= (i2 + 2) > nextIndex ||
+ src[i2] != (uint8_t)u8"\u0308"[0] ||
+ src[i2 + 1] != (uint8_t)u8"\u0308"[1];
+ i2 += 2;
+ }
+ if (addTonos) {
+ change |= (i2 + 2) > nextIndex ||
+ src[i2] != (uint8_t)u8"\u0301"[0] ||
+ src[i2 + 1] != (uint8_t)u8"\u0301"[1];
+ i2 += 2;
+ }
+ int32_t oldLength = nextIndex - i;
+ int32_t newLength = (i2 - i) + numYpogegrammeni * 2; // 2 bytes per U+0399
+ change |= oldLength != newLength;
+ if (change) {
+ if (edits != NULL) {
+ edits->addReplace(oldLength, newLength);
+ }
+ } else {
+ if (edits != NULL) {
+ edits->addUnchanged(oldLength);
+ }
+ // Write unchanged text?
+ change = (options & U_OMIT_UNCHANGED_TEXT) == 0;
+ }
}
-
- if (change) {
- ByteSinkUtil::appendTwoBytes(upper, sink);
- if ((data & HAS_EITHER_DIALYTIKA) != 0) {
- sink.AppendU8(u8"\u0308", 2); // restore or add a dialytika
- }
- if (addTonos) {
- sink.AppendU8(u8"\u0301", 2);
- }
- while (numYpogegrammeni > 0) {
- sink.AppendU8(u8"\u0399", 2);
- --numYpogegrammeni;
- }
+
+ if (change) {
+ ByteSinkUtil::appendTwoBytes(upper, sink);
+ if ((data & HAS_EITHER_DIALYTIKA) != 0) {
+ sink.AppendU8(u8"\u0308", 2); // restore or add a dialytika
+ }
+ if (addTonos) {
+ sink.AppendU8(u8"\u0301", 2);
+ }
+ while (numYpogegrammeni > 0) {
+ sink.AppendU8(u8"\u0399", 2);
+ --numYpogegrammeni;
+ }
}
} else if(c>=0) {
const UChar *s;
- c=ucase_toFullUpper(c, NULL, NULL, &s, UCASE_LOC_GREEK);
- if (!appendResult(nextIndex - i, c, s, sink, options, edits, errorCode)) {
- return;
+ c=ucase_toFullUpper(c, NULL, NULL, &s, UCASE_LOC_GREEK);
+ if (!appendResult(nextIndex - i, c, s, sink, options, edits, errorCode)) {
+ return;
}
} else {
// Malformed UTF-8.
- if (!ByteSinkUtil::appendUnchanged(src+i, nextIndex-i,
- sink, options, edits, errorCode)) {
- return;
+ if (!ByteSinkUtil::appendUnchanged(src+i, nextIndex-i,
+ sink, options, edits, errorCode)) {
+ return;
}
}
i = nextIndex;
@@ -718,98 +718,98 @@ void toUpper(uint32_t options,
} // namespace GreekUpper
U_NAMESPACE_END
-static void U_CALLCONV
-ucasemap_internalUTF8ToLower(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_UNUSED
+static void U_CALLCONV
+ucasemap_internalUTF8ToLower(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_UNUSED
const uint8_t *src, int32_t srcLength,
- icu::ByteSink &sink, icu::Edits *edits,
- UErrorCode &errorCode) {
+ icu::ByteSink &sink, icu::Edits *edits,
+ UErrorCode &errorCode) {
UCaseContext csc=UCASECONTEXT_INITIALIZER;
csc.p=(void *)src;
csc.limit=srcLength;
- toLower(
- caseLocale, options,
+ toLower(
+ caseLocale, options,
src, &csc, 0, srcLength,
- sink, edits, errorCode);
+ sink, edits, errorCode);
}
-static void U_CALLCONV
-ucasemap_internalUTF8ToUpper(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_UNUSED
+static void U_CALLCONV
+ucasemap_internalUTF8ToUpper(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_UNUSED
const uint8_t *src, int32_t srcLength,
- icu::ByteSink &sink, icu::Edits *edits,
- UErrorCode &errorCode) {
- if (caseLocale == UCASE_LOC_GREEK) {
- GreekUpper::toUpper(options, src, srcLength, sink, edits, errorCode);
- } else {
- UCaseContext csc=UCASECONTEXT_INITIALIZER;
- csc.p=(void *)src;
- csc.limit=srcLength;
- toUpper(
- caseLocale, options,
- src, &csc, srcLength,
- sink, edits, errorCode);
+ icu::ByteSink &sink, icu::Edits *edits,
+ UErrorCode &errorCode) {
+ if (caseLocale == UCASE_LOC_GREEK) {
+ GreekUpper::toUpper(options, src, srcLength, sink, edits, errorCode);
+ } else {
+ UCaseContext csc=UCASECONTEXT_INITIALIZER;
+ csc.p=(void *)src;
+ csc.limit=srcLength;
+ toUpper(
+ caseLocale, options,
+ src, &csc, srcLength,
+ sink, edits, errorCode);
}
}
-static void U_CALLCONV
-ucasemap_internalUTF8Fold(int32_t /* caseLocale */, uint32_t options, UCASEMAP_BREAK_ITERATOR_UNUSED
- const uint8_t *src, int32_t srcLength,
- icu::ByteSink &sink, icu::Edits *edits,
- UErrorCode &errorCode) {
- toLower(
- -1, options,
- src, nullptr, 0, srcLength,
- sink, edits, errorCode);
-}
-
-void
-ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_PARAM
- const char *src, int32_t srcLength,
- UTF8CaseMapper *stringCaseMapper,
- icu::ByteSink &sink, icu::Edits *edits,
- UErrorCode &errorCode) {
- /* check argument values */
- if (U_FAILURE(errorCode)) {
- return;
- }
- if ((src == nullptr && srcLength != 0) || srcLength < -1) {
- errorCode = U_ILLEGAL_ARGUMENT_ERROR;
- return;
- }
-
- // Get the string length.
- if (srcLength == -1) {
- srcLength = (int32_t)uprv_strlen((const char *)src);
+static void U_CALLCONV
+ucasemap_internalUTF8Fold(int32_t /* caseLocale */, uint32_t options, UCASEMAP_BREAK_ITERATOR_UNUSED
+ const uint8_t *src, int32_t srcLength,
+ icu::ByteSink &sink, icu::Edits *edits,
+ UErrorCode &errorCode) {
+ toLower(
+ -1, options,
+ src, nullptr, 0, srcLength,
+ sink, edits, errorCode);
+}
+
+void
+ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_PARAM
+ const char *src, int32_t srcLength,
+ UTF8CaseMapper *stringCaseMapper,
+ icu::ByteSink &sink, icu::Edits *edits,
+ UErrorCode &errorCode) {
+ /* check argument values */
+ if (U_FAILURE(errorCode)) {
+ return;
+ }
+ if ((src == nullptr && srcLength != 0) || srcLength < -1) {
+ errorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
+
+ // Get the string length.
+ if (srcLength == -1) {
+ srcLength = (int32_t)uprv_strlen((const char *)src);
}
- if (edits != nullptr && (options & U_EDITS_NO_RESET) == 0) {
- edits->reset();
- }
- stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
- (const uint8_t *)src, srcLength, sink, edits, errorCode);
- sink.Flush();
- if (U_SUCCESS(errorCode)) {
- if (edits != nullptr) {
- edits->copyErrorTo(errorCode);
- }
+ if (edits != nullptr && (options & U_EDITS_NO_RESET) == 0) {
+ edits->reset();
}
+ stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
+ (const uint8_t *)src, srcLength, sink, edits, errorCode);
+ sink.Flush();
+ if (U_SUCCESS(errorCode)) {
+ if (edits != nullptr) {
+ edits->copyErrorTo(errorCode);
+ }
+ }
}
-int32_t
-ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_PARAM
- char *dest, int32_t destCapacity,
- const char *src, int32_t srcLength,
+int32_t
+ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_PARAM
+ char *dest, int32_t destCapacity,
+ const char *src, int32_t srcLength,
UTF8CaseMapper *stringCaseMapper,
- icu::Edits *edits,
- UErrorCode &errorCode) {
+ icu::Edits *edits,
+ UErrorCode &errorCode) {
/* check argument values */
- if(U_FAILURE(errorCode)) {
+ if(U_FAILURE(errorCode)) {
return 0;
}
if( destCapacity<0 ||
(dest==NULL && destCapacity>0) ||
- (src==NULL && srcLength!=0) || srcLength<-1
+ (src==NULL && srcLength!=0) || srcLength<-1
) {
- errorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ errorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
@@ -823,25 +823,25 @@ ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_P
((src>=dest && src<(dest+destCapacity)) ||
(dest>=src && dest<(src+srcLength)))
) {
- errorCode=U_ILLEGAL_ARGUMENT_ERROR;
+ errorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
- CheckedArrayByteSink sink(dest, destCapacity);
- if (edits != nullptr && (options & U_EDITS_NO_RESET) == 0) {
- edits->reset();
- }
- stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
- (const uint8_t *)src, srcLength, sink, edits, errorCode);
- sink.Flush();
- if (U_SUCCESS(errorCode)) {
- if (sink.Overflowed()) {
- errorCode = U_BUFFER_OVERFLOW_ERROR;
- } else if (edits != nullptr) {
- edits->copyErrorTo(errorCode);
- }
- }
- return u_terminateChars(dest, destCapacity, sink.NumberOfBytesAppended(), &errorCode);
+ CheckedArrayByteSink sink(dest, destCapacity);
+ if (edits != nullptr && (options & U_EDITS_NO_RESET) == 0) {
+ edits->reset();
+ }
+ stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
+ (const uint8_t *)src, srcLength, sink, edits, errorCode);
+ sink.Flush();
+ if (U_SUCCESS(errorCode)) {
+ if (sink.Overflowed()) {
+ errorCode = U_BUFFER_OVERFLOW_ERROR;
+ } else if (edits != nullptr) {
+ edits->copyErrorTo(errorCode);
+ }
+ }
+ return u_terminateChars(dest, destCapacity, sink.NumberOfBytesAppended(), &errorCode);
}
/* public API functions */
@@ -851,11 +851,11 @@ ucasemap_utf8ToLower(const UCaseMap *csm,
char *dest, int32_t destCapacity,
const char *src, int32_t srcLength,
UErrorCode *pErrorCode) {
- return ucasemap_mapUTF8(
- csm->caseLocale, csm->options, UCASEMAP_BREAK_ITERATOR_NULL
- dest, destCapacity,
- src, srcLength,
- ucasemap_internalUTF8ToLower, NULL, *pErrorCode);
+ return ucasemap_mapUTF8(
+ csm->caseLocale, csm->options, UCASEMAP_BREAK_ITERATOR_NULL
+ dest, destCapacity,
+ src, srcLength,
+ ucasemap_internalUTF8ToLower, NULL, *pErrorCode);
}
U_CAPI int32_t U_EXPORT2
@@ -863,11 +863,11 @@ ucasemap_utf8ToUpper(const UCaseMap *csm,
char *dest, int32_t destCapacity,
const char *src, int32_t srcLength,
UErrorCode *pErrorCode) {
- return ucasemap_mapUTF8(
- csm->caseLocale, csm->options, UCASEMAP_BREAK_ITERATOR_NULL
- dest, destCapacity,
- src, srcLength,
- ucasemap_internalUTF8ToUpper, NULL, *pErrorCode);
+ return ucasemap_mapUTF8(
+ csm->caseLocale, csm->options, UCASEMAP_BREAK_ITERATOR_NULL
+ dest, destCapacity,
+ src, srcLength,
+ ucasemap_internalUTF8ToUpper, NULL, *pErrorCode);
}
U_CAPI int32_t U_EXPORT2
@@ -875,79 +875,79 @@ ucasemap_utf8FoldCase(const UCaseMap *csm,
char *dest, int32_t destCapacity,
const char *src, int32_t srcLength,
UErrorCode *pErrorCode) {
- return ucasemap_mapUTF8(
- UCASE_LOC_ROOT, csm->options, UCASEMAP_BREAK_ITERATOR_NULL
- dest, destCapacity,
- src, srcLength,
- ucasemap_internalUTF8Fold, NULL, *pErrorCode);
-}
-
-U_NAMESPACE_BEGIN
-
-void CaseMap::utf8ToLower(
- const char *locale, uint32_t options,
- StringPiece src, ByteSink &sink, Edits *edits,
- UErrorCode &errorCode) {
- ucasemap_mapUTF8(
- ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
- src.data(), src.length(),
- ucasemap_internalUTF8ToLower, sink, edits, errorCode);
+ return ucasemap_mapUTF8(
+ UCASE_LOC_ROOT, csm->options, UCASEMAP_BREAK_ITERATOR_NULL
+ dest, destCapacity,
+ src, srcLength,
+ ucasemap_internalUTF8Fold, NULL, *pErrorCode);
}
-
-void CaseMap::utf8ToUpper(
- const char *locale, uint32_t options,
- StringPiece src, ByteSink &sink, Edits *edits,
- UErrorCode &errorCode) {
- ucasemap_mapUTF8(
- ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
- src.data(), src.length(),
- ucasemap_internalUTF8ToUpper, sink, edits, errorCode);
-}
-
-void CaseMap::utf8Fold(
- uint32_t options,
- StringPiece src, ByteSink &sink, Edits *edits,
- UErrorCode &errorCode) {
- ucasemap_mapUTF8(
- UCASE_LOC_ROOT, options, UCASEMAP_BREAK_ITERATOR_NULL
- src.data(), src.length(),
- ucasemap_internalUTF8Fold, sink, edits, errorCode);
-}
-
-int32_t CaseMap::utf8ToLower(
- const char *locale, uint32_t options,
- const char *src, int32_t srcLength,
- char *dest, int32_t destCapacity, Edits *edits,
- UErrorCode &errorCode) {
- return ucasemap_mapUTF8(
- ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
- dest, destCapacity,
- src, srcLength,
- ucasemap_internalUTF8ToLower, edits, errorCode);
-}
-
-int32_t CaseMap::utf8ToUpper(
- const char *locale, uint32_t options,
- const char *src, int32_t srcLength,
- char *dest, int32_t destCapacity, Edits *edits,
- UErrorCode &errorCode) {
- return ucasemap_mapUTF8(
- ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
- dest, destCapacity,
- src, srcLength,
- ucasemap_internalUTF8ToUpper, edits, errorCode);
-}
-
-int32_t CaseMap::utf8Fold(
- uint32_t options,
- const char *src, int32_t srcLength,
- char *dest, int32_t destCapacity, Edits *edits,
- UErrorCode &errorCode) {
- return ucasemap_mapUTF8(
- UCASE_LOC_ROOT, options, UCASEMAP_BREAK_ITERATOR_NULL
- dest, destCapacity,
- src, srcLength,
- ucasemap_internalUTF8Fold, edits, errorCode);
-}
-
-U_NAMESPACE_END
+
+U_NAMESPACE_BEGIN
+
+void CaseMap::utf8ToLower(
+ const char *locale, uint32_t options,
+ StringPiece src, ByteSink &sink, Edits *edits,
+ UErrorCode &errorCode) {
+ ucasemap_mapUTF8(
+ ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
+ src.data(), src.length(),
+ ucasemap_internalUTF8ToLower, sink, edits, errorCode);
+}
+
+void CaseMap::utf8ToUpper(
+ const char *locale, uint32_t options,
+ StringPiece src, ByteSink &sink, Edits *edits,
+ UErrorCode &errorCode) {
+ ucasemap_mapUTF8(
+ ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
+ src.data(), src.length(),
+ ucasemap_internalUTF8ToUpper, sink, edits, errorCode);
+}
+
+void CaseMap::utf8Fold(
+ uint32_t options,
+ StringPiece src, ByteSink &sink, Edits *edits,
+ UErrorCode &errorCode) {
+ ucasemap_mapUTF8(
+ UCASE_LOC_ROOT, options, UCASEMAP_BREAK_ITERATOR_NULL
+ src.data(), src.length(),
+ ucasemap_internalUTF8Fold, sink, edits, errorCode);
+}
+
+int32_t CaseMap::utf8ToLower(
+ const char *locale, uint32_t options,
+ const char *src, int32_t srcLength,
+ char *dest, int32_t destCapacity, Edits *edits,
+ UErrorCode &errorCode) {
+ return ucasemap_mapUTF8(
+ ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
+ dest, destCapacity,
+ src, srcLength,
+ ucasemap_internalUTF8ToLower, edits, errorCode);
+}
+
+int32_t CaseMap::utf8ToUpper(
+ const char *locale, uint32_t options,
+ const char *src, int32_t srcLength,
+ char *dest, int32_t destCapacity, Edits *edits,
+ UErrorCode &errorCode) {
+ return ucasemap_mapUTF8(
+ ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
+ dest, destCapacity,
+ src, srcLength,
+ ucasemap_internalUTF8ToUpper, edits, errorCode);
+}
+
+int32_t CaseMap::utf8Fold(
+ uint32_t options,
+ const char *src, int32_t srcLength,
+ char *dest, int32_t destCapacity, Edits *edits,
+ UErrorCode &errorCode) {
+ return ucasemap_mapUTF8(
+ UCASE_LOC_ROOT, options, UCASEMAP_BREAK_ITERATOR_NULL
+ dest, destCapacity,
+ src, srcLength,
+ ucasemap_internalUTF8Fold, edits, errorCode);
+}
+
+U_NAMESPACE_END