summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/i18n/ulistformatter.cpp
diff options
context:
space:
mode:
authorUjjwal Sharma <usharma1998@gmail.com>2019-04-23 15:35:49 +0530
committerMichaƫl Zasso <targos@protonmail.com>2019-04-25 21:37:14 +0200
commitc9b298c5eed7abec0aff02d1f67e18e5ea938fc9 (patch)
treed523c26552e0c06e0c7e17434d2b68bed2b6e9e8 /deps/icu-small/source/i18n/ulistformatter.cpp
parent6bbb9ebf8d8da927fc71f648af4739f2d574014f (diff)
downloadandroid-node-v8-c9b298c5eed7abec0aff02d1f67e18e5ea938fc9.tar.gz
android-node-v8-c9b298c5eed7abec0aff02d1f67e18e5ea938fc9.tar.bz2
android-node-v8-c9b298c5eed7abec0aff02d1f67e18e5ea938fc9.zip
deps: update ICU to 64.2
Update the version of the bundled ICU (deps/icu-small) to ICU version 64.2 (Unicode 12, CLDR 35) Fixes: https://github.com/nodejs/node/issues/26388 PR-URL: https://github.com/nodejs/node/pull/27361 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Steven R Loomis <srloomis@us.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'deps/icu-small/source/i18n/ulistformatter.cpp')
-rw-r--r--deps/icu-small/source/i18n/ulistformatter.cpp98
1 files changed, 76 insertions, 22 deletions
diff --git a/deps/icu-small/source/i18n/ulistformatter.cpp b/deps/icu-small/source/i18n/ulistformatter.cpp
index c140c784b5..f7ad6751d3 100644
--- a/deps/icu-small/source/i18n/ulistformatter.cpp
+++ b/deps/icu-small/source/i18n/ulistformatter.cpp
@@ -15,6 +15,7 @@
#include "unicode/listformatter.h"
#include "unicode/localpointer.h"
#include "cmemory.h"
+#include "formattedval_impl.h"
U_NAMESPACE_USE
@@ -40,6 +41,49 @@ ulistfmt_close(UListFormatter *listfmt)
}
+// Magic number: FLST in ASCII
+UPRV_FORMATTED_VALUE_CAPI_AUTO_IMPL(
+ FormattedList,
+ UFormattedList,
+ UFormattedListImpl,
+ UFormattedListApiHelper,
+ ulistfmt,
+ 0x464C5354)
+
+
+static UnicodeString* getUnicodeStrings(
+ const UChar* const strings[],
+ const int32_t* stringLengths,
+ int32_t stringCount,
+ UnicodeString* length4StackBuffer,
+ LocalArray<UnicodeString>& maybeOwner,
+ UErrorCode& status) {
+ U_ASSERT(U_SUCCESS(status));
+ if (stringCount < 0 || (strings == NULL && stringCount > 0)) {
+ status = U_ILLEGAL_ARGUMENT_ERROR;
+ return nullptr;
+ }
+ UnicodeString* ustrings = length4StackBuffer;
+ if (stringCount > 4) {
+ maybeOwner.adoptInsteadAndCheckErrorCode(new UnicodeString[stringCount], status);
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ ustrings = maybeOwner.getAlias();
+ }
+ if (stringLengths == NULL) {
+ for (int32_t stringIndex = 0; stringIndex < stringCount; stringIndex++) {
+ ustrings[stringIndex].setTo(TRUE, strings[stringIndex], -1);
+ }
+ } else {
+ for (int32_t stringIndex = 0; stringIndex < stringCount; stringIndex++) {
+ ustrings[stringIndex].setTo(stringLengths[stringIndex] < 0, strings[stringIndex], stringLengths[stringIndex]);
+ }
+ }
+ return ustrings;
+}
+
+
U_CAPI int32_t U_EXPORT2
ulistfmt_format(const UListFormatter* listfmt,
const UChar* const strings[],
@@ -52,27 +96,16 @@ ulistfmt_format(const UListFormatter* listfmt,
if (U_FAILURE(*status)) {
return -1;
}
- if (stringCount < 0 || (strings == NULL && stringCount > 0) || ((result == NULL)? resultCapacity != 0 : resultCapacity < 0)) {
+ if ((result == NULL) ? resultCapacity != 0 : resultCapacity < 0) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return -1;
}
- UnicodeString ustringsStackBuf[4];
- UnicodeString* ustrings = ustringsStackBuf;
- if (stringCount > UPRV_LENGTHOF(ustringsStackBuf)) {
- ustrings = new UnicodeString[stringCount];
- if (ustrings == NULL) {
- *status = U_MEMORY_ALLOCATION_ERROR;
- return -1;
- }
- }
- if (stringLengths == NULL) {
- for (int32_t stringIndex = 0; stringIndex < stringCount; stringIndex++) {
- ustrings[stringIndex].setTo(TRUE, strings[stringIndex], -1);
- }
- } else {
- for (int32_t stringIndex = 0; stringIndex < stringCount; stringIndex++) {
- ustrings[stringIndex].setTo(stringLengths[stringIndex] < 0, strings[stringIndex], stringLengths[stringIndex]);
- }
+ UnicodeString length4StackBuffer[4];
+ LocalArray<UnicodeString> maybeOwner;
+ UnicodeString* ustrings = getUnicodeStrings(
+ strings, stringLengths, stringCount, length4StackBuffer, maybeOwner, *status);
+ if (U_FAILURE(*status)) {
+ return -1;
}
UnicodeString res;
if (result != NULL) {
@@ -80,12 +113,33 @@ ulistfmt_format(const UListFormatter* listfmt,
// otherwise, alias the destination buffer (copied from udat_format)
res.setTo(result, 0, resultCapacity);
}
- ((const ListFormatter*)listfmt)->format( ustrings, stringCount, res, *status );
- if (ustrings != ustringsStackBuf) {
- delete[] ustrings;
- }
+ reinterpret_cast<const ListFormatter*>(listfmt)->format( ustrings, stringCount, res, *status );
return res.extract(result, resultCapacity, *status);
}
+U_CAPI void U_EXPORT2
+ulistfmt_formatStringsToResult(
+ const UListFormatter* listfmt,
+ const UChar* const strings[],
+ const int32_t * stringLengths,
+ int32_t stringCount,
+ UFormattedList* uresult,
+ UErrorCode* status) {
+ auto* result = UFormattedListApiHelper::validate(uresult, *status);
+ if (U_FAILURE(*status)) {
+ return;
+ }
+ UnicodeString length4StackBuffer[4];
+ LocalArray<UnicodeString> maybeOwner;
+ UnicodeString* ustrings = getUnicodeStrings(
+ strings, stringLengths, stringCount, length4StackBuffer, maybeOwner, *status);
+ if (U_FAILURE(*status)) {
+ return;
+ }
+ result->fImpl = reinterpret_cast<const ListFormatter*>(listfmt)
+ ->formatStringsToValue(ustrings, stringCount, *status);
+}
+
+
#endif /* #if !UCONFIG_NO_FORMATTING */