From c9b298c5eed7abec0aff02d1f67e18e5ea938fc9 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Tue, 23 Apr 2019 15:35:49 +0530 Subject: 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 Reviewed-By: Steven R Loomis Reviewed-By: Michael Dawson --- deps/icu-small/source/i18n/ulistformatter.cpp | 98 +++++++++++++++++++++------ 1 file changed, 76 insertions(+), 22 deletions(-) (limited to 'deps/icu-small/source/i18n/ulistformatter.cpp') 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& 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 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(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 maybeOwner; + UnicodeString* ustrings = getUnicodeStrings( + strings, stringLengths, stringCount, length4StackBuffer, maybeOwner, *status); + if (U_FAILURE(*status)) { + return; + } + result->fImpl = reinterpret_cast(listfmt) + ->formatStringsToValue(ustrings, stringCount, *status); +} + + #endif /* #if !UCONFIG_NO_FORMATTING */ -- cgit v1.2.3