summaryrefslogtreecommitdiff
path: root/thirdparty/icu4c/common/loclikely.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/icu4c/common/loclikely.cpp')
-rw-r--r--thirdparty/icu4c/common/loclikely.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/thirdparty/icu4c/common/loclikely.cpp b/thirdparty/icu4c/common/loclikely.cpp
index 94a60aba3e..d80096b588 100644
--- a/thirdparty/icu4c/common/loclikely.cpp
+++ b/thirdparty/icu4c/common/loclikely.cpp
@@ -115,7 +115,7 @@ findLikelySubtags(const char* localeID,
* @param tag The tag to add.
* @param tagLength The length of the tag.
* @param buffer The output buffer.
- * @param bufferLength The length of the output buffer. This is an input/ouput parameter.
+ * @param bufferLength The length of the output buffer. This is an input/output parameter.
**/
static void U_CALLCONV
appendTag(
@@ -1181,13 +1181,13 @@ error:
}
}
-static UBool
+static int32_t
do_canonicalize(const char* localeID,
char* buffer,
int32_t bufferCapacity,
UErrorCode* err)
{
- uloc_canonicalize(
+ int32_t canonicalizedSize = uloc_canonicalize(
localeID,
buffer,
bufferCapacity,
@@ -1195,16 +1195,14 @@ do_canonicalize(const char* localeID,
if (*err == U_STRING_NOT_TERMINATED_WARNING ||
*err == U_BUFFER_OVERFLOW_ERROR) {
- *err = U_ILLEGAL_ARGUMENT_ERROR;
-
- return FALSE;
+ return canonicalizedSize;
}
else if (U_FAILURE(*err)) {
- return FALSE;
+ return -1;
}
else {
- return TRUE;
+ return canonicalizedSize;
}
}
@@ -1241,12 +1239,17 @@ static UBool
_ulocimp_addLikelySubtags(const char* localeID,
icu::ByteSink& sink,
UErrorCode* status) {
- char localeBuffer[ULOC_FULLNAME_CAPACITY];
-
- if (do_canonicalize(localeID, localeBuffer, sizeof localeBuffer, status)) {
- return _uloc_addLikelySubtags(localeBuffer, sink, status);
+ PreflightingLocaleIDBuffer localeBuffer;
+ do {
+ localeBuffer.requestedCapacity = do_canonicalize(localeID, localeBuffer.getBuffer(),
+ localeBuffer.getCapacity(), status);
+ } while (localeBuffer.needToTryAgain(status));
+
+ if (U_SUCCESS(*status)) {
+ return _uloc_addLikelySubtags(localeBuffer.getBuffer(), sink, status);
+ } else {
+ return FALSE;
}
- return FALSE;
}
U_CAPI void U_EXPORT2
@@ -1289,11 +1292,13 @@ U_CAPI void U_EXPORT2
ulocimp_minimizeSubtags(const char* localeID,
icu::ByteSink& sink,
UErrorCode* status) {
- char localeBuffer[ULOC_FULLNAME_CAPACITY];
-
- if (do_canonicalize(localeID, localeBuffer, sizeof localeBuffer, status)) {
- _uloc_minimizeSubtags(localeBuffer, sink, status);
- }
+ PreflightingLocaleIDBuffer localeBuffer;
+ do {
+ localeBuffer.requestedCapacity = do_canonicalize(localeID, localeBuffer.getBuffer(),
+ localeBuffer.getCapacity(), status);
+ } while (localeBuffer.needToTryAgain(status));
+
+ _uloc_minimizeSubtags(localeBuffer.getBuffer(), sink, status);
}
// Pairs of (language subtag, + or -) for finding out fast if common languages