Revert "Improve toLanguageTag()'s "und" locale handling"
This reverts commit ac1a79bbc6550a5f84adf38eee34ab302856e309.
Reason for revert: ticket 142301859, causing flakes and errors on the test.
Bug: b/142301859
Change-Id: Ie37bd52f833fd444abf3351306010c270fa0e432
diff --git a/libs/minikin/LocaleListCache.cpp b/libs/minikin/LocaleListCache.cpp
index 9ed5bd6..15156cd 100644
--- a/libs/minikin/LocaleListCache.cpp
+++ b/libs/minikin/LocaleListCache.cpp
@@ -18,7 +18,6 @@
#include "LocaleListCache.h"
-#include <cstring>
#include <unordered_set>
#include <log/log.h>
@@ -50,20 +49,24 @@
return 0;
}
- char likelyChars[ULOC_FULLNAME_CAPACITY];
// Preserve "" and "_****" since uloc_addLikelySubtags changes "" to "en_Latn_US".
if (outLength == 0 || (outLength == 5 && output[0] == '_')) {
- size_t len = outLength < ULOC_FULLNAME_CAPACITY ? outLength : ULOC_FULLNAME_CAPACITY;
- strncpy(likelyChars, output, len);
- } else {
- uErr = U_ZERO_ERROR;
- uloc_addLikelySubtags(output, likelyChars, ULOC_FULLNAME_CAPACITY, &uErr);
- if (U_FAILURE(uErr)) {
- // unable to build a proper locale identifier
- ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s", output, u_errorName(uErr));
- output[0] = '\0';
- return 0;
+ if (output[0] == '_') {
+ output[0] = '-';
}
+ std::string buf(output, outLength);
+ outLength = (size_t)snprintf(output, outSize, "und%s", buf.c_str());
+ return outLength;
+ }
+
+ char likelyChars[ULOC_FULLNAME_CAPACITY];
+ uErr = U_ZERO_ERROR;
+ uloc_addLikelySubtags(output, likelyChars, ULOC_FULLNAME_CAPACITY, &uErr);
+ if (U_FAILURE(uErr)) {
+ // unable to build a proper locale identifier
+ ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s", output, u_errorName(uErr));
+ output[0] = '\0';
+ return 0;
}
uErr = U_ZERO_ERROR;