diff --git a/LICENSE b/LICENSE index cedae41d607e2f..a7f7e92f9d272e 100644 --- a/LICENSE +++ b/LICENSE @@ -418,9 +418,9 @@ The externally maintained libraries used by Node.js are: # Copyright (c) 2013 International Business Machines Corporation # and others. All Rights Reserved. # - # Project: http://code.google.com/p/lao-dictionary/ - # Dictionary: http://lao-dictionary.googlecode.com/git/Lao-Dictionary.txt - # License: http://lao-dictionary.googlecode.com/git/Lao-Dictionary-LICENSE.txt + # Project: https://github.com/veer66/lao-dictionary + # Dictionary: https://github.com/veer66/lao-dictionary/blob/master/Lao-Dictionary.txt + # License: https://github.com/veer66/lao-dictionary/blob/master/Lao-Dictionary-LICENSE.txt # (copied below) # # This file is derived from the above dictionary, with slight diff --git a/deps/icu-small/LICENSE b/deps/icu-small/LICENSE index e7f98ed18391b8..5d664a083b986f 100644 --- a/deps/icu-small/LICENSE +++ b/deps/icu-small/LICENSE @@ -284,9 +284,9 @@ property of their respective owners. # Copyright (c) 2013 International Business Machines Corporation # and others. All Rights Reserved. # - # Project: http://code.google.com/p/lao-dictionary/ - # Dictionary: http://lao-dictionary.googlecode.com/git/Lao-Dictionary.txt - # License: http://lao-dictionary.googlecode.com/git/Lao-Dictionary-LICENSE.txt + # Project: https://github.com/veer66/lao-dictionary + # Dictionary: https://github.com/veer66/lao-dictionary/blob/master/Lao-Dictionary.txt + # License: https://github.com/veer66/lao-dictionary/blob/master/Lao-Dictionary-LICENSE.txt # (copied below) # # This file is derived from the above dictionary, with slight diff --git a/deps/icu-small/README-FULL-ICU.txt b/deps/icu-small/README-FULL-ICU.txt index bad8b0346d3e98..df63187d3ae6e4 100644 --- a/deps/icu-small/README-FULL-ICU.txt +++ b/deps/icu-small/README-FULL-ICU.txt @@ -1,8 +1,8 @@ ICU sources - auto generated by shrink-icu-src.py This directory contains the ICU subset used by --with-intl=full-icu -It is a strict subset of ICU 67 source files with the following exception(s): -* deps/icu-small/source/data/in/icudt67l.dat.bz2 : compressed data file +It is a strict subset of ICU 68 source files with the following exception(s): +* deps/icu-small/source/data/in/icudt68l.dat.bz2 : compressed data file To rebuild this directory, see ../../tools/icu/README.md diff --git a/deps/icu-small/source/.clang-format b/deps/icu-small/source/.clang-format new file mode 100644 index 00000000000000..06bd4885a10a21 --- /dev/null +++ b/deps/icu-small/source/.clang-format @@ -0,0 +1,11 @@ +# © 2020 and later: Unicode, Inc. and others. +# License & terms of use: http://www.unicode.org/copyright.html + +--- +Language: Cpp +BasedOnStyle: LLVM +IndentWidth: 4 +ColumnLimit: 105 +AllowShortBlocksOnASingleLine: false +AllowShortIfStatementsOnASingleLine: true +... diff --git a/deps/icu-small/source/common/bmpset.h b/deps/icu-small/source/common/bmpset.h index 018aeb7f95b078..e1982ac669db85 100644 --- a/deps/icu-small/source/common/bmpset.h +++ b/deps/icu-small/source/common/bmpset.h @@ -101,7 +101,7 @@ class BMPSet : public UMemory { */ UBool latin1Contains[0x100]; - /* TRUE if contains(U+FFFD). */ + /* true if contains(U+FFFD). */ UBool containsFFFD; /* diff --git a/deps/icu-small/source/common/brkeng.h b/deps/icu-small/source/common/brkeng.h index e40fce13f64b8a..155433b89a86ac 100644 --- a/deps/icu-small/source/common/brkeng.h +++ b/deps/icu-small/source/common/brkeng.h @@ -54,7 +54,7 @@ class LanguageBreakEngine : public UMemory { * a particular kind of break.

* * @param c A character which begins a run that the engine might handle - * @return TRUE if this engine handles the particular character and break + * @return true if this engine handles the particular character and break * type. */ virtual UBool handles(UChar32 c) const = 0; @@ -171,7 +171,7 @@ class UnhandledEngine : public LanguageBreakEngine { * a particular kind of break.

* * @param c A character which begins a run that the engine might handle - * @return TRUE if this engine handles the particular character and break + * @return true if this engine handles the particular character and break * type. */ virtual UBool handles(UChar32 c) const; diff --git a/deps/icu-small/source/common/bytesinkutil.h b/deps/icu-small/source/common/bytesinkutil.h index 6808fbe6777837..ab2516432d3111 100644 --- a/deps/icu-small/source/common/bytesinkutil.h +++ b/deps/icu-small/source/common/bytesinkutil.h @@ -45,9 +45,9 @@ class U_COMMON_API ByteSinkUtil { static UBool appendUnchanged(const uint8_t *s, int32_t length, ByteSink &sink, uint32_t options, Edits *edits, UErrorCode &errorCode) { - if (U_FAILURE(errorCode)) { return FALSE; } + if (U_FAILURE(errorCode)) { return false; } if (length > 0) { appendNonEmptyUnchanged(s, length, sink, options, edits); } - return TRUE; + return true; } static UBool appendUnchanged(const uint8_t *s, const uint8_t *limit, diff --git a/deps/icu-small/source/common/charstr.cpp b/deps/icu-small/source/common/charstr.cpp index dda29dac63273c..318a185b3f1d64 100644 --- a/deps/icu-small/source/common/charstr.cpp +++ b/deps/icu-small/source/common/charstr.cpp @@ -20,6 +20,7 @@ #include "cmemory.h" #include "cstring.h" #include "uinvchar.h" +#include "ustr_imp.h" U_NAMESPACE_BEGIN @@ -46,6 +47,19 @@ char *CharString::cloneData(UErrorCode &errorCode) const { return p; } +int32_t CharString::extract(char *dest, int32_t capacity, UErrorCode &errorCode) const { + if (U_FAILURE(errorCode)) { return len; } + if (capacity < 0 || (capacity > 0 && dest == nullptr)) { + errorCode = U_ILLEGAL_ARGUMENT_ERROR; + return len; + } + const char *src = buffer.getAlias(); + if (0 < len && len <= capacity && src != dest) { + uprv_memcpy(dest, src, len); + } + return u_terminateChars(dest, capacity, len, &errorCode); +} + CharString &CharString::copyFrom(const CharString &s, UErrorCode &errorCode) { if(U_SUCCESS(errorCode) && this!=&s && ensureCapacity(s.len+1, 0, errorCode)) { len=s.len; @@ -197,7 +211,7 @@ CharString &CharString::appendPathPart(StringPiece s, UErrorCode &errorCode) { } char c; if(len>0 && (c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) { - append(U_FILE_SEP_CHAR, errorCode); + append(getDirSepChar(), errorCode); } append(s, errorCode); return *this; @@ -207,9 +221,19 @@ CharString &CharString::ensureEndsWithFileSeparator(UErrorCode &errorCode) { char c; if(U_SUCCESS(errorCode) && len>0 && (c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) { - append(U_FILE_SEP_CHAR, errorCode); + append(getDirSepChar(), errorCode); } return *this; } +char CharString::getDirSepChar() const { + char dirSepChar = U_FILE_SEP_CHAR; +#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) + // We may need to return a different directory separator when building for Cygwin or MSYS2. + if(len>0 && !uprv_strchr(data(), U_FILE_SEP_CHAR) && uprv_strchr(data(), U_FILE_ALT_SEP_CHAR)) + dirSepChar = U_FILE_ALT_SEP_CHAR; +#endif + return dirSepChar; +} + U_NAMESPACE_END diff --git a/deps/icu-small/source/common/charstr.h b/deps/icu-small/source/common/charstr.h index 23b950ed6ecc76..6619faac618193 100644 --- a/deps/icu-small/source/common/charstr.h +++ b/deps/icu-small/source/common/charstr.h @@ -87,6 +87,22 @@ class U_COMMON_API CharString : public UMemory { * The caller must uprv_free() the result. */ char *cloneData(UErrorCode &errorCode) const; + /** + * Copies the contents of the string into dest. + * Checks if there is enough space in dest, extracts the entire string if possible, + * and NUL-terminates dest if possible. + * + * If the string fits into dest but cannot be NUL-terminated (length()==capacity), + * then the error code is set to U_STRING_NOT_TERMINATED_WARNING. + * If the string itself does not fit into dest (length()>capacity), + * then the error code is set to U_BUFFER_OVERFLOW_ERROR. + * + * @param dest Destination string buffer. + * @param capacity Size of the dest buffer (number of chars). + * @param errorCode ICU error code. + * @return length() + */ + int32_t extract(char *dest, int32_t capacity, UErrorCode &errorCode) const; bool operator==(StringPiece other) const { return len == other.length() && (len == 0 || uprv_memcmp(data(), other.data(), len) == 0); @@ -141,13 +157,13 @@ class U_COMMON_API CharString : public UMemory { /** * Appends a filename/path part, e.g., a directory name. - * First appends a U_FILE_SEP_CHAR if necessary. + * First appends a U_FILE_SEP_CHAR or U_FILE_ALT_SEP_CHAR if necessary. * Does nothing if s is empty. */ CharString &appendPathPart(StringPiece s, UErrorCode &errorCode); /** - * Appends a U_FILE_SEP_CHAR if this string is not empty + * Appends a U_FILE_SEP_CHAR or U_FILE_ALT_SEP_CHAR if this string is not empty * and does not already end with a U_FILE_SEP_CHAR or U_FILE_ALT_SEP_CHAR. */ CharString &ensureEndsWithFileSeparator(UErrorCode &errorCode); @@ -160,6 +176,12 @@ class U_COMMON_API CharString : public UMemory { CharString(const CharString &other); // forbid copying of this class CharString &operator=(const CharString &other); // forbid copying of this class + + /** + * Returns U_FILE_ALT_SEP_CHAR if found in string, and U_FILE_SEP_CHAR is not found. + * Otherwise returns U_FILE_SEP_CHAR. + */ + char getDirSepChar() const; }; U_NAMESPACE_END diff --git a/deps/icu-small/source/common/charstrmap.h b/deps/icu-small/source/common/charstrmap.h new file mode 100644 index 00000000000000..3320a4620852ce --- /dev/null +++ b/deps/icu-small/source/common/charstrmap.h @@ -0,0 +1,55 @@ +// © 2020 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +// charstrmap.h +// created: 2020sep01 Frank Yung-Fong Tang + +#ifndef __CHARSTRMAP_H__ +#define __CHARSTRMAP_H__ + +#include +#include "unicode/utypes.h" +#include "unicode/uobject.h" +#include "uhash.h" + +U_NAMESPACE_BEGIN + +/** + * Map of const char * keys & values. + * Stores pointers as is: Does not own/copy/adopt/release strings. + */ +class CharStringMap final : public UMemory { +public: + /** Constructs an unusable non-map. */ + CharStringMap() : map(nullptr) {} + CharStringMap(int32_t size, UErrorCode &errorCode) { + map = uhash_openSize(uhash_hashChars, uhash_compareChars, uhash_compareChars, + size, &errorCode); + } + CharStringMap(CharStringMap &&other) U_NOEXCEPT : map(other.map) { + other.map = nullptr; + } + CharStringMap(const CharStringMap &other) = delete; + ~CharStringMap() { + uhash_close(map); + } + + CharStringMap &operator=(CharStringMap &&other) U_NOEXCEPT { + map = other.map; + other.map = nullptr; + return *this; + } + CharStringMap &operator=(const CharStringMap &other) = delete; + + const char *get(const char *key) const { return static_cast(uhash_get(map, key)); } + void put(const char *key, const char *value, UErrorCode &errorCode) { + uhash_put(map, const_cast(key), const_cast(value), &errorCode); + } + +private: + UHashtable *map; +}; + +U_NAMESPACE_END + +#endif // __CHARSTRMAP_H__ diff --git a/deps/icu-small/source/common/cmemory.h b/deps/icu-small/source/common/cmemory.h index 38f99179631b10..b5e0c2b7a17296 100644 --- a/deps/icu-small/source/common/cmemory.h +++ b/deps/icu-small/source/common/cmemory.h @@ -292,14 +292,21 @@ class MaybeStackArray { /** * Default constructor initializes with internal T[stackCapacity] buffer. */ - MaybeStackArray() : ptr(stackArray), capacity(stackCapacity), needToRelease(FALSE) {} + MaybeStackArray() : ptr(stackArray), capacity(stackCapacity), needToRelease(false) {} /** * Automatically allocates the heap array if the argument is larger than the stack capacity. * Intended for use when an approximate capacity is known at compile time but the true * capacity is not known until runtime. */ - MaybeStackArray(int32_t newCapacity) : MaybeStackArray() { - if (capacity < newCapacity) { resize(newCapacity); } + MaybeStackArray(int32_t newCapacity, UErrorCode status) : MaybeStackArray() { + if (U_FAILURE(status)) { + return; + } + if (capacity < newCapacity) { + if (resize(newCapacity) == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + } + } } /** * Destructor deletes the array (if owned). @@ -355,7 +362,7 @@ class MaybeStackArray { releaseArray(); ptr=otherArray; capacity=otherCapacity; - needToRelease=FALSE; + needToRelease=false; } } /** @@ -380,6 +387,20 @@ class MaybeStackArray { * caller becomes responsible for deleting the array */ inline T *orphanOrClone(int32_t length, int32_t &resultCapacity); + +protected: + // Resizes the array to the size of src, then copies the contents of src. + void copyFrom(const MaybeStackArray &src, UErrorCode &status) { + if (U_FAILURE(status)) { + return; + } + if (this->resize(src.capacity, 0) == NULL) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + uprv_memcpy(this->ptr, src.ptr, (size_t)capacity * sizeof(T)); + } + private: T *ptr; int32_t capacity; @@ -393,14 +414,14 @@ class MaybeStackArray { void resetToStackArray() { ptr=stackArray; capacity=stackCapacity; - needToRelease=FALSE; + needToRelease=false; } /* No comparison operators with other MaybeStackArray's. */ - bool operator==(const MaybeStackArray & /*other*/) {return FALSE;} - bool operator!=(const MaybeStackArray & /*other*/) {return TRUE;} + bool operator==(const MaybeStackArray & /*other*/) = delete; + bool operator!=(const MaybeStackArray & /*other*/) = delete; /* No ownership transfer: No copy constructor, no assignment operator. */ - MaybeStackArray(const MaybeStackArray & /*other*/) {} - void operator=(const MaybeStackArray & /*other*/) {} + MaybeStackArray(const MaybeStackArray & /*other*/) = delete; + void operator=(const MaybeStackArray & /*other*/) = delete; }; template @@ -435,7 +456,7 @@ template inline T *MaybeStackArray::resize(int32_t newCapacity, int32_t length) { if(newCapacity>0) { #if U_DEBUG && defined(UPRV_MALLOC_COUNT) - ::fprintf(::stderr,"MaybeStacArray (resize) alloc %d * %lu\n", newCapacity,sizeof(T)); + ::fprintf(::stderr, "MaybeStackArray (resize) alloc %d * %lu\n", newCapacity, sizeof(T)); #endif T *p=(T *)uprv_malloc(newCapacity*sizeof(T)); if(p!=NULL) { @@ -451,7 +472,7 @@ inline T *MaybeStackArray::resize(int32_t newCapacity, int32_t releaseArray(); ptr=p; capacity=newCapacity; - needToRelease=TRUE; + needToRelease=true; } return p; } else { @@ -507,7 +528,7 @@ class MaybeStackHeaderAndArray { /** * Default constructor initializes with internal H+T[stackCapacity] buffer. */ - MaybeStackHeaderAndArray() : ptr(&stackHeader), capacity(stackCapacity), needToRelease(FALSE) {} + MaybeStackHeaderAndArray() : ptr(&stackHeader), capacity(stackCapacity), needToRelease(false) {} /** * Destructor deletes the memory (if owned). */ @@ -556,7 +577,7 @@ class MaybeStackHeaderAndArray { releaseMemory(); ptr=otherMemory; capacity=otherCapacity; - needToRelease=FALSE; + needToRelease=false; } } /** @@ -595,8 +616,8 @@ class MaybeStackHeaderAndArray { } } /* No comparison operators with other MaybeStackHeaderAndArray's. */ - bool operator==(const MaybeStackHeaderAndArray & /*other*/) {return FALSE;} - bool operator!=(const MaybeStackHeaderAndArray & /*other*/) {return TRUE;} + bool operator==(const MaybeStackHeaderAndArray & /*other*/) {return false;} + bool operator!=(const MaybeStackHeaderAndArray & /*other*/) {return true;} /* No ownership transfer: No copy constructor, no assignment operator. */ MaybeStackHeaderAndArray(const MaybeStackHeaderAndArray & /*other*/) {} void operator=(const MaybeStackHeaderAndArray & /*other*/) {} @@ -625,7 +646,7 @@ inline H *MaybeStackHeaderAndArray::resize(int32_t newCapac releaseMemory(); ptr=p; capacity=newCapacity; - needToRelease=TRUE; + needToRelease=true; } return p; } else { @@ -657,7 +678,7 @@ inline H *MaybeStackHeaderAndArray::orphanOrClone(int32_t l resultCapacity=length; ptr=&stackHeader; capacity=stackCapacity; - needToRelease=FALSE; + needToRelease=false; return p; } @@ -728,6 +749,18 @@ class MemoryPool : public UMemory { return fPool[fCount++] = new T(std::forward(args)...); } + template + T* createAndCheckErrorCode(UErrorCode &status, Args &&... args) { + if (U_FAILURE(status)) { + return nullptr; + } + T *pointer = this->create(args...); + if (U_SUCCESS(status) && pointer == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + } + return pointer; + } + /** * @return Number of elements that have been allocated. */ @@ -771,6 +804,11 @@ class MaybeStackVector : protected MemoryPool { return this->create(args...); } + template + T *emplaceBackAndCheckErrorCode(UErrorCode &status, Args &&... args) { + return this->createAndCheckErrorCode(status, args...); + } + int32_t length() const { return this->fCount; } @@ -779,6 +817,10 @@ class MaybeStackVector : protected MemoryPool { return this->fPool.getAlias(); } + const T *const *getAlias() const { + return this->fPool.getAlias(); + } + /** * Array item access (read-only). * No index bounds check. @@ -798,19 +840,6 @@ class MaybeStackVector : protected MemoryPool { T* operator[](ptrdiff_t i) { return this->fPool[i]; } - - /** - * Append all the items from another MaybeStackVector to this one. - */ - void appendAll(const MaybeStackVector& other, UErrorCode& status) { - for (int32_t i = 0; i < other.fCount; i++) { - T* item = emplaceBack(*other[i]); - if (!item) { - status = U_MEMORY_ALLOCATION_ERROR; - return; - } - } - } }; diff --git a/deps/icu-small/source/common/dictbe.h b/deps/icu-small/source/common/dictbe.h index 99d176cc2e7bcf..246c1dc6935fbd 100644 --- a/deps/icu-small/source/common/dictbe.h +++ b/deps/icu-small/source/common/dictbe.h @@ -59,7 +59,7 @@ class DictionaryBreakEngine : public LanguageBreakEngine { * a particular kind of break.

* * @param c A character which begins a run that the engine might handle - * @return TRUE if this engine handles the particular character and break + * @return true if this engine handles the particular character and break * type. */ virtual UBool handles(UChar32 c) const; diff --git a/deps/icu-small/source/common/icuplug.cpp b/deps/icu-small/source/common/icuplug.cpp index c3c8231b77d572..944df5465d0dd2 100644 --- a/deps/icu-small/source/common/icuplug.cpp +++ b/deps/icu-small/source/common/icuplug.cpp @@ -145,7 +145,7 @@ static int32_t searchForLibrary(void *lib) { return -1; } -U_INTERNAL char * U_EXPORT2 +U_CAPI char * U_EXPORT2 uplug_findLibrary(void *lib, UErrorCode *status) { int32_t libEnt; char *ret = NULL; @@ -161,7 +161,7 @@ uplug_findLibrary(void *lib, UErrorCode *status) { return ret; } -U_INTERNAL void * U_EXPORT2 +U_CAPI void * U_EXPORT2 uplug_openLibrary(const char *libName, UErrorCode *status) { int32_t libEntry = -1; void *lib = NULL; @@ -209,7 +209,7 @@ uplug_openLibrary(const char *libName, UErrorCode *status) { return lib; } -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uplug_closeLibrary(void *lib, UErrorCode *status) { int32_t i; @@ -507,7 +507,7 @@ uplug_getConfiguration(UPlugData *data) { return data->config; } -U_INTERNAL UPlugData* U_EXPORT2 +U_CAPI UPlugData* U_EXPORT2 uplug_getPlugInternal(int32_t n) { if(n <0 || n >= pluginCount) { return NULL; @@ -707,7 +707,7 @@ static void uplug_loadWaitingPlugs(UErrorCode *status) { static char plugin_file[2048] = ""; #endif -U_INTERNAL const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uplug_getPluginFile() { #if U_ENABLE_DYLOAD && !UCONFIG_NO_FILE_IO return plugin_file; @@ -782,7 +782,7 @@ uplug_init(UErrorCode *status) { /* plugin_file is not used for processing - it is only used so that uplug_getPluginFile() works (i.e. icuinfo) */ - uprv_strncpy(plugin_file, pluginFile.data(), sizeof(plugin_file)); + pluginFile.extract(plugin_file, sizeof(plugin_file), *status); #if UPLUG_TRACE DBG((stderr, "pluginfile= %s len %d/%d\n", plugin_file, (int)strlen(plugin_file), (int)sizeof(plugin_file))); diff --git a/deps/icu-small/source/common/icuplugimp.h b/deps/icu-small/source/common/icuplugimp.h index 282c639b40e271..712fdb236fde35 100644 --- a/deps/icu-small/source/common/icuplugimp.h +++ b/deps/icu-small/source/common/icuplugimp.h @@ -36,7 +36,7 @@ * @return the library pointer, or NULL * @internal internal use only */ -U_INTERNAL void * U_EXPORT2 +U_CAPI void * U_EXPORT2 uplug_openLibrary(const char *libName, UErrorCode *status); /** @@ -45,7 +45,7 @@ uplug_openLibrary(const char *libName, UErrorCode *status); * @param status error code * @internal internal use only */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uplug_closeLibrary(void *lib, UErrorCode *status); /** @@ -55,7 +55,7 @@ uplug_closeLibrary(void *lib, UErrorCode *status); * @return the library name, or NULL if not found. * @internal internal use only */ -U_INTERNAL char * U_EXPORT2 +U_CAPI char * U_EXPORT2 uplug_findLibrary(void *lib, UErrorCode *status); /** @} */ @@ -69,21 +69,21 @@ uplug_findLibrary(void *lib, UErrorCode *status); * @param status error result * @internal - Internal use only. */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uplug_init(UErrorCode *status); /** * Get raw plug N * @internal - Internal use only */ -U_INTERNAL UPlugData* U_EXPORT2 +U_CAPI UPlugData* U_EXPORT2 uplug_getPlugInternal(int32_t n); /** * Get the name of the plugin file. * @internal - Internal use only. */ -U_INTERNAL const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uplug_getPluginFile(void); /** @} */ diff --git a/deps/icu-small/source/common/localematcher.cpp b/deps/icu-small/source/common/localematcher.cpp index 85db8c8bf3246d..5795cbf87e633a 100644 --- a/deps/icu-small/source/common/localematcher.cpp +++ b/deps/icu-small/source/common/localematcher.cpp @@ -1,12 +1,9 @@ // © 2019 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html // localematcher.cpp // created: 2019may08 Markus W. Scherer -#ifndef __LOCMATCHER_H__ -#define __LOCMATCHER_H__ - #include "unicode/utypes.h" #include "unicode/localebuilder.h" #include "unicode/localematcher.h" @@ -131,6 +128,7 @@ LocaleMatcher::Builder::Builder(LocaleMatcher::Builder &&src) U_NOEXCEPT : thresholdDistance_(src.thresholdDistance_), demotion_(src.demotion_), defaultLocale_(src.defaultLocale_), + withDefault_(src.withDefault_), favor_(src.favor_), direction_(src.direction_) { src.supportedLocales_ = nullptr; @@ -140,6 +138,8 @@ LocaleMatcher::Builder::Builder(LocaleMatcher::Builder &&src) U_NOEXCEPT : LocaleMatcher::Builder::~Builder() { delete supportedLocales_; delete defaultLocale_; + delete maxDistanceDesired_; + delete maxDistanceSupported_; } LocaleMatcher::Builder &LocaleMatcher::Builder::operator=(LocaleMatcher::Builder &&src) U_NOEXCEPT { @@ -150,6 +150,7 @@ LocaleMatcher::Builder &LocaleMatcher::Builder::operator=(LocaleMatcher::Builder thresholdDistance_ = src.thresholdDistance_; demotion_ = src.demotion_; defaultLocale_ = src.defaultLocale_; + withDefault_ = src.withDefault_, favor_ = src.favor_; direction_ = src.direction_; @@ -229,6 +230,14 @@ LocaleMatcher::Builder &LocaleMatcher::Builder::addSupportedLocale(const Locale return *this; } +LocaleMatcher::Builder &LocaleMatcher::Builder::setNoDefaultLocale() { + if (U_FAILURE(errorCode_)) { return *this; } + delete defaultLocale_; + defaultLocale_ = nullptr; + withDefault_ = false; + return *this; +} + LocaleMatcher::Builder &LocaleMatcher::Builder::setDefaultLocale(const Locale *defaultLocale) { if (U_FAILURE(errorCode_)) { return *this; } Locale *clone = nullptr; @@ -241,6 +250,7 @@ LocaleMatcher::Builder &LocaleMatcher::Builder::setDefaultLocale(const Locale *d } delete defaultLocale_; defaultLocale_ = clone; + withDefault_ = true; return *this; } @@ -256,6 +266,24 @@ LocaleMatcher::Builder &LocaleMatcher::Builder::setDemotionPerDesiredLocale(ULoc return *this; } +LocaleMatcher::Builder &LocaleMatcher::Builder::setMaxDistance(const Locale &desired, + const Locale &supported) { + if (U_FAILURE(errorCode_)) { return *this; } + Locale *desiredClone = desired.clone(); + Locale *supportedClone = supported.clone(); + if (desiredClone == nullptr || supportedClone == nullptr) { + delete desiredClone; // in case only one could not be allocated + delete supportedClone; + errorCode_ = U_MEMORY_ALLOCATION_ERROR; + return *this; + } + delete maxDistanceDesired_; + delete maxDistanceSupported_; + maxDistanceDesired_ = desiredClone; + maxDistanceSupported_ = supportedClone; + return *this; +} + #if 0 /** * Internal only! @@ -340,9 +368,6 @@ LocaleMatcher::LocaleMatcher(const Builder &builder, UErrorCode &errorCode) : supportedLSRs(nullptr), supportedIndexes(nullptr), supportedLSRsLength(0), ownedDefaultLocale(nullptr), defaultLocale(nullptr) { if (U_FAILURE(errorCode)) { return; } - if (thresholdDistance < 0) { - thresholdDistance = localeDistance.getDefaultScriptDistance(); - } const Locale *def = builder.defaultLocale_; LSR builderDefaultLSR; const LSR *defLSR = nullptr; @@ -408,22 +433,20 @@ LocaleMatcher::LocaleMatcher(const Builder &builder, UErrorCode &errorCode) : int32_t suppLength = 0; // Determine insertion order. // Add locales immediately that are equivalent to the default. - MaybeStackArray order(supportedLocalesLength); - if (order.getAlias() == nullptr) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - return; - } + MaybeStackArray order(supportedLocalesLength, errorCode); + if (U_FAILURE(errorCode)) { return; } int32_t numParadigms = 0; for (int32_t i = 0; i < supportedLocalesLength; ++i) { const Locale &locale = *supportedLocales[i]; const LSR &lsr = lsrs[i]; - if (defLSR == nullptr) { + if (defLSR == nullptr && builder.withDefault_) { + // Implicit default locale = first supported locale, if not turned off. U_ASSERT(i == 0); def = &locale; defLSR = &lsr; order[i] = 1; suppLength = putIfAbsent(lsr, 0, suppLength, errorCode); - } else if (lsr.isEquivalentTo(*defLSR)) { + } else if (defLSR != nullptr && lsr.isEquivalentTo(*defLSR)) { order[i] = 1; suppLength = putIfAbsent(lsr, i, suppLength, errorCode); } else if (localeDistance.isParadigmLSR(lsr)) { @@ -458,6 +481,25 @@ LocaleMatcher::LocaleMatcher(const Builder &builder, UErrorCode &errorCode) : if (builder.demotion_ == ULOCMATCH_DEMOTION_REGION) { demotionPerDesiredLocale = localeDistance.getDefaultDemotionPerDesiredLocale(); } + + if (thresholdDistance >= 0) { + // already copied + } else if (builder.maxDistanceDesired_ != nullptr) { + LSR suppLSR = getMaximalLsrOrUnd(likelySubtags, *builder.maxDistanceSupported_, errorCode); + const LSR *pSuppLSR = &suppLSR; + int32_t indexAndDistance = localeDistance.getBestIndexAndDistance( + getMaximalLsrOrUnd(likelySubtags, *builder.maxDistanceDesired_, errorCode), + &pSuppLSR, 1, + LocaleDistance::shiftDistance(100), favorSubtag, direction); + if (U_SUCCESS(errorCode)) { + // +1 for an exclusive threshold from an inclusive max. + thresholdDistance = LocaleDistance::getDistanceFloor(indexAndDistance) + 1; + } else { + thresholdDistance = 0; + } + } else { + thresholdDistance = localeDistance.getDefaultScriptDistance(); + } } LocaleMatcher::LocaleMatcher(LocaleMatcher &&src) U_NOEXCEPT : @@ -683,6 +725,18 @@ int32_t LocaleMatcher::getBestSuppIndex(LSR desiredLSR, LocaleLsrIterator *remai return supportedIndexes[bestSupportedLsrIndex]; } +UBool LocaleMatcher::isMatch(const Locale &desired, const Locale &supported, + UErrorCode &errorCode) const { + LSR suppLSR = getMaximalLsrOrUnd(likelySubtags, supported, errorCode); + if (U_FAILURE(errorCode)) { return 0; } + const LSR *pSuppLSR = &suppLSR; + int32_t indexAndDistance = localeDistance.getBestIndexAndDistance( + getMaximalLsrOrUnd(likelySubtags, desired, errorCode), + &pSuppLSR, 1, + LocaleDistance::shiftDistance(thresholdDistance), favorSubtag, direction); + return indexAndDistance >= 0; +} + double LocaleMatcher::internalMatch(const Locale &desired, const Locale &supported, UErrorCode &errorCode) const { // Returns the inverse of the distance: That is, 1-distance(desired, supported). LSR suppLSR = getMaximalLsrOrUnd(likelySubtags, supported, errorCode); @@ -790,5 +844,3 @@ uloc_acceptLanguageFromHTTP(char *result, int32_t resultAvailable, return acceptLanguage(*availableLocales, desiredLocales, result, resultAvailable, outResult, *status); } - -#endif // __LOCMATCHER_H__ diff --git a/deps/icu-small/source/common/localeprioritylist.cpp b/deps/icu-small/source/common/localeprioritylist.cpp index cee408269c9b39..8916b121be3057 100644 --- a/deps/icu-small/source/common/localeprioritylist.cpp +++ b/deps/icu-small/source/common/localeprioritylist.cpp @@ -1,5 +1,5 @@ // © 2019 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html // localeprioritylist.cpp // created: 2019jul11 Markus W. Scherer diff --git a/deps/icu-small/source/common/localeprioritylist.h b/deps/icu-small/source/common/localeprioritylist.h index 80ca38a7b52892..41e9d3ea081f56 100644 --- a/deps/icu-small/source/common/localeprioritylist.h +++ b/deps/icu-small/source/common/localeprioritylist.h @@ -1,5 +1,5 @@ // © 2019 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html // localeprioritylist.h // created: 2019jul11 Markus W. Scherer diff --git a/deps/icu-small/source/common/locdispnames.cpp b/deps/icu-small/source/common/locdispnames.cpp index 7216a3a3083e3d..a60dd0c9c1ffa7 100644 --- a/deps/icu-small/source/common/locdispnames.cpp +++ b/deps/icu-small/source/common/locdispnames.cpp @@ -26,6 +26,8 @@ #include "unicode/uloc.h" #include "unicode/ures.h" #include "unicode/ustring.h" +#include "bytesinkutil.h" +#include "charstr.h" #include "cmemory.h" #include "cstring.h" #include "putilimp.h" @@ -406,20 +408,26 @@ uloc_getDisplayScript(const char* locale, UChar *dest, int32_t destCapacity, UErrorCode *pErrorCode) { - UErrorCode err = U_ZERO_ERROR; - int32_t res = _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, + UErrorCode err = U_ZERO_ERROR; + int32_t res = _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, uloc_getScript, _kScriptsStandAlone, &err); - if ( err == U_USING_DEFAULT_WARNING ) { + if (destCapacity == 0 && err == U_BUFFER_OVERFLOW_ERROR) { + // For preflight, return the max of the value and the fallback. + int32_t fallback_res = _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, + uloc_getScript, _kScripts, pErrorCode); + return (fallback_res > res) ? fallback_res : res; + } + if ( err == U_USING_DEFAULT_WARNING ) { return _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, - uloc_getScript, _kScripts, pErrorCode); - } else { - *pErrorCode = err; - return res; - } + uloc_getScript, _kScripts, pErrorCode); + } else { + *pErrorCode = err; + return res; + } } -U_INTERNAL int32_t U_EXPORT2 +static int32_t uloc_getDisplayScriptInContext(const char* locale, const char* displayLocale, UChar *dest, int32_t destCapacity, @@ -727,7 +735,7 @@ uloc_getDisplayName(const char *locale, int32_t padLen; patPos+=subLen; padLen=(subi==0 ? sub1Pos : patLen)-patPos; - if(length+padLen < destCapacity) { + if(length+padLen <= destCapacity) { p=dest+length; for(int32_t i=0;i> DISTANCE_SHIFT; + } + static int32_t getIndex(int32_t indexAndDistance) { // assert indexAndDistance >= 0; return indexAndDistance >> INDEX_SHIFT; @@ -79,10 +83,6 @@ class LocaleDistance final : public UMemory { // tic constexpr int32_t MAX_INDEX = 0x1fffff; // avoids sign bit static constexpr int32_t INDEX_NEG_1 = 0xfffffc00; - static int32_t getDistanceFloor(int32_t indexAndDistance) { - return (indexAndDistance & DISTANCE_MASK) >> DISTANCE_SHIFT; - } - LocaleDistance(const LocaleDistanceData &data, const XLikelySubtags &likely); LocaleDistance(const LocaleDistance &other) = delete; LocaleDistance &operator=(const LocaleDistance &other) = delete; diff --git a/deps/icu-small/source/common/locid.cpp b/deps/icu-small/source/common/locid.cpp index 753a452120ee62..2804e36bf62cb1 100644 --- a/deps/icu-small/source/common/locid.cpp +++ b/deps/icu-small/source/common/locid.cpp @@ -42,6 +42,7 @@ #include "bytesinkutil.h" #include "charstr.h" +#include "charstrmap.h" #include "cmemory.h" #include "cstring.h" #include "mutex.h" @@ -51,7 +52,9 @@ #include "uhash.h" #include "ulocimp.h" #include "umutex.h" +#include "uniquecharstr.h" #include "ustr_imp.h" +#include "uvector.h" U_CDECL_BEGIN static UBool U_CALLCONV locale_cleanup(void); @@ -102,12 +105,6 @@ typedef enum ELocalePos { eMAX_LOCALES } ELocalePos; -U_CFUNC int32_t locale_getKeywords(const char *localeID, - char prev, - char *keywords, int32_t keywordCapacity, - UBool valuesToo, - UErrorCode *status); - U_CDECL_BEGIN // // Deleter function for Locales owned by the default Locale hash table/ @@ -252,6 +249,7 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Locale) // '_' // In the platform codepage. #define SEP_CHAR '_' +#define NULL_CHAR '\0' Locale::~Locale() { @@ -506,38 +504,1127 @@ Locale::operator==( const Locale& other) const return (uprv_strcmp(other.fullName, fullName) == 0); } -#define ISASCIIALPHA(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) - namespace { -CharString& AppendLSCVE(CharString& out, const char* language, const char* script, - const char* country, const char* variants, const char* extension, - UErrorCode& status) { +UInitOnce gKnownCanonicalizedInitOnce = U_INITONCE_INITIALIZER; +UHashtable *gKnownCanonicalized = nullptr; + +static const char* const KNOWN_CANONICALIZED[] = { + "c", + // Commonly used locales known are already canonicalized + "af", "af_ZA", "am", "am_ET", "ar", "ar_001", "as", "as_IN", "az", "az_AZ", + "be", "be_BY", "bg", "bg_BG", "bn", "bn_IN", "bs", "bs_BA", "ca", "ca_ES", + "cs", "cs_CZ", "cy", "cy_GB", "da", "da_DK", "de", "de_DE", "el", "el_GR", + "en", "en_GB", "en_US", "es", "es_419", "es_ES", "et", "et_EE", "eu", + "eu_ES", "fa", "fa_IR", "fi", "fi_FI", "fil", "fil_PH", "fr", "fr_FR", + "ga", "ga_IE", "gl", "gl_ES", "gu", "gu_IN", "he", "he_IL", "hi", "hi_IN", + "hr", "hr_HR", "hu", "hu_HU", "hy", "hy_AM", "id", "id_ID", "is", "is_IS", + "it", "it_IT", "ja", "ja_JP", "jv", "jv_ID", "ka", "ka_GE", "kk", "kk_KZ", + "km", "km_KH", "kn", "kn_IN", "ko", "ko_KR", "ky", "ky_KG", "lo", "lo_LA", + "lt", "lt_LT", "lv", "lv_LV", "mk", "mk_MK", "ml", "ml_IN", "mn", "mn_MN", + "mr", "mr_IN", "ms", "ms_MY", "my", "my_MM", "nb", "nb_NO", "ne", "ne_NP", + "nl", "nl_NL", "or", "or_IN", "pa", "pa_IN", "pl", "pl_PL", "ps", "ps_AF", + "pt", "pt_BR", "pt_PT", "ro", "ro_RO", "ru", "ru_RU", "sd", "sd_IN", "si", + "si_LK", "sk", "sk_SK", "sl", "sl_SI", "so", "so_SO", "sq", "sq_AL", "sr", + "sr_Cyrl_RS", "sr_Latn", "sr_RS", "sv", "sv_SE", "sw", "sw_TZ", "ta", + "ta_IN", "te", "te_IN", "th", "th_TH", "tk", "tk_TM", "tr", "tr_TR", "uk", + "uk_UA", "ur", "ur_PK", "uz", "uz_UZ", "vi", "vi_VN", "yue", "yue_Hant", + "yue_Hant_HK", "yue_HK", "zh", "zh_CN", "zh_Hans", "zh_Hans_CN", "zh_Hant", + "zh_Hant_TW", "zh_TW", "zu", "zu_ZA" +}; + +static UBool U_CALLCONV cleanupKnownCanonicalized() { + gKnownCanonicalizedInitOnce.reset(); + if (gKnownCanonicalized) { uhash_close(gKnownCanonicalized); } + return TRUE; +} + +static void U_CALLCONV loadKnownCanonicalized(UErrorCode &status) { + ucln_common_registerCleanup(UCLN_COMMON_LOCALE_KNOWN_CANONICALIZED, + cleanupKnownCanonicalized); + LocalUHashtablePointer newKnownCanonicalizedMap( + uhash_open(uhash_hashChars, uhash_compareChars, nullptr, &status)); + for (int32_t i = 0; + U_SUCCESS(status) && i < UPRV_LENGTHOF(KNOWN_CANONICALIZED); + i++) { + uhash_puti(newKnownCanonicalizedMap.getAlias(), + (void*)KNOWN_CANONICALIZED[i], + 1, &status); + } + if (U_FAILURE(status)) { + return; + } + + gKnownCanonicalized = newKnownCanonicalizedMap.orphan(); +} + +class AliasData; + +/** + * A Builder class to build the alias data. + */ +class AliasDataBuilder { +public: + AliasDataBuilder() { + } + + // Build the AliasData from resource. + AliasData* build(UErrorCode &status); + +private: + void readAlias(UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, + void (*checkType)(const char* type), + void (*checkReplacement)(const UnicodeString& replacement), + UErrorCode &status); + + // Read the languageAlias data from alias to + // strings+types+replacementIndexes + // The number of record will be stored into length. + // Allocate length items for types, to store the type field. + // Allocate length items for replacementIndexes, + // to store the index in the strings for the replacement script. + void readLanguageAlias(UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, + UErrorCode &status); + + // Read the scriptAlias data from alias to + // strings+types+replacementIndexes + // Allocate length items for types, to store the type field. + // Allocate length items for replacementIndexes, + // to store the index in the strings for the replacement script. + void readScriptAlias(UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, UErrorCode &status); + + // Read the territoryAlias data from alias to + // strings+types+replacementIndexes + // Allocate length items for types, to store the type field. + // Allocate length items for replacementIndexes, + // to store the index in the strings for the replacement script. + void readTerritoryAlias(UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, UErrorCode &status); + + // Read the variantAlias data from alias to + // strings+types+replacementIndexes + // Allocate length items for types, to store the type field. + // Allocate length items for replacementIndexes, + // to store the index in the strings for the replacement variant. + void readVariantAlias(UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, UErrorCode &status); +}; + +/** + * A class to hold the Alias Data. + */ +class AliasData : public UMemory { +public: + static const AliasData* singleton(UErrorCode& status) { + if (U_FAILURE(status)) { + // Do not get into loadData if the status already has error. + return nullptr; + } + umtx_initOnce(AliasData::gInitOnce, &AliasData::loadData, status); + return gSingleton; + } + + const CharStringMap& languageMap() const { return language; } + const CharStringMap& scriptMap() const { return script; } + const CharStringMap& territoryMap() const { return territory; } + const CharStringMap& variantMap() const { return variant; } + + static void U_CALLCONV loadData(UErrorCode &status); + static UBool U_CALLCONV cleanup(); + + static UInitOnce gInitOnce; + +private: + AliasData(CharStringMap languageMap, + CharStringMap scriptMap, + CharStringMap territoryMap, + CharStringMap variantMap, + CharString* strings) + : language(std::move(languageMap)), + script(std::move(scriptMap)), + territory(std::move(territoryMap)), + variant(std::move(variantMap)), + strings(strings) { + } + + ~AliasData() { + delete strings; + } + + static const AliasData* gSingleton; + + CharStringMap language; + CharStringMap script; + CharStringMap territory; + CharStringMap variant; + CharString* strings; + + friend class AliasDataBuilder; +}; + + +const AliasData* AliasData::gSingleton = nullptr; +UInitOnce AliasData::gInitOnce = U_INITONCE_INITIALIZER; + +UBool U_CALLCONV +AliasData::cleanup() +{ + gInitOnce.reset(); + delete gSingleton; + return TRUE; +} + +void +AliasDataBuilder::readAlias( + UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, + void (*checkType)(const char* type), + void (*checkReplacement)(const UnicodeString& replacement), + UErrorCode &status) { + if (U_FAILURE(status)) { + return; + } + length = ures_getSize(alias); + const char** rawTypes = types.allocateInsteadAndCopy(length); + if (rawTypes == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + int32_t* rawIndexes = replacementIndexes.allocateInsteadAndCopy(length); + if (rawIndexes == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + int i = 0; + while (ures_hasNext(alias)) { + LocalUResourceBundlePointer res( + ures_getNextResource(alias, nullptr, &status)); + const char* aliasFrom = ures_getKey(res.getAlias()); + UnicodeString aliasTo = + ures_getUnicodeStringByKey(res.getAlias(), "replacement", &status); + + checkType(aliasFrom); + checkReplacement(aliasTo); + + rawTypes[i] = aliasFrom; + rawIndexes[i] = strings->add(aliasTo, status); + i++; + } +} + +/** + * Read the languageAlias data from alias to strings+types+replacementIndexes. + * Allocate length items for types, to store the type field. Allocate length + * items for replacementIndexes, to store the index in the strings for the + * replacement language. + */ +void +AliasDataBuilder::readLanguageAlias( + UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, + UErrorCode &status) +{ + return readAlias( + alias, strings, types, replacementIndexes, length, +#if U_DEBUG + [](const char* type) { + // Assert the aliasFrom only contains the following possibilties + // language_REGION_variant + // language_REGION + // language_variant + // language + // und_variant + Locale test(type); + // Assert no script in aliasFrom + U_ASSERT(test.getScript()[0] == '\0'); + // Assert when language is und, no REGION in aliasFrom. + U_ASSERT(test.getLanguage()[0] != '\0' || test.getCountry()[0] == '\0'); + }, +#else + [](const char*) {}, +#endif + [](const UnicodeString&) {}, status); +} + +/** + * Read the scriptAlias data from alias to strings+types+replacementIndexes. + * Allocate length items for types, to store the type field. Allocate length + * items for replacementIndexes, to store the index in the strings for the + * replacement script. + */ +void +AliasDataBuilder::readScriptAlias( + UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, + UErrorCode &status) +{ + return readAlias( + alias, strings, types, replacementIndexes, length, +#if U_DEBUG + [](const char* type) { + U_ASSERT(uprv_strlen(type) == 4); + }, + [](const UnicodeString& replacement) { + U_ASSERT(replacement.length() == 4); + }, +#else + [](const char*) {}, + [](const UnicodeString&) { }, +#endif + status); +} + +/** + * Read the territoryAlias data from alias to strings+types+replacementIndexes. + * Allocate length items for types, to store the type field. Allocate length + * items for replacementIndexes, to store the index in the strings for the + * replacement regions. + */ +void +AliasDataBuilder::readTerritoryAlias( + UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, + UErrorCode &status) +{ + return readAlias( + alias, strings, types, replacementIndexes, length, +#if U_DEBUG + [](const char* type) { + U_ASSERT(uprv_strlen(type) == 2 || uprv_strlen(type) == 3); + }, +#else + [](const char*) {}, +#endif + [](const UnicodeString&) { }, + status); +} + +/** + * Read the variantAlias data from alias to strings+types+replacementIndexes. + * Allocate length items for types, to store the type field. Allocate length + * items for replacementIndexes, to store the index in the strings for the + * replacement variant. + */ +void +AliasDataBuilder::readVariantAlias( + UResourceBundle* alias, + UniqueCharStrings* strings, + LocalMemory& types, + LocalMemory& replacementIndexes, + int32_t &length, + UErrorCode &status) +{ + return readAlias( + alias, strings, types, replacementIndexes, length, +#if U_DEBUG + [](const char* type) { + U_ASSERT(uprv_strlen(type) >= 4 && uprv_strlen(type) <= 8); + U_ASSERT(uprv_strlen(type) != 4 || + (type[0] >= '0' && type[0] <= '9')); + }, + [](const UnicodeString& replacement) { + U_ASSERT(replacement.length() >= 4 && replacement.length() <= 8); + U_ASSERT(replacement.length() != 4 || + (replacement.charAt(0) >= u'0' && + replacement.charAt(0) <= u'9')); + }, +#else + [](const char*) {}, + [](const UnicodeString&) { }, +#endif + status); +} + +/** + * Initializes the alias data from the ICU resource bundles. The alias data + * contains alias of language, country, script and variants. + * + * If the alias data has already loaded, then this method simply returns without + * doing anything meaningful. + */ +void U_CALLCONV +AliasData::loadData(UErrorCode &status) +{ +#ifdef LOCALE_CANONICALIZATION_DEBUG + UDate start = uprv_getRawUTCtime(); +#endif // LOCALE_CANONICALIZATION_DEBUG + ucln_common_registerCleanup(UCLN_COMMON_LOCALE_ALIAS, cleanup); + AliasDataBuilder builder; + gSingleton = builder.build(status); +#ifdef LOCALE_CANONICALIZATION_DEBUG + UDate end = uprv_getRawUTCtime(); + printf("AliasData::loadData took total %f ms\n", end - start); +#endif // LOCALE_CANONICALIZATION_DEBUG +} + +/** + * Build the alias data from resources. + */ +AliasData* +AliasDataBuilder::build(UErrorCode &status) { + LocalUResourceBundlePointer metadata( + ures_openDirect(nullptr, "metadata", &status)); + LocalUResourceBundlePointer metadataAlias( + ures_getByKey(metadata.getAlias(), "alias", nullptr, &status)); + LocalUResourceBundlePointer languageAlias( + ures_getByKey(metadataAlias.getAlias(), "language", nullptr, &status)); + LocalUResourceBundlePointer scriptAlias( + ures_getByKey(metadataAlias.getAlias(), "script", nullptr, &status)); + LocalUResourceBundlePointer territoryAlias( + ures_getByKey(metadataAlias.getAlias(), "territory", nullptr, &status)); + LocalUResourceBundlePointer variantAlias( + ures_getByKey(metadataAlias.getAlias(), "variant", nullptr, &status)); + + if (U_FAILURE(status)) { + return nullptr; + } + int32_t languagesLength = 0, scriptLength = 0, territoryLength = 0, + variantLength = 0; + + // Read the languageAlias into languageTypes, languageReplacementIndexes + // and strings + UniqueCharStrings strings(status); + LocalMemory languageTypes; + LocalMemory languageReplacementIndexes; + readLanguageAlias(languageAlias.getAlias(), + &strings, + languageTypes, + languageReplacementIndexes, + languagesLength, + status); + + // Read the scriptAlias into scriptTypes, scriptReplacementIndexes + // and strings + LocalMemory scriptTypes; + LocalMemory scriptReplacementIndexes; + readScriptAlias(scriptAlias.getAlias(), + &strings, + scriptTypes, + scriptReplacementIndexes, + scriptLength, + status); + + // Read the territoryAlias into territoryTypes, territoryReplacementIndexes + // and strings + LocalMemory territoryTypes; + LocalMemory territoryReplacementIndexes; + readTerritoryAlias(territoryAlias.getAlias(), + &strings, + territoryTypes, + territoryReplacementIndexes, + territoryLength, status); + + // Read the variantAlias into variantTypes, variantReplacementIndexes + // and strings + LocalMemory variantTypes; + LocalMemory variantReplacementIndexes; + readVariantAlias(variantAlias.getAlias(), + &strings, + variantTypes, + variantReplacementIndexes, + variantLength, status); + + if (U_FAILURE(status)) { + return nullptr; + } + + // We can only use strings after freeze it. + strings.freeze(); + + // Build the languageMap from languageTypes & languageReplacementIndexes + CharStringMap languageMap(490, status); + for (int32_t i = 0; U_SUCCESS(status) && i < languagesLength; i++) { + languageMap.put(languageTypes[i], + strings.get(languageReplacementIndexes[i]), + status); + } + + // Build the scriptMap from scriptTypes & scriptReplacementIndexes + CharStringMap scriptMap(1, status); + for (int32_t i = 0; U_SUCCESS(status) && i < scriptLength; i++) { + scriptMap.put(scriptTypes[i], + strings.get(scriptReplacementIndexes[i]), + status); + } + + // Build the territoryMap from territoryTypes & territoryReplacementIndexes + CharStringMap territoryMap(650, status); + for (int32_t i = 0; U_SUCCESS(status) && i < territoryLength; i++) { + territoryMap.put(territoryTypes[i], + strings.get(territoryReplacementIndexes[i]), + status); + } + + // Build the variantMap from variantTypes & variantReplacementIndexes. + CharStringMap variantMap(2, status); + for (int32_t i = 0; U_SUCCESS(status) && i < variantLength; i++) { + variantMap.put(variantTypes[i], + strings.get(variantReplacementIndexes[i]), + status); + } + + if (U_FAILURE(status)) { + return nullptr; + } + + // copy hashtables + auto *data = new AliasData( + std::move(languageMap), + std::move(scriptMap), + std::move(territoryMap), + std::move(variantMap), + strings.orphanCharStrings()); + + if (data == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + } + return data; +} + +/** + * A class that find the replacement values of locale fields by using AliasData. + */ +class AliasReplacer { +public: + AliasReplacer(UErrorCode status) : + language(nullptr), script(nullptr), region(nullptr), + extensions(nullptr), variants(status), + data(nullptr) { + } + ~AliasReplacer() { + } + + // Check the fields inside locale, if need to replace fields, + // place the the replaced locale ID in out and return true. + // Otherwise return false for no replacement or error. + bool replace( + const Locale& locale, CharString& out, UErrorCode status); + +private: + const char* language; + const char* script; + const char* region; + const char* extensions; + UVector variants; + + const AliasData* data; + + inline bool notEmpty(const char* str) { + return str && str[0] != NULL_CHAR; + } + + /** + * If replacement is neither null nor empty and input is either null or empty, + * return replacement. + * If replacement is neither null nor empty but input is not empty, return input. + * If replacement is either null or empty and type is either null or empty, + * return input. + * Otherwise return null. + * replacement input type return + * AAA nullptr * AAA + * AAA BBB * BBB + * nullptr || "" CCC nullptr CCC + * nullptr || "" * DDD nullptr + */ + inline const char* deleteOrReplace( + const char* input, const char* type, const char* replacement) { + return notEmpty(replacement) ? + ((input == nullptr) ? replacement : input) : + ((type == nullptr) ? input : nullptr); + } + + inline bool same(const char* a, const char* b) { + if (a == nullptr && b == nullptr) { + return true; + } + if ((a == nullptr && b != nullptr) || + (a != nullptr && b == nullptr)) { + return false; + } + return uprv_strcmp(a, b) == 0; + } + + // Gather fields and generate locale ID into out. + CharString& outputToString(CharString& out, UErrorCode status); + + // Generate the lookup key. + CharString& generateKey(const char* language, const char* region, + const char* variant, CharString& out, + UErrorCode status); + + void parseLanguageReplacement(const char* replacement, + const char*& replaceLanguage, + const char*& replaceScript, + const char*& replaceRegion, + const char*& replaceVariant, + const char*& replaceExtensions, + UVector& toBeFreed, + UErrorCode& status); + + // Replace by using languageAlias. + bool replaceLanguage(bool checkLanguage, bool checkRegion, + bool checkVariants, UVector& toBeFreed, + UErrorCode& status); + + // Replace by using territoryAlias. + bool replaceTerritory(UVector& toBeFreed, UErrorCode& status); + + // Replace by using scriptAlias. + bool replaceScript(UErrorCode& status); + + // Replace by using variantAlias. + bool replaceVariant(UErrorCode& status); +}; + +CharString& +AliasReplacer::generateKey( + const char* language, const char* region, const char* variant, + CharString& out, UErrorCode status) +{ out.append(language, status); - if (script && script[0] != '\0') { - out.append('_', status); - out.append(script, status); - } - if (country && country[0] != '\0') { - out.append('_', status); - out.append(country, status); - } - if (variants && variants[0] != '\0') { - if ((script == nullptr || script[0] == '\0') && - (country == nullptr || country[0] == '\0')) { - out.append('_', status); + if (notEmpty(region)) { + out.append(SEP_CHAR, status) + .append(region, status); + } + if (notEmpty(variant)) { + out.append(SEP_CHAR, status) + .append(variant, status); + } + return out; +} + +void +AliasReplacer::parseLanguageReplacement( + const char* replacement, + const char*& replacedLanguage, + const char*& replacedScript, + const char*& replacedRegion, + const char*& replacedVariant, + const char*& replacedExtensions, + UVector& toBeFreed, + UErrorCode& status) +{ + if (U_FAILURE(status)) { + return; + } + replacedScript = replacedRegion = replacedVariant + = replacedExtensions = nullptr; + if (uprv_strchr(replacement, '_') == nullptr) { + replacedLanguage = replacement; + // reach the end, just return it. + return; + } + // We have multiple field so we have to allocate and parse + CharString* str = new CharString( + replacement, (int32_t)uprv_strlen(replacement), status); + if (U_FAILURE(status)) { + return; + } + if (str == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + toBeFreed.addElement(str, status); + char* data = str->data(); + replacedLanguage = (const char*) data; + char* endOfField = uprv_strchr(data, '_'); + *endOfField = '\0'; // null terminiate it. + endOfField++; + const char* start = endOfField; + endOfField = (char*) uprv_strchr(start, '_'); + size_t len = 0; + if (endOfField == nullptr) { + len = uprv_strlen(start); + } else { + len = endOfField - start; + *endOfField = '\0'; // null terminiate it. + } + if (len == 4 && uprv_isASCIILetter(*start)) { + // Got a script + replacedScript = start; + if (endOfField == nullptr) { + return; + } + start = endOfField++; + endOfField = (char*)uprv_strchr(start, '_'); + if (endOfField == nullptr) { + len = uprv_strlen(start); + } else { + len = endOfField - start; + *endOfField = '\0'; // null terminiate it. + } + } + if (len >= 2 && len <= 3) { + // Got a region + replacedRegion = start; + if (endOfField == nullptr) { + return; + } + start = endOfField++; + endOfField = (char*)uprv_strchr(start, '_'); + if (endOfField == nullptr) { + len = uprv_strlen(start); + } else { + len = endOfField - start; + *endOfField = '\0'; // null terminiate it. + } + } + if (len >= 4) { + // Got a variant + replacedVariant = start; + if (endOfField == nullptr) { + return; } - out.append('_', status); - out.append(variants, status); + start = endOfField++; + } + replacedExtensions = start; +} + +bool +AliasReplacer::replaceLanguage( + bool checkLanguage, bool checkRegion, + bool checkVariants, UVector& toBeFreed, UErrorCode& status) +{ + if (U_FAILURE(status)) { + return false; + } + if ( (checkRegion && region == nullptr) || + (checkVariants && variants.size() == 0)) { + // Nothing to search. + return false; + } + int32_t variant_size = checkVariants ? variants.size() : 1; + // Since we may have more than one variant, we need to loop through them. + const char* searchLanguage = checkLanguage ? language : "und"; + const char* searchRegion = checkRegion ? region : nullptr; + const char* searchVariant = nullptr; + for (int32_t variant_index = 0; + variant_index < variant_size; + variant_index++) { + if (checkVariants) { + U_ASSERT(variant_index < variant_size); + searchVariant = (const char*)(variants.elementAt(variant_index)); + } + + if (searchVariant != nullptr && uprv_strlen(searchVariant) < 4) { + // Do not consider ill-formed variant subtag. + searchVariant = nullptr; + } + CharString typeKey; + generateKey(searchLanguage, searchRegion, searchVariant, typeKey, + status); + if (U_FAILURE(status)) { + return false; + } + const char *replacement = data->languageMap().get(typeKey.data()); + if (replacement == nullptr) { + // Found no replacement data. + continue; + } + + const char* replacedLanguage = nullptr; + const char* replacedScript = nullptr; + const char* replacedRegion = nullptr; + const char* replacedVariant = nullptr; + const char* replacedExtensions = nullptr; + parseLanguageReplacement(replacement, + replacedLanguage, + replacedScript, + replacedRegion, + replacedVariant, + replacedExtensions, + toBeFreed, + status); + replacedLanguage = + (replacedLanguage != nullptr && uprv_strcmp(replacedLanguage, "und") == 0) ? + language : replacedLanguage; + replacedScript = deleteOrReplace(script, nullptr, replacedScript); + replacedRegion = deleteOrReplace(region, searchRegion, replacedRegion); + replacedVariant = deleteOrReplace( + searchVariant, searchVariant, replacedVariant); + + if ( same(language, replacedLanguage) && + same(script, replacedScript) && + same(region, replacedRegion) && + same(searchVariant, replacedVariant) && + replacedExtensions == nullptr) { + // Replacement produce no changes. + continue; + } + + language = replacedLanguage; + region = replacedRegion; + script = replacedScript; + if (searchVariant != nullptr) { + if (notEmpty(replacedVariant)) { + variants.setElementAt((void*)replacedVariant, variant_index); + } else { + variants.removeElementAt(variant_index); + } + } + if (replacedExtensions != nullptr) { + // TODO(ICU-21292) + // DO NOTHING + // UTS35 does not specifiy what should we do if we have extensions in the + // replacement. Currently we know only the following 4 "BCP47 LegacyRules" have + // extensions in them languageAlias: + // i_default => en_x_i_default + // i_enochian => und_x_i_enochian + // i_mingo => see_x_i_mingo + // zh_min => nan_x_zh_min + // But all of them are already changed by code inside ultag_parse() before + // hitting this code. + } + + // Something changed by language alias data. + return true; + } + // Nothing changed by language alias data. + return false; +} + +bool +AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status) +{ + if (U_FAILURE(status)) { + return false; + } + if (region == nullptr) { + // No region to search. + return false; + } + const char *replacement = data->territoryMap().get(region); + if (replacement == nullptr) { + // Found no replacement data for this region. + return false; + } + const char* replacedRegion = replacement; + const char* firstSpace = uprv_strchr(replacement, ' '); + if (firstSpace != nullptr) { + // If there are are more than one region in the replacement. + // We need to check which one match based on the language. + // Cannot use nullptr for language because that will construct + // the default locale, in that case, use "und" to get the correct + // locale. + Locale l(language == nullptr ? "und" : language, nullptr, script); + l.addLikelySubtags(status); + const char* likelyRegion = l.getCountry(); + CharString* item = nullptr; + if (likelyRegion != nullptr && uprv_strlen(likelyRegion) > 0) { + size_t len = uprv_strlen(likelyRegion); + const char* foundInReplacement = uprv_strstr(replacement, + likelyRegion); + if (foundInReplacement != nullptr) { + // Assuming the case there are no three letter region code in + // the replacement of territoryAlias + U_ASSERT(foundInReplacement == replacement || + *(foundInReplacement-1) == ' '); + U_ASSERT(foundInReplacement[len] == ' ' || + foundInReplacement[len] == '\0'); + item = new CharString(foundInReplacement, (int32_t)len, status); + } + } + if (item == nullptr) { + item = new CharString(replacement, + (int32_t)(firstSpace - replacement), status); + } + if (U_FAILURE(status)) { return false; } + if (item == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return false; + } + replacedRegion = item->data(); + toBeFreed.addElement(item, status); + } + U_ASSERT(!same(region, replacedRegion)); + region = replacedRegion; + // The region is changed by data in territory alias. + return true; +} + +bool +AliasReplacer::replaceScript(UErrorCode& status) +{ + if (U_FAILURE(status)) { + return false; + } + if (script == nullptr) { + // No script to search. + return false; } - if (extension && extension[0] != '\0') { - out.append(extension, status); + const char *replacement = data->scriptMap().get(script); + if (replacement == nullptr) { + // Found no replacement data for this script. + return false; + } + U_ASSERT(!same(script, replacement)); + script = replacement; + // The script is changed by data in script alias. + return true; +} + +bool +AliasReplacer::replaceVariant(UErrorCode& status) +{ + if (U_FAILURE(status)) { + return false; + } + // Since we may have more than one variant, we need to loop through them. + for (int32_t i = 0; i < variants.size(); i++) { + const char *variant = (const char*)(variants.elementAt(i)); + const char *replacement = data->variantMap().get(variant); + if (replacement == nullptr) { + // Found no replacement data for this variant. + continue; + } + U_ASSERT((uprv_strlen(replacement) >= 5 && + uprv_strlen(replacement) <= 8) || + (uprv_strlen(replacement) == 4 && + replacement[0] >= '0' && + replacement[0] <= '9')); + if (!same(variant, replacement)) { + variants.setElementAt((void*)replacement, i); + // Special hack to handle hepburn-heploc => alalc97 + if (uprv_strcmp(variant, "heploc") == 0) { + for (int32_t j = 0; j < variants.size(); j++) { + if (uprv_strcmp((const char*)(variants.elementAt(j)), + "hepburn") == 0) { + variants.removeElementAt(j); + } + } + } + return true; + } + } + return false; +} + +CharString& +AliasReplacer::outputToString( + CharString& out, UErrorCode status) +{ + out.append(language, status); + if (notEmpty(script)) { + out.append(SEP_CHAR, status) + .append(script, status); + } + if (notEmpty(region)) { + out.append(SEP_CHAR, status) + .append(region, status); + } + if (variants.size() > 0) { + if (!notEmpty(script) && !notEmpty(region)) { + out.append(SEP_CHAR, status); + } + variants.sort([](UElement e1, UElement e2) -> int8_t { + return uprv_strcmp( + (const char*)e1.pointer, (const char*)e2.pointer); + }, status); + int32_t variantsStart = out.length(); + for (int32_t i = 0; i < variants.size(); i++) { + out.append(SEP_CHAR, status) + .append((const char*)((UVector*)variants.elementAt(i)), + status); + } + T_CString_toUpperCase(out.data() + variantsStart); + } + if (notEmpty(extensions)) { + CharString tmp("und_", status); + tmp.append(extensions, status); + Locale tmpLocale(tmp.data()); + // only support x extension inside CLDR for now. + U_ASSERT(extensions[0] == 'x'); + out.append(tmpLocale.getName() + 1, status); } return out; } +bool +AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode status) +{ + data = AliasData::singleton(status); + if (U_FAILURE(status)) { + return false; + } + U_ASSERT(data != nullptr); + out.clear(); + language = locale.getLanguage(); + if (!notEmpty(language)) { + language = nullptr; + } + script = locale.getScript(); + if (!notEmpty(script)) { + script = nullptr; + } + region = locale.getCountry(); + if (!notEmpty(region)) { + region = nullptr; + } + const char* variantsStr = locale.getVariant(); + const char* extensionsStr = locale_getKeywordsStart(locale.getName()); + CharString variantsBuff(variantsStr, -1, status); + if (!variantsBuff.isEmpty()) { + if (U_FAILURE(status)) { return false; } + char* start = variantsBuff.data(); + T_CString_toLowerCase(start); + char* end; + while ((end = uprv_strchr(start, SEP_CHAR)) != nullptr && + U_SUCCESS(status)) { + *end = NULL_CHAR; // null terminate inside variantsBuff + variants.addElement(start, status); + start = end + 1; + } + variants.addElement(start, status); + } + if (U_FAILURE(status)) { return false; } + + // Sort the variants + variants.sort([](UElement e1, UElement e2) -> int8_t { + return uprv_strcmp( + (const char*)e1.pointer, (const char*)e2.pointer); + }, status); + + // A changed count to assert when loop too many times. + int changed = 0; + // A UVector to to hold CharString allocated by the replace* method + // and freed when out of scope from his function. + UVector stringsToBeFreed([](void *obj){ delete ((CharString*) obj); }, + nullptr, 10, status); + while (U_SUCCESS(status)) { + // Something wrong with the data cause looping here more than 10 times + // already. + U_ASSERT(changed < 5); + // From observation of key in data/misc/metadata.txt + // we know currently we only need to search in the following combination + // of fields for type in languageAlias: + // * lang_region_variant + // * lang_region + // * lang_variant + // * lang + // * und_variant + // This assumption is ensured by the U_ASSERT in readLanguageAlias + // + // lang REGION variant + if ( replaceLanguage(true, true, true, stringsToBeFreed, status) || + replaceLanguage(true, true, false, stringsToBeFreed, status) || + replaceLanguage(true, false, true, stringsToBeFreed, status) || + replaceLanguage(true, false, false, stringsToBeFreed, status) || + replaceLanguage(false,false, true, stringsToBeFreed, status) || + replaceTerritory(stringsToBeFreed, status) || + replaceScript(status) || + replaceVariant(status)) { + // Some values in data is changed, try to match from the beginning + // again. + changed++; + continue; + } + // Nothing changed. Break out. + break; + } // while(1) + + if (U_FAILURE(status)) { return false; } + // Nothing changed and we know the order of the vaiants are not change + // because we have no variant or only one. + if (changed == 0 && variants.size() <= 1) { + return false; + } + outputToString(out, status); + if (extensionsStr != nullptr) { + out.append(extensionsStr, status); + } + if (U_FAILURE(status)) { + return false; + } + // If the tag is not changed, return. + if (uprv_strcmp(out.data(), locale.getName()) == 0) { + U_ASSERT(changed == 0); + U_ASSERT(variants.size() > 1); + out.clear(); + return false; + } + return true; +} + +// Return true if the locale is changed during canonicalization. +// The replaced value then will be put into out. +bool +canonicalizeLocale(const Locale& locale, CharString& out, UErrorCode& status) +{ + AliasReplacer replacer(status); + return replacer.replace(locale, out, status); +} + +// Function to optimize for known cases without so we can skip the loading +// of resources in the startup time until we really need it. +bool +isKnownCanonicalizedLocale(const char* locale, UErrorCode& status) +{ + if ( uprv_strcmp(locale, "c") == 0 || + uprv_strcmp(locale, "en") == 0 || + uprv_strcmp(locale, "en_US") == 0) { + return true; + } + + // common well-known Canonicalized. + umtx_initOnce(gKnownCanonicalizedInitOnce, + &loadKnownCanonicalized, status); + if (U_FAILURE(status)) { + return false; + } + U_ASSERT(gKnownCanonicalized != nullptr); + return uhash_geti(gKnownCanonicalized, locale) != 0; +} + } // namespace +// Function for testing. +U_CAPI const char* const* +ulocimp_getKnownCanonicalizedLocaleForTest(int32_t* length) +{ + *length = UPRV_LENGTHOF(KNOWN_CANONICALIZED); + return KNOWN_CANONICALIZED; +} + +// Function for testing. +U_CAPI bool +ulocimp_isCanonicalizedLocaleForTest(const char* localeName) +{ + Locale l(localeName); + UErrorCode status = U_ZERO_ERROR; + CharString temp; + return !canonicalizeLocale(l, temp, status) && U_SUCCESS(status); +} + /*This function initializes a Locale from a C locale ID*/ Locale& Locale::init(const char* localeID, UBool canonicalize) { @@ -632,9 +1719,9 @@ Locale& Locale::init(const char* localeID, UBool canonicalize) uprv_memcpy(language, fullName, fieldLen[0]); language[fieldLen[0]] = 0; } - if (fieldLen[1] == 4 && ISASCIIALPHA(field[1][0]) && - ISASCIIALPHA(field[1][1]) && ISASCIIALPHA(field[1][2]) && - ISASCIIALPHA(field[1][3])) { + if (fieldLen[1] == 4 && uprv_isASCIILetter(field[1][0]) && + uprv_isASCIILetter(field[1][1]) && uprv_isASCIILetter(field[1][2]) && + uprv_isASCIILetter(field[1][3])) { /* We have at least a script */ uprv_memcpy(script, field[1], fieldLen[1]); script[fieldLen[1]] = 0; @@ -662,192 +1749,18 @@ Locale& Locale::init(const char* localeID, UBool canonicalize) } if (canonicalize) { - UErrorCode status = U_ZERO_ERROR; - // TODO: Try to use ResourceDataValue and ures_getValueWithFallback() etc. - LocalUResourceBundlePointer metadata(ures_openDirect(NULL, "metadata", &status)); - LocalUResourceBundlePointer metadataAlias(ures_getByKey(metadata.getAlias(), "alias", NULL, &status)); - // Look up the metadata:alias:language:$key:replacement entries - // key could be one of the following: - // language - // language_Script_REGION - // language_REGION - // language_variant - do { - // The resource structure looks like - // metadata { - // alias { - // language { - // art_lojban { - // replacement{"jbo"} - // } - // ... - // ks_Arab_IN { - // replacement{"ks_IN"} - // } - // ... - // no { - // replacement{"nb"} - // } - // .... - // zh_CN { - // replacement{"zh_Hans_CN"} - // } - // } - // ... - // } - // } - LocalUResourceBundlePointer languageAlias(ures_getByKey(metadataAlias.getAlias(), "language", NULL, &status)); - if (U_FAILURE(status)) + if (!isKnownCanonicalizedLocale(fullName, err)) { + CharString replaced; + // Not sure it is already canonicalized + if (canonicalizeLocale(*this, replaced, err)) { + U_ASSERT(U_SUCCESS(err)); + // If need replacement, call init again. + init(replaced.data(), false); + } + if (U_FAILURE(err)) { break; - CharString temp; - // Handle cases of key pattern "language _ variant" - // ex: Map "art_lojban" to "jbo" - const char* variants = getVariant(); - if (variants != nullptr && variants[0] != '\0') { - const char* begin = variants; - const char* end = begin; - // We may have multiple variants, need to look at each of - // them. - do { - status = U_ZERO_ERROR; - end = uprv_strchr(begin, '_'); - int32_t len = (end == nullptr) ? int32_t(uprv_strlen(begin)) : int32_t(end - begin); - temp.clear().append(getLanguage(), status).append("_", status).append(begin, len, status); - LocalUResourceBundlePointer languageVariantAlias( - ures_getByKey(languageAlias.getAlias(), - temp.data(), - NULL, &status)); - temp.clear().appendInvariantChars( - UnicodeString(ures_getStringByKey(languageVariantAlias.getAlias(), "replacement", nullptr, &status)), status); - if (U_SUCCESS(status)) { - CharString newVar; - if (begin != variants) { - newVar.append(variants, static_cast(begin - variants - 1), status); - } - if (end != nullptr) { - if (begin != variants) { - newVar.append("_", status); - } - newVar.append(end + 1, status); - } - Locale l(temp.data()); - init(AppendLSCVE(temp.clear(), - l.getLanguage(), - (getScript() != nullptr && getScript()[0] != '\0') ? getScript() : l.getScript(), - (getCountry() != nullptr && getCountry()[0] != '\0') ? getCountry() : l.getCountry(), - newVar.data(), - uprv_strchr(fullName, '@'), status).data(), false); - break; - } - begin = end + 1; - } while (end != nullptr); - } // End of handle language _ variant - // Handle cases of key pattern "language _ Script _ REGION" - // ex: Map "ks_Arab_IN" to "ks_IN" - if (getScript() != nullptr && getScript()[0] != '\0' && - getCountry() != nullptr && getCountry()[0] != '\0') { - status = U_ZERO_ERROR; - LocalUResourceBundlePointer replacedAlias( - ures_getByKey(languageAlias.getAlias(), - AppendLSCVE(temp.clear(), getLanguage(), getScript(), getCountry(), - nullptr, nullptr, status).data(), NULL, &status)); - temp.clear().appendInvariantChars( - UnicodeString(ures_getStringByKey(replacedAlias.getAlias(), "replacement", nullptr, &status)), status); - if (U_SUCCESS(status)) { - Locale l(temp.data()); - init(AppendLSCVE(temp.clear(), - l.getLanguage(), - l.getScript(), - l.getCountry(), - getVariant(), - uprv_strchr(fullName, '@'), status).data(), false); - } - } // End of handle language _ Script _ REGION - // Handle cases of key pattern "language _ REGION" - // ex: Map "zh_CN" to "zh_Hans_CN" - if (getCountry() != nullptr && getCountry()[0] != '\0') { - status = U_ZERO_ERROR; - LocalUResourceBundlePointer replacedAlias( - ures_getByKey(languageAlias.getAlias(), - AppendLSCVE(temp.clear(), getLanguage(), nullptr, getCountry(), - nullptr, nullptr, status).data(), NULL, &status)); - temp.clear().appendInvariantChars( - UnicodeString(ures_getStringByKey(replacedAlias.getAlias(), "replacement", nullptr, &status)), status); - if (U_SUCCESS(status)) { - Locale l(temp.data()); - init(AppendLSCVE(temp.clear(), - l.getLanguage(), - (getScript() != nullptr && getScript()[0] != '\0') ? getScript() : l.getScript(), - l.getCountry(), - getVariant(), - uprv_strchr(fullName, '@'), status).data(), false); - } - } // End of handle "language _ REGION" - // Handle cases of key pattern "language" - // ex: Map "no" to "nb" - { - status = U_ZERO_ERROR; - LocalUResourceBundlePointer replaceLanguageAlias(ures_getByKey(languageAlias.getAlias(), getLanguage(), NULL, &status)); - temp.clear().appendInvariantChars( - UnicodeString(ures_getStringByKey(replaceLanguageAlias.getAlias(), "replacement", nullptr, &status)), status); - if (U_SUCCESS(status)) { - Locale l(temp.data()); - init(AppendLSCVE(temp.clear(), - l.getLanguage(), - (getScript() != nullptr && getScript()[0] != '\0') ? getScript() : l.getScript(), - (getCountry() != nullptr && getCountry()[0] != '\0') ? getCountry() : l.getCountry(), - getVariant(), - uprv_strchr(fullName, '@'), status).data(), false); - } - } // End of handle "language" - - // Look up the metadata:alias:territory:$key:replacement entries - // key is region code. - if (getCountry() != nullptr) { - status = U_ZERO_ERROR; - // The resource structure looks like - // metadata { - // alias { - // ... - // territory: { - // 172 { - // replacement{"RU AM AZ BY GE KG KZ MD TJ TM UA UZ"} - // } - // ... - // 554 { - // replacement{"NZ"} - // } - // } - // } - // } - LocalUResourceBundlePointer territoryAlias(ures_getByKey(metadataAlias.getAlias(), "territory", NULL, &status)); - LocalUResourceBundlePointer countryAlias(ures_getByKey(territoryAlias.getAlias(), getCountry(), NULL, &status)); - UnicodeString replacements( - ures_getStringByKey(countryAlias.getAlias(), "replacement", nullptr, &status)); - if (U_SUCCESS(status)) { - CharString replacedCountry; - int32_t delPos = replacements.indexOf(' '); - if (delPos == -1) { - replacedCountry.appendInvariantChars(replacements, status); - } else { - Locale l(AppendLSCVE(temp.clear(), getLanguage(), nullptr, getScript(), - nullptr, nullptr, status).data()); - l.addLikelySubtags(status); - if (replacements.indexOf(UnicodeString(l.getCountry())) != -1) { - replacedCountry.append(l.getCountry(), status); - } else { - replacedCountry.appendInvariantChars(replacements.getBuffer(), delPos, status); - } - } - init(AppendLSCVE(temp.clear(), - getLanguage(), - getScript(), - replacedCountry.data(), - getVariant(), - uprv_strchr(fullName, '@'), status).data(), false); - } - } // End of handle REGION - } while (0); + } + } } // if (canonicalize) { // successful end of init() @@ -1024,13 +1937,14 @@ Locale::forLanguageTag(StringPiece tag, UErrorCode& status) return result; } - // If a BCP-47 language tag is passed as the language parameter to the + // If a BCP 47 language tag is passed as the language parameter to the // normal Locale constructor, it will actually fall back to invoking // uloc_forLanguageTag() to parse it if it somehow is able to detect that - // the string actually is BCP-47. This works well for things like strings - // using BCP-47 extensions, but it does not at all work for things like - // BCP-47 grandfathered tags (eg. "en-GB-oed") which are possible to also - // interpret as ICU locale IDs and because of that won't trigger the BCP-47 + // the string actually is BCP 47. This works well for things like strings + // using BCP 47 extensions, but it does not at all work for things like + // legacy language tags (marked as “Type: grandfathered” in BCP 47, + // e.g., "en-GB-oed") which are possible to also + // interpret as ICU locale IDs and because of that won't trigger the BCP 47 // parsing. Therefore the code here explicitly calls uloc_forLanguageTag() // and then Locale::init(), instead of just calling the normal constructor. @@ -1414,8 +2328,6 @@ UnicodeKeywordEnumeration::~UnicodeKeywordEnumeration() = default; StringEnumeration * Locale::createKeywords(UErrorCode &status) const { - char keywords[256]; - int32_t keywordCapacity = sizeof keywords; StringEnumeration *result = NULL; if (U_FAILURE(status)) { @@ -1426,9 +2338,11 @@ Locale::createKeywords(UErrorCode &status) const const char* assignment = uprv_strchr(fullName, '='); if(variantStart) { if(assignment > variantStart) { - int32_t keyLen = locale_getKeywords(variantStart+1, '@', keywords, keywordCapacity, FALSE, &status); - if(U_SUCCESS(status) && keyLen) { - result = new KeywordEnumeration(keywords, keyLen, 0, status); + CharString keywords; + CharStringByteSink sink(&keywords); + ulocimp_getKeywords(variantStart+1, '@', sink, FALSE, &status); + if (U_SUCCESS(status) && !keywords.isEmpty()) { + result = new KeywordEnumeration(keywords.data(), keywords.length(), 0, status); if (!result) { status = U_MEMORY_ALLOCATION_ERROR; } @@ -1443,8 +2357,6 @@ Locale::createKeywords(UErrorCode &status) const StringEnumeration * Locale::createUnicodeKeywords(UErrorCode &status) const { - char keywords[256]; - int32_t keywordCapacity = sizeof keywords; StringEnumeration *result = NULL; if (U_FAILURE(status)) { @@ -1455,9 +2367,11 @@ Locale::createUnicodeKeywords(UErrorCode &status) const const char* assignment = uprv_strchr(fullName, '='); if(variantStart) { if(assignment > variantStart) { - int32_t keyLen = locale_getKeywords(variantStart+1, '@', keywords, keywordCapacity, FALSE, &status); - if(U_SUCCESS(status) && keyLen) { - result = new UnicodeKeywordEnumeration(keywords, keyLen, 0, status); + CharString keywords; + CharStringByteSink sink(&keywords); + ulocimp_getKeywords(variantStart+1, '@', sink, FALSE, &status); + if (U_SUCCESS(status) && !keywords.isEmpty()) { + result = new UnicodeKeywordEnumeration(keywords.data(), keywords.length(), 0, status); if (!result) { status = U_MEMORY_ALLOCATION_ERROR; } @@ -1492,48 +2406,7 @@ Locale::getKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& sta return; } - LocalMemory scratch; - int32_t scratch_capacity = 16; // Arbitrarily chosen default size. - - char* buffer; - int32_t result_capacity, reslen; - - for (;;) { - if (scratch.allocateInsteadAndReset(scratch_capacity) == nullptr) { - status = U_MEMORY_ALLOCATION_ERROR; - return; - } - - buffer = sink.GetAppendBuffer( - /*min_capacity=*/scratch_capacity, - /*desired_capacity_hint=*/scratch_capacity, - scratch.getAlias(), - scratch_capacity, - &result_capacity); - - reslen = uloc_getKeywordValue( - fullName, - keywordName_nul.data(), - buffer, - result_capacity, - &status); - - if (status != U_BUFFER_OVERFLOW_ERROR) { - break; - } - - scratch_capacity = reslen; - status = U_ZERO_ERROR; - } - - if (U_FAILURE(status)) { - return; - } - - sink.Append(buffer, reslen); - if (status == U_STRING_NOT_TERMINATED_WARNING) { - status = U_ZERO_ERROR; // Terminators not used. - } + ulocimp_getKeywordValue(fullName, keywordName_nul.data(), sink, &status); } void diff --git a/deps/icu-small/source/common/loclikely.cpp b/deps/icu-small/source/common/loclikely.cpp index 3b71708e549d5f..6a34bb42cecf3f 100644 --- a/deps/icu-small/source/common/loclikely.cpp +++ b/deps/icu-small/source/common/loclikely.cpp @@ -464,8 +464,7 @@ parseTagString( goto error; } - subtagLength = ulocimp_getLanguage(position, lang, *langLength, &position); - u_terminateChars(lang, *langLength, subtagLength, err); + subtagLength = ulocimp_getLanguage(position, &position, *err).extract(lang, *langLength, *err); /* * Note that we explicit consider U_STRING_NOT_TERMINATED_WARNING @@ -486,8 +485,7 @@ parseTagString( ++position; } - subtagLength = ulocimp_getScript(position, script, *scriptLength, &position); - u_terminateChars(script, *scriptLength, subtagLength, err); + subtagLength = ulocimp_getScript(position, &position, *err).extract(script, *scriptLength, *err); if(U_FAILURE(*err)) { goto error; @@ -511,8 +509,7 @@ parseTagString( } } - subtagLength = ulocimp_getCountry(position, region, *regionLength, &position); - u_terminateChars(region, *regionLength, subtagLength, err); + subtagLength = ulocimp_getCountry(position, &position, *err).extract(region, *regionLength, *err); if(U_FAILURE(*err)) { goto error; @@ -826,7 +823,7 @@ createLikelySubtagsString( } \ } UPRV_BLOCK_MACRO_END -static void +static UBool _uloc_addLikelySubtags(const char* localeID, icu::ByteSink& sink, UErrorCode* err) { @@ -897,15 +894,22 @@ _uloc_addLikelySubtags(const char* localeID, sink.Append(localeID, localIDLength); } - return; + return success; error: if (!U_FAILURE(*err)) { *err = U_ILLEGAL_ARGUMENT_ERROR; } + return FALSE; } +// Add likely subtags to the sink +// return true if the value in the sink is produced by a match during the lookup +// return false if the value in the sink is the same as input because there are +// no match after the lookup. +static UBool _ulocimp_addLikelySubtags(const char*, icu::ByteSink&, UErrorCode*); + static void _uloc_minimizeSubtags(const char* localeID, icu::ByteSink& sink, @@ -921,6 +925,7 @@ _uloc_minimizeSubtags(const char* localeID, const char* trailing = ""; int32_t trailingLength = 0; int32_t trailingIndex = 0; + UBool successGetMax = FALSE; if(U_FAILURE(*err)) { goto error; @@ -961,7 +966,7 @@ _uloc_minimizeSubtags(const char* localeID, { icu::CharString base; { - icu::CharStringByteSink sink(&base); + icu::CharStringByteSink baseSink(&base); createTagString( lang, langLength, @@ -971,7 +976,7 @@ _uloc_minimizeSubtags(const char* localeID, regionLength, NULL, 0, - sink, + baseSink, err); } @@ -980,8 +985,8 @@ _uloc_minimizeSubtags(const char* localeID, * from AddLikelySubtags. **/ { - icu::CharStringByteSink sink(&maximizedTagBuffer); - ulocimp_addLikelySubtags(base.data(), sink, err); + icu::CharStringByteSink maxSink(&maximizedTagBuffer); + successGetMax = _ulocimp_addLikelySubtags(base.data(), maxSink, err); } } @@ -989,13 +994,40 @@ _uloc_minimizeSubtags(const char* localeID, goto error; } + if (!successGetMax) { + /** + * If we got here, return the locale ID parameter unchanged. + **/ + const int32_t localeIDLength = (int32_t)uprv_strlen(localeID); + sink.Append(localeID, localeIDLength); + return; + } + + // In the following, the lang, script, region are referring to those in + // the maximizedTagBuffer, not the one in the localeID. + langLength = sizeof(lang); + scriptLength = sizeof(script); + regionLength = sizeof(region); + parseTagString( + maximizedTagBuffer.data(), + lang, + &langLength, + script, + &scriptLength, + region, + ®ionLength, + err); + if(U_FAILURE(*err)) { + goto error; + } + /** * Start first with just the language. **/ { icu::CharString tagBuffer; { - icu::CharStringByteSink sink(&tagBuffer); + icu::CharStringByteSink tagSink(&tagBuffer); createLikelySubtagsString( lang, langLength, @@ -1005,14 +1037,15 @@ _uloc_minimizeSubtags(const char* localeID, 0, NULL, 0, - sink, + tagSink, err); } if(U_FAILURE(*err)) { goto error; } - else if (!tagBuffer.isEmpty() && uprv_strnicmp( + else if (!tagBuffer.isEmpty() && + uprv_strnicmp( maximizedTagBuffer.data(), tagBuffer.data(), tagBuffer.length()) == 0) { @@ -1039,7 +1072,7 @@ _uloc_minimizeSubtags(const char* localeID, icu::CharString tagBuffer; { - icu::CharStringByteSink sink(&tagBuffer); + icu::CharStringByteSink tagSink(&tagBuffer); createLikelySubtagsString( lang, langLength, @@ -1049,14 +1082,15 @@ _uloc_minimizeSubtags(const char* localeID, regionLength, NULL, 0, - sink, + tagSink, err); } if(U_FAILURE(*err)) { goto error; } - else if (uprv_strnicmp( + else if (!tagBuffer.isEmpty() && + uprv_strnicmp( maximizedTagBuffer.data(), tagBuffer.data(), tagBuffer.length()) == 0) { @@ -1081,10 +1115,10 @@ _uloc_minimizeSubtags(const char* localeID, * since trying with all three subtags would only yield the * maximal version that we already have. **/ - if (scriptLength > 0 && regionLength > 0) { + if (scriptLength > 0) { icu::CharString tagBuffer; { - icu::CharStringByteSink sink(&tagBuffer); + icu::CharStringByteSink tagSink(&tagBuffer); createLikelySubtagsString( lang, langLength, @@ -1094,14 +1128,15 @@ _uloc_minimizeSubtags(const char* localeID, 0, NULL, 0, - sink, + tagSink, err); } if(U_FAILURE(*err)) { goto error; } - else if (uprv_strnicmp( + else if (!tagBuffer.isEmpty() && + uprv_strnicmp( maximizedTagBuffer.data(), tagBuffer.data(), tagBuffer.length()) == 0) { @@ -1123,10 +1158,19 @@ _uloc_minimizeSubtags(const char* localeID, { /** - * If we got here, return the locale ID parameter. + * If we got here, return the max + trail. **/ - const int32_t localeIDLength = (int32_t)uprv_strlen(localeID); - sink.Append(localeID, localeIDLength); + createTagString( + lang, + langLength, + script, + scriptLength, + region, + regionLength, + trailing, + trailingLength, + sink, + err); return; } @@ -1193,15 +1237,23 @@ uloc_addLikelySubtags(const char* localeID, return reslen; } -U_CAPI void U_EXPORT2 -ulocimp_addLikelySubtags(const char* localeID, - icu::ByteSink& sink, - UErrorCode* status) { +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)) { - _uloc_addLikelySubtags(localeBuffer, sink, status); + return _uloc_addLikelySubtags(localeBuffer, sink, status); } + return FALSE; +} + +U_CAPI void U_EXPORT2 +ulocimp_addLikelySubtags(const char* localeID, + icu::ByteSink& sink, + UErrorCode* status) { + _ulocimp_addLikelySubtags(localeID, sink, status); } U_CAPI int32_t U_EXPORT2 diff --git a/deps/icu-small/source/common/loclikelysubtags.cpp b/deps/icu-small/source/common/loclikelysubtags.cpp index 1fbf1a1463299f..a031bfa5872642 100644 --- a/deps/icu-small/source/common/loclikelysubtags.cpp +++ b/deps/icu-small/source/common/loclikelysubtags.cpp @@ -1,5 +1,5 @@ // © 2019 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html // loclikelysubtags.cpp // created: 2019may08 Markus W. Scherer @@ -20,6 +20,7 @@ #include "uhash.h" #include "uinvchar.h" #include "umutex.h" +#include "uniquecharstr.h" #include "uresdata.h" #include "uresimp.h" @@ -31,71 +32,6 @@ constexpr char PSEUDO_ACCENTS_PREFIX = '\''; // -XA, -PSACCENT constexpr char PSEUDO_BIDI_PREFIX = '+'; // -XB, -PSBIDI constexpr char PSEUDO_CRACKED_PREFIX = ','; // -XC, -PSCRACK -/** - * Stores NUL-terminated strings with duplicate elimination. - * Checks for unique UTF-16 string pointers and converts to invariant characters. - */ -class UniqueCharStrings { -public: - UniqueCharStrings(UErrorCode &errorCode) : strings(nullptr) { - uhash_init(&map, uhash_hashUChars, uhash_compareUChars, uhash_compareLong, &errorCode); - if (U_FAILURE(errorCode)) { return; } - strings = new CharString(); - if (strings == nullptr) { - errorCode = U_MEMORY_ALLOCATION_ERROR; - } - } - ~UniqueCharStrings() { - uhash_close(&map); - delete strings; - } - - /** Returns/orphans the CharString that contains all strings. */ - CharString *orphanCharStrings() { - CharString *result = strings; - strings = nullptr; - return result; - } - - /** Adds a string and returns a unique number for it. */ - int32_t add(const UnicodeString &s, UErrorCode &errorCode) { - if (U_FAILURE(errorCode)) { return 0; } - if (isFrozen) { - errorCode = U_NO_WRITE_PERMISSION; - return 0; - } - // The string points into the resource bundle. - const char16_t *p = s.getBuffer(); - int32_t oldIndex = uhash_geti(&map, p); - if (oldIndex != 0) { // found duplicate - return oldIndex; - } - // Explicit NUL terminator for the previous string. - // The strings object is also terminated with one implicit NUL. - strings->append(0, errorCode); - int32_t newIndex = strings->length(); - strings->appendInvariantChars(s, errorCode); - uhash_puti(&map, const_cast(p), newIndex, &errorCode); - return newIndex; - } - - void freeze() { isFrozen = true; } - - /** - * Returns a string pointer for its unique number, if this object is frozen. - * Otherwise nullptr. - */ - const char *get(int32_t i) const { - U_ASSERT(isFrozen); - return isFrozen && i > 0 ? strings->data() + i : nullptr; - } - -private: - UHashtable map; - CharString *strings; - bool isFrozen = false; -}; - } // namespace LocaleDistanceData::LocaleDistanceData(LocaleDistanceData &&data) : diff --git a/deps/icu-small/source/common/loclikelysubtags.h b/deps/icu-small/source/common/loclikelysubtags.h index 90ddfffaca672d..14a01a5eac7eba 100644 --- a/deps/icu-small/source/common/loclikelysubtags.h +++ b/deps/icu-small/source/common/loclikelysubtags.h @@ -1,5 +1,5 @@ // © 2019 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html // loclikelysubtags.h // created: 2019may08 Markus W. Scherer @@ -13,49 +13,13 @@ #include "unicode/locid.h" #include "unicode/uobject.h" #include "unicode/ures.h" +#include "charstrmap.h" #include "lsr.h" -#include "uhash.h" U_NAMESPACE_BEGIN struct XLikelySubtagsData; -/** - * Map of const char * keys & values. - * Stores pointers as is: Does not own/copy/adopt/release strings. - */ -class CharStringMap final : public UMemory { -public: - /** Constructs an unusable non-map. */ - CharStringMap() : map(nullptr) {} - CharStringMap(int32_t size, UErrorCode &errorCode) { - map = uhash_openSize(uhash_hashChars, uhash_compareChars, uhash_compareChars, - size, &errorCode); - } - CharStringMap(CharStringMap &&other) U_NOEXCEPT : map(other.map) { - other.map = nullptr; - } - CharStringMap(const CharStringMap &other) = delete; - ~CharStringMap() { - uhash_close(map); - } - - CharStringMap &operator=(CharStringMap &&other) U_NOEXCEPT { - map = other.map; - other.map = nullptr; - return *this; - } - CharStringMap &operator=(const CharStringMap &other) = delete; - - const char *get(const char *key) const { return static_cast(uhash_get(map, key)); } - void put(const char *key, const char *value, UErrorCode &errorCode) { - uhash_put(map, const_cast(key), const_cast(value), &errorCode); - } - -private: - UHashtable *map; -}; - struct LocaleDistanceData { LocaleDistanceData() = default; LocaleDistanceData(LocaleDistanceData &&data); diff --git a/deps/icu-small/source/common/locmap.cpp b/deps/icu-small/source/common/locmap.cpp index 46986399b23e7a..515205222a65ac 100644 --- a/deps/icu-small/source/common/locmap.cpp +++ b/deps/icu-small/source/common/locmap.cpp @@ -28,8 +28,11 @@ */ #include "locmap.h" +#include "bytesinkutil.h" +#include "charstr.h" #include "cstring.h" #include "cmemory.h" +#include "ulocimp.h" #include "unicode/uloc.h" #if U_PLATFORM_HAS_WIN32_API && UCONFIG_USE_WINDOWS_LCID_MAPPING_API @@ -1167,15 +1170,18 @@ uprv_convertToLCIDPlatform(const char* localeID, UErrorCode* status) // conversion functionality when available. #if U_PLATFORM_HAS_WIN32_API && UCONFIG_USE_WINDOWS_LCID_MAPPING_API int32_t len; - char collVal[ULOC_KEYWORDS_CAPACITY] = {}; char baseName[ULOC_FULLNAME_CAPACITY] = {}; const char * mylocaleID = localeID; // Check any for keywords. if (uprv_strchr(localeID, '@')) { - len = uloc_getKeywordValue(localeID, "collation", collVal, UPRV_LENGTHOF(collVal) - 1, status); - if (U_SUCCESS(*status) && len > 0) + icu::CharString collVal; + { + icu::CharStringByteSink sink(&collVal); + ulocimp_getKeywordValue(localeID, "collation", sink, status); + } + if (U_SUCCESS(*status) && !collVal.isEmpty()) { // If it contains the keyword collation, return 0 so that the LCID lookup table will be used. return 0; diff --git a/deps/icu-small/source/common/lsr.cpp b/deps/icu-small/source/common/lsr.cpp index d4308ad0275428..b81808f2c4aae1 100644 --- a/deps/icu-small/source/common/lsr.cpp +++ b/deps/icu-small/source/common/lsr.cpp @@ -1,5 +1,5 @@ // © 2019 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html // lsr.cpp // created: 2019may08 Markus W. Scherer diff --git a/deps/icu-small/source/common/lsr.h b/deps/icu-small/source/common/lsr.h index d535e5b0376cd3..a33f855245335e 100644 --- a/deps/icu-small/source/common/lsr.h +++ b/deps/icu-small/source/common/lsr.h @@ -1,5 +1,5 @@ // © 2019 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html // lsr.h // created: 2019may08 Markus W. Scherer diff --git a/deps/icu-small/source/common/messageimpl.h b/deps/icu-small/source/common/messageimpl.h index dc7a6edd6c0e5f..a56479066bc058 100644 --- a/deps/icu-small/source/common/messageimpl.h +++ b/deps/icu-small/source/common/messageimpl.h @@ -33,7 +33,7 @@ U_NAMESPACE_BEGIN class U_COMMON_API MessageImpl { public: /** - * @return TRUE if getApostropheMode()==UMSGPAT_APOS_DOUBLE_REQUIRED + * @return true if getApostropheMode()==UMSGPAT_APOS_DOUBLE_REQUIRED */ static UBool jdkAposMode(const MessagePattern &msgPattern) { return msgPattern.getApostropheMode()==UMSGPAT_APOS_DOUBLE_REQUIRED; diff --git a/deps/icu-small/source/common/norm2allmodes.h b/deps/icu-small/source/common/norm2allmodes.h index 682ece28f13092..e8bd52c6ae39d7 100644 --- a/deps/icu-small/source/common/norm2allmodes.h +++ b/deps/icu-small/source/common/norm2allmodes.h @@ -65,13 +65,13 @@ class Normalizer2WithImpl : public Normalizer2 { normalizeSecondAndAppend(UnicodeString &first, const UnicodeString &second, UErrorCode &errorCode) const { - return normalizeSecondAndAppend(first, second, TRUE, errorCode); + return normalizeSecondAndAppend(first, second, true, errorCode); } virtual UnicodeString & append(UnicodeString &first, const UnicodeString &second, UErrorCode &errorCode) const { - return normalizeSecondAndAppend(first, second, FALSE, errorCode); + return normalizeSecondAndAppend(first, second, false, errorCode); } UnicodeString & normalizeSecondAndAppend(UnicodeString &first, @@ -112,14 +112,14 @@ class Normalizer2WithImpl : public Normalizer2 { int32_t length; const UChar *d=impl.getDecomposition(c, buffer, length); if(d==NULL) { - return FALSE; + return false; } if(d==buffer) { decomposition.setTo(buffer, length); // copy the string (Jamos from Hangul syllable c) } else { - decomposition.setTo(FALSE, d, length); // read-only alias + decomposition.setTo(false, d, length); // read-only alias } - return TRUE; + return true; } virtual UBool getRawDecomposition(UChar32 c, UnicodeString &decomposition) const { @@ -127,14 +127,14 @@ class Normalizer2WithImpl : public Normalizer2 { int32_t length; const UChar *d=impl.getRawDecomposition(c, buffer, length); if(d==NULL) { - return FALSE; + return false; } if(d==buffer) { decomposition.setTo(buffer, length); // copy the string (algorithmic decomposition) } else { - decomposition.setTo(FALSE, d, length); // read-only alias + decomposition.setTo(false, d, length); // read-only alias } - return TRUE; + return true; } virtual UChar32 composePair(UChar32 a, UChar32 b) const { @@ -150,12 +150,12 @@ class Normalizer2WithImpl : public Normalizer2 { virtual UBool isNormalized(const UnicodeString &s, UErrorCode &errorCode) const { if(U_FAILURE(errorCode)) { - return FALSE; + return false; } const UChar *sArray=s.getBuffer(); if(sArray==NULL) { errorCode=U_ILLEGAL_ARGUMENT_ERROR; - return FALSE; + return false; } const UChar *sLimit=sArray+s.length(); return sLimit==spanQuickCheckYes(sArray, sLimit, errorCode); @@ -227,7 +227,7 @@ class ComposeNormalizer2 : public Normalizer2WithImpl { virtual void normalize(const UChar *src, const UChar *limit, ReorderingBuffer &buffer, UErrorCode &errorCode) const U_OVERRIDE { - impl.compose(src, limit, onlyContiguous, TRUE, buffer, errorCode); + impl.compose(src, limit, onlyContiguous, true, buffer, errorCode); } using Normalizer2WithImpl::normalize; // Avoid warning about hiding base class function. @@ -256,24 +256,24 @@ class ComposeNormalizer2 : public Normalizer2WithImpl { virtual UBool isNormalized(const UnicodeString &s, UErrorCode &errorCode) const U_OVERRIDE { if(U_FAILURE(errorCode)) { - return FALSE; + return false; } const UChar *sArray=s.getBuffer(); if(sArray==NULL) { errorCode=U_ILLEGAL_ARGUMENT_ERROR; - return FALSE; + return false; } UnicodeString temp; ReorderingBuffer buffer(impl, temp); if(!buffer.init(5, errorCode)) { // small destCapacity for substring normalization - return FALSE; + return false; } - return impl.compose(sArray, sArray+s.length(), onlyContiguous, FALSE, buffer, errorCode); + return impl.compose(sArray, sArray+s.length(), onlyContiguous, false, buffer, errorCode); } virtual UBool isNormalizedUTF8(StringPiece sp, UErrorCode &errorCode) const U_OVERRIDE { if(U_FAILURE(errorCode)) { - return FALSE; + return false; } const uint8_t *s = reinterpret_cast(sp.data()); return impl.composeUTF8(0, onlyContiguous, s, s + sp.length(), nullptr, nullptr, errorCode); @@ -343,7 +343,7 @@ class FCDNormalizer2 : public Normalizer2WithImpl { struct Norm2AllModes : public UMemory { Norm2AllModes(Normalizer2Impl *i) - : impl(i), comp(*i, FALSE), decomp(*i), fcd(*i), fcc(*i, TRUE) {} + : impl(i), comp(*i, false), decomp(*i), fcd(*i), fcc(*i, true) {} ~Norm2AllModes(); static Norm2AllModes *createInstance(Normalizer2Impl *impl, UErrorCode &errorCode); diff --git a/deps/icu-small/source/common/normalizer2impl.h b/deps/icu-small/source/common/normalizer2impl.h index cf3015ea881bfc..4218a30a3452df 100644 --- a/deps/icu-small/source/common/normalizer2impl.h +++ b/deps/icu-small/source/common/normalizer2impl.h @@ -171,7 +171,7 @@ class U_COMMON_API ReorderingBuffer : public UMemory { UErrorCode &errorCode); UBool appendBMP(UChar c, uint8_t cc, UErrorCode &errorCode) { if(remainingCapacity==0 && !resize(1, errorCode)) { - return FALSE; + return false; } if(lastCC<=cc || cc==0) { *limit++=c; @@ -183,7 +183,7 @@ class U_COMMON_API ReorderingBuffer : public UMemory { insert(c, cc); } --remainingCapacity; - return TRUE; + return true; } UBool appendZeroCC(UChar32 c, UErrorCode &errorCode); UBool appendZeroCC(const UChar *s, const UChar *sLimit, UErrorCode &errorCode); @@ -359,7 +359,7 @@ class U_COMMON_API Normalizer2Impl : public UObject { return getFCD16FromNormData(c); } - /** Returns TRUE if the single-or-lead code unit c might have non-zero FCD data. */ + /** Returns true if the single-or-lead code unit c might have non-zero FCD data. */ UBool singleLeadMightHaveNonZeroFCD16(UChar32 lead) const { // 0<=lead<=0xffff uint8_t bits=smallFCD[lead>>8]; @@ -397,8 +397,8 @@ class U_COMMON_API Normalizer2Impl : public UObject { MIN_YES_YES_WITH_CC=0xfe02, JAMO_VT=0xfe00, MIN_NORMAL_MAYBE_YES=0xfc00, - JAMO_L=2, // offset=1 hasCompBoundaryAfter=FALSE - INERT=1, // offset=0 hasCompBoundaryAfter=TRUE + JAMO_L=2, // offset=1 hasCompBoundaryAfter=false + INERT=1, // offset=0 hasCompBoundaryAfter=true // norm16 bit 0 is comp-boundary-after. HAS_COMP_BOUNDARY_AFTER=1, diff --git a/deps/icu-small/source/common/patternprops.h b/deps/icu-small/source/common/patternprops.h index b57cdeb6e534f6..95898d580c82f0 100644 --- a/deps/icu-small/source/common/patternprops.h +++ b/deps/icu-small/source/common/patternprops.h @@ -44,17 +44,17 @@ U_NAMESPACE_BEGIN class U_COMMON_API PatternProps { public: /** - * @return TRUE if c is a Pattern_Syntax code point. + * @return true if c is a Pattern_Syntax code point. */ static UBool isSyntax(UChar32 c); /** - * @return TRUE if c is a Pattern_Syntax or Pattern_White_Space code point. + * @return true if c is a Pattern_Syntax or Pattern_White_Space code point. */ static UBool isSyntaxOrWhiteSpace(UChar32 c); /** - * @return TRUE if c is a Pattern_White_Space character. + * @return true if c is a Pattern_White_Space character. */ static UBool isWhiteSpace(UChar32 c); @@ -78,7 +78,7 @@ class U_COMMON_API PatternProps { /** * Tests whether the string contains a "pattern identifier", that is, * whether it contains only non-Pattern_White_Space, non-Pattern_Syntax characters. - * @return TRUE if there are no Pattern_White_Space or Pattern_Syntax characters in s. + * @return true if there are no Pattern_White_Space or Pattern_Syntax characters in s. */ static UBool isIdentifier(const UChar *s, int32_t length); diff --git a/deps/icu-small/source/common/pluralmap.h b/deps/icu-small/source/common/pluralmap.h index db644093a1fc46..d898ac4671f797 100644 --- a/deps/icu-small/source/common/pluralmap.h +++ b/deps/icu-small/source/common/pluralmap.h @@ -234,7 +234,7 @@ class PluralMap : public PluralMapBase { } /** - * Returns TRUE if this object equals rhs. + * Returns true if this object equals rhs. */ UBool equals( const PluralMap &rhs, @@ -244,13 +244,13 @@ class PluralMap : public PluralMapBase { continue; } if (fVariants[i] == NULL || rhs.fVariants[i] == NULL) { - return FALSE; + return false; } if (!eqFunc(*fVariants[i], *rhs.fVariants[i])) { - return FALSE; + return false; } } - return TRUE; + return true; } private: diff --git a/deps/icu-small/source/common/punycode.cpp b/deps/icu-small/source/common/punycode.cpp index 4f0b9ea9cd385f..94d32a66d7678d 100644 --- a/deps/icu-small/source/common/punycode.cpp +++ b/deps/icu-small/source/common/punycode.cpp @@ -107,36 +107,26 @@ digitToBasic(int32_t digit, UBool uppercase) { } /** - * basicToDigit[] contains the numeric value of a basic code - * point (for use in representing integers) in the range 0 to - * BASE-1, or -1 if b is does not represent a value. + * @return the numeric value of a basic code point (for use in representing integers) + * in the range 0 to BASE-1, or a negative value if cp is invalid. */ -static const int8_t -basicToDigit[256]={ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -1, - - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 -}; +static int32_t decodeDigit(int32_t cp) { + if(cp<=u'Z') { + if(cp<=u'9') { + if(cp 26..35 + } + } else { + return cp-u'A'; // A-Z -> 0..25 + } + } else if(cp<=u'z') { + return cp-'a'; // a..z -> 0..25 + } else { + return -1; + } +} static inline char asciiCaseMap(char b, UBool uppercase) { @@ -178,15 +168,23 @@ adaptBias(int32_t delta, int32_t length, UBool firstTime) { return count+(((BASE-TMIN+1)*delta)/(delta+SKEW)); } -#define MAX_CP_COUNT 200 +namespace { -U_CFUNC int32_t +// ICU-13727: Limit input length for n^2 algorithm +// where well-formed strings are at most 59 characters long. +constexpr int32_t ENCODE_MAX_CODE_UNITS=1000; +constexpr int32_t DECODE_MAX_CHARS=2000; + +} // namespace + +// encode +U_CAPI int32_t u_strToPunycode(const UChar *src, int32_t srcLength, UChar *dest, int32_t destCapacity, const UBool *caseFlags, UErrorCode *pErrorCode) { - int32_t cpBuffer[MAX_CP_COUNT]; + int32_t cpBuffer[ENCODE_MAX_CODE_UNITS]; int32_t n, delta, handledCPCount, basicLength, destLength, bias, j, m, q, k, t, srcCPCount; UChar c, c2; @@ -199,6 +197,10 @@ u_strToPunycode(const UChar *src, int32_t srcLength, *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; return 0; } + if (srcLength>ENCODE_MAX_CODE_UNITS) { + *pErrorCode=U_INPUT_TOO_LONG_ERROR; + return 0; + } /* * Handle the basic code points and @@ -211,9 +213,8 @@ u_strToPunycode(const UChar *src, int32_t srcLength, if((c=src[j])==0) { break; } - if(srcCPCount==MAX_CP_COUNT) { - /* too many input code points */ - *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; + if(j>=ENCODE_MAX_CODE_UNITS) { + *pErrorCode=U_INPUT_TOO_LONG_ERROR; return 0; } if(IS_BASIC(c)) { @@ -243,11 +244,6 @@ u_strToPunycode(const UChar *src, int32_t srcLength, } else { /* length-specified input */ for(j=0; j state to , but guard against overflow: */ - if(m-n>(0x7fffffff-MAX_CP_COUNT-delta)/(handledCPCount+1)) { + if(m-n>(0x7fffffff-handledCPCount-delta)/(handledCPCount+1)) { *pErrorCode=U_INTERNAL_PROGRAM_ERROR; return 0; } @@ -373,7 +369,8 @@ u_strToPunycode(const UChar *src, int32_t srcLength, return u_terminateUChars(dest, destCapacity, destLength, pErrorCode); } -U_CFUNC int32_t +// decode +U_CAPI int32_t u_strFromPunycode(const UChar *src, int32_t srcLength, UChar *dest, int32_t destCapacity, UBool *caseFlags, @@ -395,6 +392,10 @@ u_strFromPunycode(const UChar *src, int32_t srcLength, if(srcLength==-1) { srcLength=u_strlen(src); } + if (srcLength>DECODE_MAX_CHARS) { + *pErrorCode=U_INPUT_TOO_LONG_ERROR; + return 0; + } /* * Handle the basic code points: @@ -455,7 +456,7 @@ u_strFromPunycode(const UChar *src, int32_t srcLength, return 0; } - digit=basicToDigit[(uint8_t)src[in++]]; + digit=decodeDigit(src[in++]); if(digit<0) { *pErrorCode=U_INVALID_CHAR_FOUND; return 0; diff --git a/deps/icu-small/source/common/punycode.h b/deps/icu-small/source/common/punycode.h index 5d8a243175cca3..9e28f770c407ec 100644 --- a/deps/icu-small/source/common/punycode.h +++ b/deps/icu-small/source/common/punycode.h @@ -50,7 +50,7 @@ Adam M. Costello * @param caseFlags Vector of boolean values, one per input UChar, * indicating that the corresponding character is to be * marked for the decoder optionally - * uppercasing (TRUE) or lowercasing (FALSE) + * uppercasing (true) or lowercasing (false) * the character. * ASCII characters are output directly in the case as marked. * Flags corresponding to trail surrogates are ignored. @@ -65,7 +65,7 @@ Adam M. Costello * * @see u_strFromPunycode */ -U_CFUNC int32_t +U_CAPI int32_t u_strToPunycode(const UChar *src, int32_t srcLength, UChar *dest, int32_t destCapacity, const UBool *caseFlags, @@ -83,10 +83,10 @@ u_strToPunycode(const UChar *src, int32_t srcLength, * and of caseFlags in numbers of UBools. * @param caseFlags Output array for case flags as * defined by the Punycode string. - * The caller should uppercase (TRUE) or lowercase (FASLE) + * The caller should uppercase (true) or lowercase (FASLE) * the corresponding character in dest. * For supplementary characters, only the lead surrogate - * is marked, and FALSE is stored for the trail surrogate. + * is marked, and false is stored for the trail surrogate. * This is redundant and not necessary for ASCII characters * because they are already in the case indicated. * Can be NULL if the case flags are not needed. @@ -100,7 +100,7 @@ u_strToPunycode(const UChar *src, int32_t srcLength, * * @see u_strToPunycode */ -U_CFUNC int32_t +U_CAPI int32_t u_strFromPunycode(const UChar *src, int32_t srcLength, UChar *dest, int32_t destCapacity, UBool *caseFlags, diff --git a/deps/icu-small/source/common/putil.cpp b/deps/icu-small/source/common/putil.cpp index 51c2473c982d5d..3ed6a05d22d839 100644 --- a/deps/icu-small/source/common/putil.cpp +++ b/deps/icu-small/source/common/putil.cpp @@ -81,7 +81,7 @@ #include #ifndef U_COMMON_IMPLEMENTATION -#error U_COMMON_IMPLEMENTATION not set - must be set for all ICU source files in common/ - see http://userguide.icu-project.org/howtouseicu +#error U_COMMON_IMPLEMENTATION not set - must be set for all ICU source files in common/ - see https://unicode-org.github.io/icu/userguide/howtouseicu #endif @@ -118,11 +118,15 @@ # ifndef _XPG4_2 # define _XPG4_2 # endif +# elif U_PLATFORM == U_PF_ANDROID +# include +# include # endif #elif U_PLATFORM == U_PF_QNX # include #endif + /* * Only include langinfo.h if we have a way to get the codeset. If we later * depend on more feature, we can test on U_HAVE_NL_LANGINFO. @@ -1043,9 +1047,53 @@ static char* searchForTZFile(const char* path, DefaultTZInfo* tzInfo) { } #endif +#if U_PLATFORM == U_PF_ANDROID +typedef int(system_property_read_callback)(const prop_info* info, + void (*callback)(void* cookie, + const char* name, + const char* value, + uint32_t serial), + void* cookie); +typedef int(system_property_get)(const char*, char*); + +static char gAndroidTimeZone[PROP_VALUE_MAX] = { '\0' }; + +static void u_property_read(void* cookie, const char* name, const char* value, + uint32_t serial) { + uprv_strcpy((char* )cookie, value); +} +#endif + U_CAPI void U_EXPORT2 -uprv_tzname_clear_cache() +uprv_tzname_clear_cache(void) { +#if U_PLATFORM == U_PF_ANDROID + /* Android's timezone is stored in system property. */ + gAndroidTimeZone[0] = '\0'; + void* libc = dlopen("libc.so", RTLD_NOLOAD); + if (libc) { + /* Android API 26+ has new API to get system property and old API + * (__system_property_get) is deprecated */ + system_property_read_callback* property_read_callback = + (system_property_read_callback*)dlsym( + libc, "__system_property_read_callback"); + if (property_read_callback) { + const prop_info* info = + __system_property_find("persist.sys.timezone"); + if (info) { + property_read_callback(info, &u_property_read, gAndroidTimeZone); + } + } else { + system_property_get* property_get = + (system_property_get*)dlsym(libc, "__system_property_get"); + if (property_get) { + property_get("persist.sys.timezone", gAndroidTimeZone); + } + } + dlclose(libc); + } +#endif + #if defined(CHECK_LOCALTIME_LINK) && !defined(DEBUG_SKIP_LOCALTIME_LINK) gTimeZoneBufferPtr = NULL; #endif @@ -1084,7 +1132,11 @@ uprv_tzname(int n) /* This code can be temporarily disabled to test tzname resolution later on. */ #ifndef DEBUG_TZNAME +#if U_PLATFORM == U_PF_ANDROID + tzid = gAndroidTimeZone; +#else tzid = getenv("TZ"); +#endif if (tzid != NULL && isValidOlsonID(tzid) #if U_PLATFORM == U_PF_SOLARIS /* When TZ equals localtime on Solaris, check the /etc/localtime file. */ @@ -2299,7 +2351,7 @@ u_getVersion(UVersionInfo versionArray) { #include #endif /* HAVE_DLFCN_H */ -U_INTERNAL void * U_EXPORT2 +U_CAPI void * U_EXPORT2 uprv_dl_open(const char *libName, UErrorCode *status) { void *ret = NULL; if(U_FAILURE(*status)) return ret; @@ -2313,13 +2365,13 @@ uprv_dl_open(const char *libName, UErrorCode *status) { return ret; } -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uprv_dl_close(void *lib, UErrorCode *status) { if(U_FAILURE(*status)) return; dlclose(lib); } -U_INTERNAL UVoidFunction* U_EXPORT2 +U_CAPI UVoidFunction* U_EXPORT2 uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) { union { UVoidFunction *fp; @@ -2342,7 +2394,7 @@ uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) { /* Windows API implementation. */ // Note: UWP does not expose/allow these APIs, so the UWP version gets the null implementation. */ -U_INTERNAL void * U_EXPORT2 +U_CAPI void * U_EXPORT2 uprv_dl_open(const char *libName, UErrorCode *status) { HMODULE lib = NULL; @@ -2357,7 +2409,7 @@ uprv_dl_open(const char *libName, UErrorCode *status) { return (void*)lib; } -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uprv_dl_close(void *lib, UErrorCode *status) { HMODULE handle = (HMODULE)lib; if(U_FAILURE(*status)) return; @@ -2367,7 +2419,7 @@ uprv_dl_close(void *lib, UErrorCode *status) { return; } -U_INTERNAL UVoidFunction* U_EXPORT2 +U_CAPI UVoidFunction* U_EXPORT2 uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) { HMODULE handle = (HMODULE)lib; UVoidFunction* addr = NULL; @@ -2392,7 +2444,7 @@ uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) { /* No dynamic loading, null (nonexistent) implementation. */ -U_INTERNAL void * U_EXPORT2 +U_CAPI void * U_EXPORT2 uprv_dl_open(const char *libName, UErrorCode *status) { (void)libName; if(U_FAILURE(*status)) return NULL; @@ -2400,7 +2452,7 @@ uprv_dl_open(const char *libName, UErrorCode *status) { return NULL; } -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uprv_dl_close(void *lib, UErrorCode *status) { (void)lib; if(U_FAILURE(*status)) return; @@ -2408,7 +2460,7 @@ uprv_dl_close(void *lib, UErrorCode *status) { return; } -U_INTERNAL UVoidFunction* U_EXPORT2 +U_CAPI UVoidFunction* U_EXPORT2 uprv_dlsym_func(void *lib, const char* sym, UErrorCode *status) { (void)lib; (void)sym; diff --git a/deps/icu-small/source/common/putilimp.h b/deps/icu-small/source/common/putilimp.h index 2e9fbcc4837cd8..a325c6c359ad26 100644 --- a/deps/icu-small/source/common/putilimp.h +++ b/deps/icu-small/source/common/putilimp.h @@ -210,93 +210,93 @@ typedef size_t uintptr_t; * Floating point utility to determine if a double is Not a Number (NaN). * @internal */ -U_INTERNAL UBool U_EXPORT2 uprv_isNaN(double d); +U_CAPI UBool U_EXPORT2 uprv_isNaN(double d); /** * Floating point utility to determine if a double has an infinite value. * @internal */ -U_INTERNAL UBool U_EXPORT2 uprv_isInfinite(double d); +U_CAPI UBool U_EXPORT2 uprv_isInfinite(double d); /** * Floating point utility to determine if a double has a positive infinite value. * @internal */ -U_INTERNAL UBool U_EXPORT2 uprv_isPositiveInfinity(double d); +U_CAPI UBool U_EXPORT2 uprv_isPositiveInfinity(double d); /** * Floating point utility to determine if a double has a negative infinite value. * @internal */ -U_INTERNAL UBool U_EXPORT2 uprv_isNegativeInfinity(double d); +U_CAPI UBool U_EXPORT2 uprv_isNegativeInfinity(double d); /** * Floating point utility that returns a Not a Number (NaN) value. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_getNaN(void); +U_CAPI double U_EXPORT2 uprv_getNaN(void); /** * Floating point utility that returns an infinite value. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_getInfinity(void); +U_CAPI double U_EXPORT2 uprv_getInfinity(void); /** * Floating point utility to truncate a double. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_trunc(double d); +U_CAPI double U_EXPORT2 uprv_trunc(double d); /** * Floating point utility to calculate the floor of a double. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_floor(double d); +U_CAPI double U_EXPORT2 uprv_floor(double d); /** * Floating point utility to calculate the ceiling of a double. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_ceil(double d); +U_CAPI double U_EXPORT2 uprv_ceil(double d); /** * Floating point utility to calculate the absolute value of a double. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_fabs(double d); +U_CAPI double U_EXPORT2 uprv_fabs(double d); /** * Floating point utility to calculate the fractional and integer parts of a double. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_modf(double d, double* pinteger); +U_CAPI double U_EXPORT2 uprv_modf(double d, double* pinteger); /** * Floating point utility to calculate the remainder of a double divided by another double. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_fmod(double d, double y); +U_CAPI double U_EXPORT2 uprv_fmod(double d, double y); /** * Floating point utility to calculate d to the power of exponent (d^exponent). * @internal */ -U_INTERNAL double U_EXPORT2 uprv_pow(double d, double exponent); +U_CAPI double U_EXPORT2 uprv_pow(double d, double exponent); /** * Floating point utility to calculate 10 to the power of exponent (10^exponent). * @internal */ -U_INTERNAL double U_EXPORT2 uprv_pow10(int32_t exponent); +U_CAPI double U_EXPORT2 uprv_pow10(int32_t exponent); /** * Floating point utility to calculate the maximum value of two doubles. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_fmax(double d, double y); +U_CAPI double U_EXPORT2 uprv_fmax(double d, double y); /** * Floating point utility to calculate the minimum value of two doubles. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_fmin(double d, double y); +U_CAPI double U_EXPORT2 uprv_fmin(double d, double y); /** * Private utility to calculate the maximum value of two integers. * @internal */ -U_INTERNAL int32_t U_EXPORT2 uprv_max(int32_t d, int32_t y); +U_CAPI int32_t U_EXPORT2 uprv_max(int32_t d, int32_t y); /** * Private utility to calculate the minimum value of two integers. * @internal */ -U_INTERNAL int32_t U_EXPORT2 uprv_min(int32_t d, int32_t y); +U_CAPI int32_t U_EXPORT2 uprv_min(int32_t d, int32_t y); #if U_IS_BIG_ENDIAN # define uprv_isNegative(number) (*((signed char *)&(number))<0) @@ -309,13 +309,13 @@ U_INTERNAL int32_t U_EXPORT2 uprv_min(int32_t d, int32_t y); * type of arbitrary bit length. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_maxMantissa(void); +U_CAPI double U_EXPORT2 uprv_maxMantissa(void); /** * Floating point utility to calculate the logarithm of a double. * @internal */ -U_INTERNAL double U_EXPORT2 uprv_log(double d); +U_CAPI double U_EXPORT2 uprv_log(double d); /** * Does common notion of rounding e.g. uprv_floor(x + 0.5); @@ -323,7 +323,7 @@ U_INTERNAL double U_EXPORT2 uprv_log(double d); * @return the rounded double * @internal */ -U_INTERNAL double U_EXPORT2 uprv_round(double x); +U_CAPI double U_EXPORT2 uprv_round(double x); /** * Adds the signed integers a and b, storing the result in res. @@ -336,7 +336,7 @@ U_INTERNAL double U_EXPORT2 uprv_round(double x); * @return true if overflow occurred; false if no overflow occurred. * @internal */ -U_INTERNAL UBool U_EXPORT2 uprv_add32_overflow(int32_t a, int32_t b, int32_t* res); +U_CAPI UBool U_EXPORT2 uprv_add32_overflow(int32_t a, int32_t b, int32_t* res); /** * Multiplies the signed integers a and b, storing the result in res. @@ -349,7 +349,7 @@ U_INTERNAL UBool U_EXPORT2 uprv_add32_overflow(int32_t a, int32_t b, int32_t* re * @return true if overflow occurred; false if no overflow occurred. * @internal */ -U_INTERNAL UBool U_EXPORT2 uprv_mul32_overflow(int32_t a, int32_t b, int32_t* res); +U_CAPI UBool U_EXPORT2 uprv_mul32_overflow(int32_t a, int32_t b, int32_t* res); #if 0 /** @@ -359,7 +359,7 @@ U_INTERNAL UBool U_EXPORT2 uprv_mul32_overflow(int32_t a, int32_t b, int32_t* re * @return the number of digits after the decimal point in a double number x. * @internal */ -/*U_INTERNAL int32_t U_EXPORT2 uprv_digitsAfterDecimal(double x);*/ +/*U_CAPI int32_t U_EXPORT2 uprv_digitsAfterDecimal(double x);*/ #endif #if !U_CHARSET_IS_UTF8 @@ -371,7 +371,7 @@ U_INTERNAL UBool U_EXPORT2 uprv_mul32_overflow(int32_t a, int32_t b, int32_t* re * @return the default codepage for this platform * @internal */ -U_INTERNAL const char* U_EXPORT2 uprv_getDefaultCodepage(void); +U_CAPI const char* U_EXPORT2 uprv_getDefaultCodepage(void); #endif /** @@ -383,7 +383,7 @@ U_INTERNAL const char* U_EXPORT2 uprv_getDefaultCodepage(void); * @return the default locale ID string * @internal */ -U_INTERNAL const char* U_EXPORT2 uprv_getDefaultLocaleID(void); +U_CAPI const char* U_EXPORT2 uprv_getDefaultLocaleID(void); /** * Time zone utilities @@ -417,7 +417,7 @@ U_INTERNAL const char* U_EXPORT2 uprv_getDefaultLocaleID(void); * Date/Time application. * @internal */ -U_INTERNAL void U_EXPORT2 uprv_tzset(void); +U_CAPI void U_EXPORT2 uprv_tzset(void); /** * Difference in seconds between coordinated universal @@ -425,7 +425,7 @@ U_INTERNAL void U_EXPORT2 uprv_tzset(void); * @return the difference in seconds between coordinated universal time and local time. * @internal */ -U_INTERNAL int32_t U_EXPORT2 uprv_timezone(void); +U_CAPI int32_t U_EXPORT2 uprv_timezone(void); /** * tzname(0) Three-letter time-zone name derived from TZ environment @@ -435,13 +435,13 @@ U_INTERNAL int32_t U_EXPORT2 uprv_timezone(void); * tzname(1) is an empty string. * @internal */ -U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n); +U_CAPI const char* U_EXPORT2 uprv_tzname(int n); /** * Reset the global tzname cache. * @internal */ -U_INTERNAL void uprv_tzname_clear_cache(); +U_CAPI void uprv_tzname_clear_cache(void); /** * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970. @@ -449,7 +449,7 @@ U_INTERNAL void uprv_tzname_clear_cache(); * @return the UTC time measured in milliseconds * @internal */ -U_INTERNAL UDate U_EXPORT2 uprv_getUTCtime(void); +U_CAPI UDate U_EXPORT2 uprv_getUTCtime(void); /** * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970. @@ -458,15 +458,15 @@ U_INTERNAL UDate U_EXPORT2 uprv_getUTCtime(void); * @return the UTC time measured in milliseconds * @internal */ -U_INTERNAL UDate U_EXPORT2 uprv_getRawUTCtime(void); +U_CAPI UDate U_EXPORT2 uprv_getRawUTCtime(void); /** * Determine whether a pathname is absolute or not, as defined by the platform. * @param path Pathname to test - * @return TRUE if the path is absolute + * @return true if the path is absolute * @internal (ICU 3.0) */ -U_INTERNAL UBool U_EXPORT2 uprv_pathIsAbsolute(const char *path); +U_CAPI UBool U_EXPORT2 uprv_pathIsAbsolute(const char *path); /** * Use U_MAX_PTR instead of this function. @@ -474,7 +474,7 @@ U_INTERNAL UBool U_EXPORT2 uprv_pathIsAbsolute(const char *path); * @return the largest possible pointer greater than the base * @internal (ICU 3.8) */ -U_INTERNAL void * U_EXPORT2 uprv_maximumPtr(void *base); +U_CAPI void * U_EXPORT2 uprv_maximumPtr(void *base); /** * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer. @@ -572,26 +572,26 @@ typedef void (UVoidFunction)(void); * Load a library * @internal (ICU 4.4) */ -U_INTERNAL void * U_EXPORT2 uprv_dl_open(const char *libName, UErrorCode *status); +U_CAPI void * U_EXPORT2 uprv_dl_open(const char *libName, UErrorCode *status); /** * Close a library * @internal (ICU 4.4) */ -U_INTERNAL void U_EXPORT2 uprv_dl_close( void *lib, UErrorCode *status); +U_CAPI void U_EXPORT2 uprv_dl_close( void *lib, UErrorCode *status); /** * Extract a symbol from a library (function) * @internal (ICU 4.8) */ -U_INTERNAL UVoidFunction* U_EXPORT2 uprv_dlsym_func( void *lib, const char *symbolName, UErrorCode *status); +U_CAPI UVoidFunction* U_EXPORT2 uprv_dlsym_func( void *lib, const char *symbolName, UErrorCode *status); /** * Extract a symbol from a library (function) * Not implemented, no clients. * @internal */ -/* U_INTERNAL void * U_EXPORT2 uprv_dlsym_data( void *lib, const char *symbolName, UErrorCode *status); */ +/* U_CAPI void * U_EXPORT2 uprv_dlsym_data( void *lib, const char *symbolName, UErrorCode *status); */ #endif diff --git a/deps/icu-small/source/common/rbbi.cpp b/deps/icu-small/source/common/rbbi.cpp index 43ba58ba9e6577..9b7e70c3cf419f 100644 --- a/deps/icu-small/source/common/rbbi.cpp +++ b/deps/icu-small/source/common/rbbi.cpp @@ -68,10 +68,18 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode init(status); fData = new RBBIDataWrapper(data, status); // status checked in constructor if (U_FAILURE(status)) {return;} - if(fData == 0) { + if(fData == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return; } + if (fData->fForwardTable->fLookAheadResultsSize > 0) { + fLookAheadMatches = static_cast( + uprv_malloc(fData->fForwardTable->fLookAheadResultsSize * sizeof(int32_t))); + if (fLookAheadMatches == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + } } // @@ -98,10 +106,18 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(const uint8_t *compiledRules, } fData = new RBBIDataWrapper(data, RBBIDataWrapper::kDontAdopt, status); if (U_FAILURE(status)) {return;} - if(fData == 0) { + if(fData == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return; } + if (fData->fForwardTable->fLookAheadResultsSize > 0) { + fLookAheadMatches = static_cast( + uprv_malloc(fData->fForwardTable->fLookAheadResultsSize * sizeof(int32_t))); + if (fLookAheadMatches == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + } } @@ -117,10 +133,18 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(UDataMemory* udm, UErrorCode &sta init(status); fData = new RBBIDataWrapper(udm, status); // status checked in constructor if (U_FAILURE(status)) {return;} - if(fData == 0) { + if(fData == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return; } + if (fData->fForwardTable->fLookAheadResultsSize > 0) { + fLookAheadMatches = static_cast( + uprv_malloc(fData->fForwardTable->fLookAheadResultsSize * sizeof(int32_t))); + if (fLookAheadMatches == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + } } @@ -188,30 +212,34 @@ RuleBasedBreakIterator::~RuleBasedBreakIterator() { // fCharIter was adopted from the outside. delete fCharIter; } - fCharIter = NULL; + fCharIter = nullptr; utext_close(&fText); - if (fData != NULL) { + if (fData != nullptr) { fData->removeReference(); - fData = NULL; + fData = nullptr; } delete fBreakCache; - fBreakCache = NULL; + fBreakCache = nullptr; delete fDictionaryCache; - fDictionaryCache = NULL; + fDictionaryCache = nullptr; delete fLanguageBreakEngines; - fLanguageBreakEngines = NULL; + fLanguageBreakEngines = nullptr; delete fUnhandledBreakEngine; - fUnhandledBreakEngine = NULL; + fUnhandledBreakEngine = nullptr; + + uprv_free(fLookAheadMatches); + fLookAheadMatches = nullptr; } /** * Assignment operator. Sets this iterator to have the same behavior, * and iterate over the same text, as the one passed in. + * TODO: needs better handling of memory allocation errors. */ RuleBasedBreakIterator& RuleBasedBreakIterator::operator=(const RuleBasedBreakIterator& that) { @@ -252,6 +280,14 @@ RuleBasedBreakIterator::operator=(const RuleBasedBreakIterator& that) { fData = that.fData->addReference(); } + uprv_free(fLookAheadMatches); + fLookAheadMatches = nullptr; + if (fData && fData->fForwardTable->fLookAheadResultsSize > 0) { + fLookAheadMatches = static_cast( + uprv_malloc(fData->fForwardTable->fLookAheadResultsSize * sizeof(int32_t))); + } + + fPosition = that.fPosition; fRuleStatusIndex = that.fRuleStatusIndex; fDone = that.fDone; @@ -275,16 +311,17 @@ RuleBasedBreakIterator::operator=(const RuleBasedBreakIterator& that) { // //----------------------------------------------------------------------------- void RuleBasedBreakIterator::init(UErrorCode &status) { - fCharIter = NULL; - fData = NULL; + fCharIter = nullptr; + fData = nullptr; fPosition = 0; fRuleStatusIndex = 0; fDone = false; fDictionaryCharCount = 0; - fLanguageBreakEngines = NULL; - fUnhandledBreakEngine = NULL; - fBreakCache = NULL; - fDictionaryCache = NULL; + fLanguageBreakEngines = nullptr; + fUnhandledBreakEngine = nullptr; + fBreakCache = nullptr; + fDictionaryCache = nullptr; + fLookAheadMatches = nullptr; // Note: IBM xlC is unable to assign or initialize member fText from UTEXT_INITIALIZER. // fText = UTEXT_INITIALIZER; @@ -700,50 +737,53 @@ enum RBBIRunMode { }; -// Map from look-ahead break states (corresponds to rules) to boundary positions. -// Allows multiple lookahead break rules to be in flight at the same time. +// Wrapper functions to select the appropriate handleNext() or handleSafePrevious() +// instantiation, based on whether an 8 or 16 bit table is required. // -// This is a temporary approach for ICU 57. A better fix is to make the look-ahead numbers -// in the state table be sequential, then we can just index an array. And the -// table could also tell us in advance how big that array needs to be. -// -// Before ICU 57 there was just a single simple variable for a look-ahead match that -// was in progress. Two rules at once did not work. - -static const int32_t kMaxLookaheads = 8; -struct LookAheadResults { - int32_t fUsedSlotLimit; - int32_t fPositions[8]; - int16_t fKeys[8]; +// These Trie access functions will be inlined within the handleNext()/Previous() instantions. +static inline uint16_t TrieFunc8(const UCPTrie *trie, UChar32 c) { + return UCPTRIE_FAST_GET(trie, UCPTRIE_8, c); +} - LookAheadResults() : fUsedSlotLimit(0), fPositions(), fKeys() {} +static inline uint16_t TrieFunc16(const UCPTrie *trie, UChar32 c) { + return UCPTRIE_FAST_GET(trie, UCPTRIE_16, c); +} - int32_t getPosition(int16_t key) { - for (int32_t i=0; ifForwardTable; + bool use8BitsTrie = ucptrie_getValueWidth(fData->fTrie) == UCPTRIE_VALUE_BITS_8; + if (statetable->fFlags & RBBI_8BITS_ROWS) { + if (use8BitsTrie) { + return handleNext(); + } else { + return handleNext(); + } + } else { + if (use8BitsTrie) { + return handleNext(); + } else { + return handleNext(); } - UPRV_UNREACHABLE; } +} - void setPosition(int16_t key, int32_t position) { - int32_t i; - for (i=0; ifReverseTable; + bool use8BitsTrie = ucptrie_getValueWidth(fData->fTrie) == UCPTRIE_VALUE_BITS_8; + if (statetable->fFlags & RBBI_8BITS_ROWS) { + if (use8BitsTrie) { + return handleSafePrevious(fromPosition); + } else { + return handleSafePrevious(fromPosition); } - if (i >= kMaxLookaheads) { - UPRV_UNREACHABLE; + } else { + if (use8BitsTrie) { + return handleSafePrevious(fromPosition); + } else { + return handleSafePrevious(fromPosition); } - fKeys[i] = key; - fPositions[i] = position; - U_ASSERT(fUsedSlotLimit == i); - fUsedSlotLimit = i + 1; } -}; +} //----------------------------------------------------------------------------------- @@ -752,19 +792,20 @@ struct LookAheadResults { // Run the state machine to find a boundary // //----------------------------------------------------------------------------------- +template int32_t RuleBasedBreakIterator::handleNext() { int32_t state; uint16_t category = 0; RBBIRunMode mode; - RBBIStateTableRow *row; + RowType *row; UChar32 c; - LookAheadResults lookAheadMatches; int32_t result = 0; int32_t initialPosition = 0; const RBBIStateTable *statetable = fData->fForwardTable; const char *tableData = statetable->fTableData; uint32_t tableRowLen = statetable->fRowLen; + uint32_t dictStart = statetable->fDictCategoriesStart; #ifdef RBBI_DEBUG if (gTrace) { RBBIDebugPuts("Handle Next pos char state category"); @@ -789,7 +830,7 @@ int32_t RuleBasedBreakIterator::handleNext() { // Set the initial state for the state machine state = START_STATE; - row = (RBBIStateTableRow *) + row = (RowType *) //(statetable->fTableData + (statetable->fRowLen * state)); (tableData + tableRowLen * state); @@ -825,21 +866,8 @@ int32_t RuleBasedBreakIterator::handleNext() { if (mode == RBBI_RUN) { // look up the current character's character category, which tells us // which column in the state table to look at. - // Note: the 16 in UTRIE_GET16 refers to the size of the data being returned, - // not the size of the character going in, which is a UChar32. - // - category = UTRIE2_GET16(fData->fTrie, c); - - // Check the dictionary bit in the character's category. - // Counter is only used by dictionary based iteration. - // Chars that need to be handled by a dictionary have a flag bit set - // in their category values. - // - if ((category & 0x4000) != 0) { - fDictionaryCharCount++; - // And off the dictionary flag bit. - category &= ~0x4000; - } + category = trieFunc(fData->fTrie, c); + fDictionaryCharCount += (category >= dictStart); } #ifdef RBBI_DEBUG @@ -860,25 +888,24 @@ int32_t RuleBasedBreakIterator::handleNext() { // fNextState is a variable-length array. U_ASSERT(categoryfHeader->fCatCount); state = row->fNextState[category]; /*Not accessing beyond memory*/ - row = (RBBIStateTableRow *) + row = (RowType *) // (statetable->fTableData + (statetable->fRowLen * state)); (tableData + tableRowLen * state); - if (row->fAccepting == -1) { + uint16_t accepting = row->fAccepting; + if (accepting == ACCEPTING_UNCONDITIONAL) { // Match found, common case. if (mode != RBBI_START) { result = (int32_t)UTEXT_GETNATIVEINDEX(&fText); } - fRuleStatusIndex = row->fTagIdx; // Remember the break status (tag) values. - } - - int16_t completedRule = row->fAccepting; - if (completedRule > 0) { + fRuleStatusIndex = row->fTagsIdx; // Remember the break status (tag) values. + } else if (accepting > ACCEPTING_UNCONDITIONAL) { // Lookahead match is completed. - int32_t lookaheadResult = lookAheadMatches.getPosition(completedRule); + U_ASSERT(accepting < fData->fForwardTable->fLookAheadResultsSize); + int32_t lookaheadResult = fLookAheadMatches[accepting]; if (lookaheadResult >= 0) { - fRuleStatusIndex = row->fTagIdx; + fRuleStatusIndex = row->fTagsIdx; fPosition = lookaheadResult; return lookaheadResult; } @@ -890,10 +917,12 @@ int32_t RuleBasedBreakIterator::handleNext() { // This would enable hard-break rules with no following context. // But there are line break test failures when trying this. Investigate. // Issue ICU-20837 - int16_t rule = row->fLookAhead; - if (rule != 0) { + uint16_t rule = row->fLookAhead; + U_ASSERT(rule == 0 || rule > ACCEPTING_UNCONDITIONAL); + U_ASSERT(rule == 0 || rule < fData->fForwardTable->fLookAheadResultsSize); + if (rule > ACCEPTING_UNCONDITIONAL) { int32_t pos = (int32_t)UTEXT_GETNATIVEINDEX(&fText); - lookAheadMatches.setPosition(rule, pos); + fLookAheadMatches[rule] = pos; } if (state == STOP_STATE) { @@ -948,10 +977,12 @@ int32_t RuleBasedBreakIterator::handleNext() { // because the safe table does not require as many options. // //----------------------------------------------------------------------------------- +template int32_t RuleBasedBreakIterator::handleSafePrevious(int32_t fromPosition) { + int32_t state; uint16_t category = 0; - RBBIStateTableRow *row; + RowType *row; UChar32 c; int32_t result = 0; @@ -971,7 +1002,7 @@ int32_t RuleBasedBreakIterator::handleSafePrevious(int32_t fromPosition) { // Set the initial state for the state machine c = UTEXT_PREVIOUS32(&fText); state = START_STATE; - row = (RBBIStateTableRow *) + row = (RowType *) (stateTable->fTableData + (stateTable->fRowLen * state)); // loop until we reach the start of the text or transition to state 0 @@ -980,12 +1011,9 @@ int32_t RuleBasedBreakIterator::handleSafePrevious(int32_t fromPosition) { // look up the current character's character category, which tells us // which column in the state table to look at. - // Note: the 16 in UTRIE_GET16 refers to the size of the data being returned, - // not the size of the character going in, which is a UChar32. // - // And off the dictionary flag bit. For reverse iteration it is not used. - category = UTRIE2_GET16(fData->fTrie, c); - category &= ~0x4000; + // Off the dictionary flag bit. For reverse iteration it is not used. + category = trieFunc(fData->fTrie, c); #ifdef RBBI_DEBUG if (gTrace) { @@ -1004,7 +1032,7 @@ int32_t RuleBasedBreakIterator::handleSafePrevious(int32_t fromPosition) { // fNextState is a variable-length array. U_ASSERT(categoryfHeader->fCatCount); state = row->fNextState[category]; /*Not accessing beyond memory*/ - row = (RBBIStateTableRow *) + row = (RowType *) (stateTable->fTableData + (stateTable->fRowLen * state)); if (state == STOP_STATE) { @@ -1024,6 +1052,7 @@ int32_t RuleBasedBreakIterator::handleSafePrevious(int32_t fromPosition) { return result; } + //------------------------------------------------------------------------------- // // getRuleStatus() Return the break rule tag associated with the current diff --git a/deps/icu-small/source/common/rbbi_cache.cpp b/deps/icu-small/source/common/rbbi_cache.cpp index 4f9e83360a2a32..63ff3001c7034e 100644 --- a/deps/icu-small/source/common/rbbi_cache.cpp +++ b/deps/icu-small/source/common/rbbi_cache.cpp @@ -142,13 +142,15 @@ void RuleBasedBreakIterator::DictionaryCache::populateDictionary(int32_t startPo utext_setNativeIndex(text, rangeStart); UChar32 c = utext_current32(text); - category = UTRIE2_GET16(fBI->fData->fTrie, c); + category = ucptrie_get(fBI->fData->fTrie, c); + uint32_t dictStart = fBI->fData->fForwardTable->fDictCategoriesStart; while(U_SUCCESS(status)) { - while((current = (int32_t)UTEXT_GETNATIVEINDEX(text)) < rangeEnd && (category & 0x4000) == 0) { + while((current = (int32_t)UTEXT_GETNATIVEINDEX(text)) < rangeEnd + && (category < dictStart)) { utext_next32(text); // TODO: cleaner loop structure. c = utext_current32(text); - category = UTRIE2_GET16(fBI->fData->fTrie, c); + category = ucptrie_get(fBI->fData->fTrie, c); } if (current >= rangeEnd) { break; @@ -166,7 +168,7 @@ void RuleBasedBreakIterator::DictionaryCache::populateDictionary(int32_t startPo // Reload the loop variables for the next go-round c = utext_current32(text); - category = UTRIE2_GET16(fBI->fData->fTrie, c); + category = ucptrie_get(fBI->fData->fTrie, c); } // If we found breaks, ensure that the first and last entries are diff --git a/deps/icu-small/source/common/rbbi_cache.h b/deps/icu-small/source/common/rbbi_cache.h index 864ff811aaaff3..8c1fa86e7d1aa1 100644 --- a/deps/icu-small/source/common/rbbi_cache.h +++ b/deps/icu-small/source/common/rbbi_cache.h @@ -126,13 +126,13 @@ class RuleBasedBreakIterator::BreakCache: public UMemory { * Additional boundaries, either preceding or following, may be added * to the cache as a side effect. * - * Return FALSE if the operation failed. + * Return false if the operation failed. */ UBool populateNear(int32_t position, UErrorCode &status); /** * Add boundary(s) to the cache following the current last boundary. - * Return FALSE if at the end of the text, and no more boundaries can be added. + * Return false if at the end of the text, and no more boundaries can be added. * Leave iteration position at the first newly added boundary, or unchanged if no boundary was added. */ UBool populateFollowing(); @@ -170,7 +170,7 @@ class RuleBasedBreakIterator::BreakCache: public UMemory { * Fails if the requested position is outside of the range of boundaries currently held by the cache. * The startPosition must be on a code point boundary. * - * Return TRUE if successful, FALSE if the specified position is after + * Return true if successful, false if the specified position is after * the last cached boundary or before the first. */ UBool seek(int32_t startPosition); diff --git a/deps/icu-small/source/common/rbbicst.pl b/deps/icu-small/source/common/rbbicst.pl index 839b9501dda953..29f575d7d09357 100755 --- a/deps/icu-small/source/common/rbbicst.pl +++ b/deps/icu-small/source/common/rbbicst.pl @@ -1,6 +1,6 @@ #************************************************************************** # Copyright (C) 2016 and later: Unicode, Inc. and others. -# License & terms of use: http://www.unicode.org/copyright.html#License +# License & terms of use: http://www.unicode.org/copyright.html #************************************************************************** #************************************************************************** # Copyright (C) 2002-2016 International Business Machines Corporation diff --git a/deps/icu-small/source/common/rbbidata.cpp b/deps/icu-small/source/common/rbbidata.cpp index fdcb564961362e..f78d9d06689178 100644 --- a/deps/icu-small/source/common/rbbidata.cpp +++ b/deps/icu-small/source/common/rbbidata.cpp @@ -11,10 +11,10 @@ #if !UCONFIG_NO_BREAK_ITERATION +#include "unicode/ucptrie.h" #include "unicode/utypes.h" #include "rbbidata.h" #include "rbbirb.h" -#include "utrie2.h" #include "udatamem.h" #include "cmemory.h" #include "cstring.h" @@ -110,17 +110,24 @@ void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) { fReverseTable = (RBBIStateTable *)((char *)data + fHeader->fRTable); } - fTrie = utrie2_openFromSerialized(UTRIE2_16_VALUE_BITS, - (uint8_t *)data + fHeader->fTrie, - fHeader->fTrieLen, - NULL, // *actual length - &status); + fTrie = ucptrie_openFromBinary(UCPTRIE_TYPE_FAST, + UCPTRIE_VALUE_BITS_ANY, + (uint8_t *)data + fHeader->fTrie, + fHeader->fTrieLen, + nullptr, // *actual length + &status); if (U_FAILURE(status)) { return; } - fRuleSource = (UChar *)((char *)data + fHeader->fRuleSource); - fRuleString.setTo(TRUE, fRuleSource, -1); + UCPTrieValueWidth width = ucptrie_getValueWidth(fTrie); + if (!(width == UCPTRIE_VALUE_BITS_8 || width == UCPTRIE_VALUE_BITS_16)) { + status = U_INVALID_FORMAT_ERROR; + return; + } + + fRuleSource = ((char *)data + fHeader->fRuleSource); + fRuleString = UnicodeString::fromUTF8(StringPiece(fRuleSource, fHeader->fRuleSourceLen)); U_ASSERT(data->fRuleSourceLen > 0); fRuleStatusTable = (int32_t *)((char *)data + fHeader->fStatusTable); @@ -142,8 +149,8 @@ void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) { //----------------------------------------------------------------------------- RBBIDataWrapper::~RBBIDataWrapper() { U_ASSERT(fRefCount == 0); - utrie2_close(fTrie); - fTrie = NULL; + ucptrie_close(fTrie); + fTrie = nullptr; if (fUDataMem) { udata_close(fUDataMem); } else if (!fDontFreeData) { @@ -223,9 +230,16 @@ void RBBIDataWrapper::printTable(const char *heading, const RBBIStateTable *tab uint32_t c; uint32_t s; - RBBIDebugPrintf(" %s\n", heading); + RBBIDebugPrintf("%s\n", heading); - RBBIDebugPrintf("State | Acc LA TagIx"); + RBBIDebugPrintf(" fDictCategoriesStart: %d\n", table->fDictCategoriesStart); + RBBIDebugPrintf(" fLookAheadResultsSize: %d\n", table->fLookAheadResultsSize); + RBBIDebugPrintf(" Flags: %4x RBBI_LOOKAHEAD_HARD_BREAK=%s RBBI_BOF_REQUIRED=%s RBBI_8BITS_ROWS=%s\n", + table->fFlags, + table->fFlags & RBBI_LOOKAHEAD_HARD_BREAK ? "T" : "F", + table->fFlags & RBBI_BOF_REQUIRED ? "T" : "F", + table->fFlags & RBBI_8BITS_ROWS ? "T" : "F"); + RBBIDebugPrintf("\nState | Acc LA TagIx"); for (c=0; cfCatCount; c++) {RBBIDebugPrintf("%3d ", c);} RBBIDebugPrintf("\n------|---------------"); for (c=0;cfCatCount; c++) { RBBIDebugPrintf("----"); @@ -236,12 +250,20 @@ void RBBIDataWrapper::printTable(const char *heading, const RBBIStateTable *tab RBBIDebugPrintf(" N U L L T A B L E\n\n"); return; } + UBool use8Bits = table->fFlags & RBBI_8BITS_ROWS; for (s=0; sfNumStates; s++) { RBBIStateTableRow *row = (RBBIStateTableRow *) (table->fTableData + (table->fRowLen * s)); - RBBIDebugPrintf("%4d | %3d %3d %3d ", s, row->fAccepting, row->fLookAhead, row->fTagIdx); - for (c=0; cfCatCount; c++) { - RBBIDebugPrintf("%3d ", row->fNextState[c]); + if (use8Bits) { + RBBIDebugPrintf("%4d | %3d %3d %3d ", s, row->r8.fAccepting, row->r8.fLookAhead, row->r8.fTagsIdx); + for (c=0; cfCatCount; c++) { + RBBIDebugPrintf("%3d ", row->r8.fNextState[c]); + } + } else { + RBBIDebugPrintf("%4d | %3d %3d %3d ", s, row->r16.fAccepting, row->r16.fLookAhead, row->r16.fTagsIdx); + for (c=0; cfCatCount; c++) { + RBBIDebugPrintf("%3d ", row->r16.fNextState[c]); + } } RBBIDebugPrintf("\n"); } @@ -382,10 +404,23 @@ ubrk_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outD tableLength = ds->readUInt32(rbbiDH->fFTableLen); if (tableLength > 0) { + RBBIStateTable *rbbiST = (RBBIStateTable *)(inBytes+tableStartOffset); + UBool use8Bits = ds->readUInt32(rbbiST->fFlags) & RBBI_8BITS_ROWS; + ds->swapArray32(ds, inBytes+tableStartOffset, topSize, outBytes+tableStartOffset, status); - ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize, - outBytes+tableStartOffset+topSize, status); + + // Swap the state table if the table is in 16 bits. + if (use8Bits) { + if (outBytes != inBytes) { + uprv_memmove(outBytes+tableStartOffset+topSize, + inBytes+tableStartOffset+topSize, + tableLength-topSize); + } + } else { + ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize, + outBytes+tableStartOffset+topSize, status); + } } // Reverse state table. Same layout as forward table, above. @@ -393,19 +428,35 @@ ubrk_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outD tableLength = ds->readUInt32(rbbiDH->fRTableLen); if (tableLength > 0) { + RBBIStateTable *rbbiST = (RBBIStateTable *)(inBytes+tableStartOffset); + UBool use8Bits = ds->readUInt32(rbbiST->fFlags) & RBBI_8BITS_ROWS; + ds->swapArray32(ds, inBytes+tableStartOffset, topSize, outBytes+tableStartOffset, status); - ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize, - outBytes+tableStartOffset+topSize, status); + + // Swap the state table if the table is in 16 bits. + if (use8Bits) { + if (outBytes != inBytes) { + uprv_memmove(outBytes+tableStartOffset+topSize, + inBytes+tableStartOffset+topSize, + tableLength-topSize); + } + } else { + ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize, + outBytes+tableStartOffset+topSize, status); + } } // Trie table for character categories - utrie2_swap(ds, inBytes+ds->readUInt32(rbbiDH->fTrie), ds->readUInt32(rbbiDH->fTrieLen), - outBytes+ds->readUInt32(rbbiDH->fTrie), status); - - // Source Rules Text. It's UChar data - ds->swapArray16(ds, inBytes+ds->readUInt32(rbbiDH->fRuleSource), ds->readUInt32(rbbiDH->fRuleSourceLen), - outBytes+ds->readUInt32(rbbiDH->fRuleSource), status); + ucptrie_swap(ds, inBytes+ds->readUInt32(rbbiDH->fTrie), ds->readUInt32(rbbiDH->fTrieLen), + outBytes+ds->readUInt32(rbbiDH->fTrie), status); + + // Source Rules Text. It's UTF8 data + if (outBytes != inBytes) { + uprv_memmove(outBytes+ds->readUInt32(rbbiDH->fRuleSource), + inBytes+ds->readUInt32(rbbiDH->fRuleSource), + ds->readUInt32(rbbiDH->fRuleSourceLen)); + } // Table of rule status values. It's all int_32 values ds->swapArray32(ds, inBytes+ds->readUInt32(rbbiDH->fStatusTable), ds->readUInt32(rbbiDH->fStatusTableLen), diff --git a/deps/icu-small/source/common/rbbidata.h b/deps/icu-small/source/common/rbbidata.h index 96e4649533f068..5d725deba4c262 100644 --- a/deps/icu-small/source/common/rbbidata.h +++ b/deps/icu-small/source/common/rbbidata.h @@ -49,16 +49,17 @@ ubrk_swap(const UDataSwapper *ds, #ifdef __cplusplus +#include "unicode/ucptrie.h" #include "unicode/uobject.h" #include "unicode/unistr.h" #include "unicode/uversion.h" #include "umutex.h" -#include "utrie2.h" + U_NAMESPACE_BEGIN // The current RBBI data format version. -static const uint8_t RBBI_DATA_FORMAT_VERSION[] = {5, 0, 0, 0}; +static const uint8_t RBBI_DATA_FORMAT_VERSION[] = {6, 0, 0, 0}; /* * The following structs map exactly onto the raw data from ICU common data file. @@ -94,49 +95,61 @@ struct RBBIDataHeader { -struct RBBIStateTableRow { - int16_t fAccepting; /* Non-zero if this row is for an accepting state. */ - /* Value 0: not an accepting state. */ - /* -1: Unconditional Accepting state. */ - /* positive: Look-ahead match has completed. */ - /* Actual boundary position happened earlier */ - /* Value here == fLookAhead in earlier */ - /* state, at actual boundary pos. */ - int16_t fLookAhead; /* Non-zero if this row is for a state that */ - /* corresponds to a '/' in the rule source. */ - /* Value is the same as the fAccepting */ - /* value for the rule (which will appear */ - /* in a different state. */ - int16_t fTagIdx; /* Non-zero if this row covers a {tagged} position */ - /* from a rule. Value is the index in the */ - /* StatusTable of the set of matching */ - /* tags (rule status values) */ - int16_t fReserved; - uint16_t fNextState[1]; /* Next State, indexed by char category. */ - /* Variable-length array declared with length 1 */ - /* to disable bounds checkers. */ - /* Array Size is actually fData->fHeader->fCatCount*/ - /* CAUTION: see RBBITableBuilder::getTableSize() */ - /* before changing anything here. */ +template +struct RBBIStateTableRowT { + T fAccepting; // Non-zero if this row is for an accepting state. + // Value 0: not an accepting state. + // 1: (ACCEPTING_UNCONDITIONAL) Unconditional Accepting state. + // >1: Look-ahead match has completed. + // Actual boundary position happened earlier. + // Value here == fLookAhead in earlier + // state, at actual boundary pos. + T fLookAhead; // Non-zero if this row is for a state that + // corresponds to a '/' in the rule source. + // Value is the same as the fAccepting + // value for the rule (which will appear + // in a different state. + T fTagsIdx; // Non-zero if this row covers a {tagged} position + // from a rule. Value is the index in the + // StatusTable of the set of matching + // tags (rule status values) + T fNextState[1]; // Next State, indexed by char category. + // Variable-length array declared with length 1 + // to disable bounds checkers. + // Array Size is actually fData->fHeader->fCatCount + // CAUTION: see RBBITableBuilder::getTableSize() + // before changing anything here. }; +typedef RBBIStateTableRowT RBBIStateTableRow8; +typedef RBBIStateTableRowT RBBIStateTableRow16; + +constexpr uint16_t ACCEPTING_UNCONDITIONAL = 1; // Value constant for RBBIStateTableRow::fAccepting + +union RBBIStateTableRow { + RBBIStateTableRow16 r16; + RBBIStateTableRow8 r8; +}; struct RBBIStateTable { - uint32_t fNumStates; /* Number of states. */ - uint32_t fRowLen; /* Length of a state table row, in bytes. */ - uint32_t fFlags; /* Option Flags for this state table */ - uint32_t fReserved; /* reserved */ - char fTableData[1]; /* First RBBIStateTableRow begins here. */ - /* Variable-length array declared with length 1 */ - /* to disable bounds checkers. */ - /* (making it char[] simplifies ugly address */ - /* arithmetic for indexing variable length rows.) */ + uint32_t fNumStates; // Number of states. + uint32_t fRowLen; // Length of a state table row, in bytes. + uint32_t fDictCategoriesStart; // Char category number of the first dictionary + // char class, or the the largest category number + 1 + // if there are no dictionary categories. + uint32_t fLookAheadResultsSize; // Size of run-time array required for holding + // look-ahead results. Indexed by row.fLookAhead. + uint32_t fFlags; // Option Flags for this state table. + char fTableData[1]; // First RBBIStateTableRow begins here. + // Variable-length array declared with length 1 + // to disable bounds checkers. + // (making it char[] simplifies ugly address + // arithmetic for indexing variable length rows.) }; -typedef enum { - RBBI_LOOKAHEAD_HARD_BREAK = 1, - RBBI_BOF_REQUIRED = 2 -} RBBIStateTableFlags; +constexpr uint32_t RBBI_LOOKAHEAD_HARD_BREAK = 1; +constexpr uint32_t RBBI_BOF_REQUIRED = 2; +constexpr uint32_t RBBI_8BITS_ROWS = 4; /* */ @@ -170,13 +183,13 @@ class RBBIDataWrapper : public UMemory { const RBBIDataHeader *fHeader; const RBBIStateTable *fForwardTable; const RBBIStateTable *fReverseTable; - const UChar *fRuleSource; + const char *fRuleSource; const int32_t *fRuleStatusTable; /* number of int32_t values in the rule status table. Used to sanity check indexing */ int32_t fStatusMaxIdx; - UTrie2 *fTrie; + UCPTrie *fTrie; private: u_atomic_int32_t fRefCount; @@ -184,8 +197,8 @@ class RBBIDataWrapper : public UMemory { UnicodeString fRuleString; UBool fDontFreeData; - RBBIDataWrapper(const RBBIDataWrapper &other); /* forbid copying of this class */ - RBBIDataWrapper &operator=(const RBBIDataWrapper &other); /* forbid copying of this class */ + RBBIDataWrapper(const RBBIDataWrapper &other) = delete; /* forbid copying of this class */ + RBBIDataWrapper &operator=(const RBBIDataWrapper &other) = delete; /* forbid copying of this class */ }; diff --git a/deps/icu-small/source/common/rbbinode.h b/deps/icu-small/source/common/rbbinode.h index e33662167fe3fd..ef4e4ccac7f08e 100644 --- a/deps/icu-small/source/common/rbbinode.h +++ b/deps/icu-small/source/common/rbbinode.h @@ -79,7 +79,7 @@ class RBBINode : public UMemory { // corresponds to columns in the final // state transition table. - UBool fLookAheadEnd; // For endMark nodes, set TRUE if + UBool fLookAheadEnd; // For endMark nodes, set true if // marking the end of a look-ahead rule. UBool fRuleRoot; // True if this node is the root of a rule. diff --git a/deps/icu-small/source/common/rbbirb.cpp b/deps/icu-small/source/common/rbbirb.cpp index 4df96532643d06..09c8d3de7e6687 100644 --- a/deps/icu-small/source/common/rbbirb.cpp +++ b/deps/icu-small/source/common/rbbirb.cpp @@ -22,6 +22,7 @@ #include "unicode/uniset.h" #include "unicode/uchar.h" #include "unicode/uchriter.h" +#include "unicode/ustring.h" #include "unicode/parsepos.h" #include "unicode/parseerr.h" @@ -154,7 +155,14 @@ RBBIDataHeader *RBBIRuleBuilder::flattenData() { int32_t reverseTableSize = align8(fForwardTable->getSafeTableSize()); int32_t trieSize = align8(fSetBuilder->getTrieSize()); int32_t statusTableSize = align8(fRuleStatusVals->size() * sizeof(int32_t)); - int32_t rulesSize = align8((fStrippedRules.length()+1) * sizeof(UChar)); + + int32_t rulesLengthInUTF8 = 0; + u_strToUTF8WithSub(0, 0, &rulesLengthInUTF8, + fStrippedRules.getBuffer(), fStrippedRules.length(), + 0xfffd, nullptr, fStatus); + *fStatus = U_ZERO_ERROR; + + int32_t rulesSize = align8((rulesLengthInUTF8+1)); int32_t totalSize = headerSize + forwardTableSize @@ -197,11 +205,11 @@ RBBIDataHeader *RBBIRuleBuilder::flattenData() { data->fRTableLen = reverseTableSize; data->fTrie = data->fRTable + data->fRTableLen; - data->fTrieLen = fSetBuilder->getTrieSize(); - data->fStatusTable = data->fTrie + trieSize; + data->fTrieLen = trieSize; + data->fStatusTable = data->fTrie + data->fTrieLen; data->fStatusTableLen= statusTableSize; data->fRuleSource = data->fStatusTable + statusTableSize; - data->fRuleSourceLen = fStrippedRules.length() * sizeof(UChar); + data->fRuleSourceLen = rulesLengthInUTF8; uprv_memset(data->fReserved, 0, sizeof(data->fReserved)); @@ -214,7 +222,12 @@ RBBIDataHeader *RBBIRuleBuilder::flattenData() { ruleStatusTable[i] = fRuleStatusVals->elementAti(i); } - fStrippedRules.extract((UChar *)((uint8_t *)data+data->fRuleSource), rulesSize/2+1, *fStatus); + u_strToUTF8WithSub((char *)data+data->fRuleSource, rulesSize, &rulesLengthInUTF8, + fStrippedRules.getBuffer(), fStrippedRules.length(), + 0xfffd, nullptr, fStatus); + if (U_FAILURE(*fStatus)) { + return NULL; + } return data; } @@ -274,9 +287,7 @@ RBBIDataHeader *RBBIRuleBuilder::build(UErrorCode &status) { // // UnicodeSet processing. - // Munge the Unicode Sets to create a set of character categories. - // Generate the mapping tables (TRIE) from input code points to - // the character categories. + // Munge the Unicode Sets to create an initial set of character categories. // fSetBuilder->buildRanges(); @@ -290,6 +301,12 @@ RBBIDataHeader *RBBIRuleBuilder::build(UErrorCode &status) { } fForwardTable->buildForwardTable(); + + // State table and character category optimization. + // Merge equivalent rows and columns. + // Note that this process alters the initial set of character categories, + // causing the representation of UnicodeSets in the parse tree to become invalid. + optimizeTables(); fForwardTable->buildSafeReverseTable(status); @@ -302,6 +319,9 @@ RBBIDataHeader *RBBIRuleBuilder::build(UErrorCode &status) { } #endif + // Generate the mapping tables (TRIE) from input code points to + // the character categories. + // fSetBuilder->buildTrie(); // diff --git a/deps/icu-small/source/common/rbbiscan.cpp b/deps/icu-small/source/common/rbbiscan.cpp index da8246ba6f1e47..947a07304fd8b1 100644 --- a/deps/icu-small/source/common/rbbiscan.cpp +++ b/deps/icu-small/source/common/rbbiscan.cpp @@ -829,16 +829,14 @@ static const UChar chRParen = 0x29; UnicodeString RBBIRuleScanner::stripRules(const UnicodeString &rules) { UnicodeString strippedRules; int32_t rulesLength = rules.length(); - bool skippingSpaces = false; for (int32_t idx=0; idxfStatus; - fRangeList = 0; - fTrie = 0; + fRangeList = nullptr; + fMutableTrie = nullptr; + fTrie = nullptr; fTrieSize = 0; fGroupCount = 0; - fSawBOF = FALSE; + fSawBOF = false; } @@ -79,7 +80,8 @@ RBBISetBuilder::~RBBISetBuilder() delete r; } - utrie2_close(fTrie); + ucptrie_close(fTrie); + umutablecptrie_close(fMutableTrie); } @@ -194,24 +196,47 @@ void RBBISetBuilder::buildRanges() { // // Numbering: # 0 (state table column 0) is unused. // # 1 is reserved - table column 1 is for end-of-input - // # 2 is reserved - table column 2 is for beginning-in-input + // # 2 is reserved - table column 2 is for beginning-of-input // # 3 is the first range list. // RangeDescriptor *rlSearchRange; - for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) { + int32_t dictGroupCount = 0; + + for (rlRange = fRangeList; rlRange!=nullptr; rlRange=rlRange->fNext) { for (rlSearchRange=fRangeList; rlSearchRange != rlRange; rlSearchRange=rlSearchRange->fNext) { if (rlRange->fIncludesSets->equals(*rlSearchRange->fIncludesSets)) { rlRange->fNum = rlSearchRange->fNum; + rlRange->fIncludesDict = rlSearchRange->fIncludesDict; break; } } if (rlRange->fNum == 0) { - fGroupCount ++; - rlRange->fNum = fGroupCount+2; - rlRange->setDictionaryFlag(); - addValToSets(rlRange->fIncludesSets, fGroupCount+2); + rlRange->fFirstInGroup = true; + if (rlRange->isDictionaryRange()) { + rlRange->fNum = ++dictGroupCount; + rlRange->fIncludesDict = true; + } else { + fGroupCount++; + rlRange->fNum = fGroupCount+2; + addValToSets(rlRange->fIncludesSets, rlRange->fNum); + } + } + } + + // Move the character category numbers for any dictionary ranges up, so that they + // immediately follow the non-dictionary ranges. + + fDictCategoriesStart = fGroupCount + 3; + for (rlRange = fRangeList; rlRange!=nullptr; rlRange=rlRange->fNext) { + if (rlRange->fIncludesDict) { + rlRange->fNum += fDictCategoriesStart - 1; + if (rlRange->fFirstInGroup) { + addValToSets(rlRange->fIncludesSets, rlRange->fNum); + } } } + fGroupCount += dictGroupCount; + // Handle input sets that contain the special string {eof}. // Column 1 of the state table is reserved for EOF on input. @@ -220,13 +245,11 @@ void RBBISetBuilder::buildRanges() { // references to {bof}.) // Add this column value (1 or 2) to the equivalent expression // subtree for each UnicodeSet that contains the string {eof} - // Because {bof} and {eof} are not a characters in the normal sense, - // they doesn't affect the computation of ranges or TRIE. - static const UChar eofUString[] = {0x65, 0x6f, 0x66, 0}; - static const UChar bofUString[] = {0x62, 0x6f, 0x66, 0}; + // Because {bof} and {eof} are not characters in the normal sense, + // they don't affect the computation of the ranges or TRIE. - UnicodeString eofString(eofUString); - UnicodeString bofString(bofUString); + UnicodeString eofString(u"eof"); + UnicodeString bofString(u"bof"); for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni); if (usetNode==NULL) { @@ -253,19 +276,17 @@ void RBBISetBuilder::buildRanges() { // range group number. // void RBBISetBuilder::buildTrie() { - RangeDescriptor *rlRange; - - fTrie = utrie2_open(0, // Initial value for all code points. + fMutableTrie = umutablecptrie_open( + 0, // Initial value for all code points. 0, // Error value for out-of-range input. fStatus); - for (rlRange = fRangeList; rlRange!=0 && U_SUCCESS(*fStatus); rlRange=rlRange->fNext) { - utrie2_setRange32(fTrie, - rlRange->fStartChar, // Range start - rlRange->fEndChar, // Range end (inclusive) - rlRange->fNum, // value for range - TRUE, // Overwrite previously written values - fStatus); + for (RangeDescriptor *range = fRangeList; range!=nullptr && U_SUCCESS(*fStatus); range=range->fNext) { + umutablecptrie_setRange(fMutableTrie, + range->fStartChar, // Range start + range->fEndChar, // Range end (inclusive) + range->fNum, // value for range + fStatus); } } @@ -273,16 +294,21 @@ void RBBISetBuilder::buildTrie() { void RBBISetBuilder::mergeCategories(IntPair categories) { U_ASSERT(categories.first >= 1); U_ASSERT(categories.second > categories.first); + U_ASSERT((categories.first < fDictCategoriesStart && categories.second < fDictCategoriesStart) || + (categories.first >= fDictCategoriesStart && categories.second >= fDictCategoriesStart)); + for (RangeDescriptor *rd = fRangeList; rd != nullptr; rd = rd->fNext) { - int32_t rangeNum = rd->fNum & ~DICT_BIT; - int32_t rangeDict = rd->fNum & DICT_BIT; + int32_t rangeNum = rd->fNum; if (rangeNum == categories.second) { - rd->fNum = categories.first | rangeDict; + rd->fNum = categories.first; } else if (rangeNum > categories.second) { rd->fNum--; } } --fGroupCount; + if (categories.second <= fDictCategoriesStart) { + --fDictCategoriesStart; + } } @@ -295,15 +321,18 @@ int32_t RBBISetBuilder::getTrieSize() { if (U_FAILURE(*fStatus)) { return 0; } - utrie2_freeze(fTrie, UTRIE2_16_VALUE_BITS, fStatus); - fTrieSize = utrie2_serialize(fTrie, - NULL, // Buffer - 0, // Capacity - fStatus); - if (*fStatus == U_BUFFER_OVERFLOW_ERROR) { - *fStatus = U_ZERO_ERROR; + if (fTrie == nullptr) { + bool use8Bits = getNumCharCategories() <= kMaxCharCategoriesFor8BitsTrie; + fTrie = umutablecptrie_buildImmutable( + fMutableTrie, + UCPTRIE_TYPE_FAST, + use8Bits ? UCPTRIE_VALUE_BITS_8 : UCPTRIE_VALUE_BITS_16, + fStatus); + fTrieSize = ucptrie_toBinary(fTrie, nullptr, 0, fStatus); + if (*fStatus == U_BUFFER_OVERFLOW_ERROR) { + *fStatus = U_ZERO_ERROR; + } } - // RBBIDebugPrintf("Trie table size is %d\n", trieSize); return fTrieSize; } @@ -316,9 +345,9 @@ int32_t RBBISetBuilder::getTrieSize() { // //----------------------------------------------------------------------------------- void RBBISetBuilder::serializeTrie(uint8_t *where) { - utrie2_serialize(fTrie, - where, // Buffer - fTrieSize, // Capacity + ucptrie_toBinary(fTrie, + where, // Buffer + fTrieSize, // Capacity fStatus); } @@ -384,6 +413,16 @@ int32_t RBBISetBuilder::getNumCharCategories() const { } +//------------------------------------------------------------------------ +// +// getDictCategoriesStart +// +//------------------------------------------------------------------------ +int32_t RBBISetBuilder::getDictCategoriesStart() const { + return fDictCategoriesStart; +} + + //------------------------------------------------------------------------ // // sawBOF @@ -403,7 +442,7 @@ UBool RBBISetBuilder::sawBOF() const { UChar32 RBBISetBuilder::getFirstChar(int32_t category) const { RangeDescriptor *rlRange; UChar32 retVal = (UChar32)-1; - for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) { + for (rlRange = fRangeList; rlRange!=nullptr; rlRange=rlRange->fNext) { if (rlRange->fNum == category) { retVal = rlRange->fStartChar; break; @@ -413,7 +452,6 @@ UChar32 RBBISetBuilder::getFirstChar(int32_t category) const { } - //------------------------------------------------------------------------ // // printRanges A debugging function. @@ -426,16 +464,16 @@ void RBBISetBuilder::printRanges() { int i; RBBIDebugPrintf("\n\n Nonoverlapping Ranges ...\n"); - for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) { - RBBIDebugPrintf("%2i %4x-%4x ", rlRange->fNum, rlRange->fStartChar, rlRange->fEndChar); + for (rlRange = fRangeList; rlRange!=nullptr; rlRange=rlRange->fNext) { + RBBIDebugPrintf("%4x-%4x ", rlRange->fStartChar, rlRange->fEndChar); for (i=0; ifIncludesSets->size(); i++) { RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i); - UnicodeString setName = UNICODE_STRING("anon", 4); + UnicodeString setName {u"anon"}; RBBINode *setRef = usetNode->fParent; - if (setRef != NULL) { + if (setRef != nullptr) { RBBINode *varRef = setRef->fParent; - if (varRef != NULL && varRef->fType == RBBINode::varRef) { + if (varRef != nullptr && varRef->fType == RBBINode::varRef) { setName = varRef->fText; } } @@ -455,19 +493,15 @@ void RBBISetBuilder::printRanges() { //------------------------------------------------------------------------ #ifdef RBBI_DEBUG void RBBISetBuilder::printRangeGroups() { - RangeDescriptor *rlRange; - RangeDescriptor *tRange; int i; - int lastPrintedGroupNum = 0; RBBIDebugPrintf("\nRanges grouped by Unicode Set Membership...\n"); - for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) { - int groupNum = rlRange->fNum & 0xbfff; - if (groupNum > lastPrintedGroupNum) { - lastPrintedGroupNum = groupNum; + for (RangeDescriptor *rlRange = fRangeList; rlRange!=nullptr; rlRange=rlRange->fNext) { + if (rlRange->fFirstInGroup) { + int groupNum = rlRange->fNum; RBBIDebugPrintf("%2i ", groupNum); - if (rlRange->fNum & DICT_BIT) { RBBIDebugPrintf(" ");} + if (groupNum >= fDictCategoriesStart) { RBBIDebugPrintf(" ");} for (i=0; ifIncludesSets->size(); i++) { RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i); @@ -483,7 +517,7 @@ void RBBISetBuilder::printRangeGroups() { } i = 0; - for (tRange = rlRange; tRange != 0; tRange = tRange->fNext) { + for (RangeDescriptor *tRange = rlRange; tRange != nullptr; tRange = tRange->fNext) { if (tRange->fNum == rlRange->fNum) { if (i++ % 5 == 0) { RBBIDebugPrintf("\n "); @@ -550,28 +584,22 @@ void RBBISetBuilder::printSets() { // //------------------------------------------------------------------------------------- -RangeDescriptor::RangeDescriptor(const RangeDescriptor &other, UErrorCode &status) { - int i; - - this->fStartChar = other.fStartChar; - this->fEndChar = other.fEndChar; - this->fNum = other.fNum; - this->fNext = NULL; - UErrorCode oldstatus = status; - this->fIncludesSets = new UVector(status); - if (U_FAILURE(oldstatus)) { - status = oldstatus; - } +RangeDescriptor::RangeDescriptor(const RangeDescriptor &other, UErrorCode &status) : + fStartChar(other.fStartChar), fEndChar {other.fEndChar}, fNum {other.fNum}, + fIncludesDict{other.fIncludesDict}, fFirstInGroup{other.fFirstInGroup} { + if (U_FAILURE(status)) { return; } - /* test for NULL */ - if (this->fIncludesSets == 0) { + fIncludesSets = new UVector(status); + if (this->fIncludesSets == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; + } + if (U_FAILURE(status)) { return; } - for (i=0; isize(); i++) { + for (int32_t i=0; isize(); i++) { this->fIncludesSets->addElement(other.fIncludesSets->elementAt(i), status); } } @@ -583,24 +611,13 @@ RangeDescriptor::RangeDescriptor(const RangeDescriptor &other, UErrorCode &statu // //------------------------------------------------------------------------------------- RangeDescriptor::RangeDescriptor(UErrorCode &status) { - this->fStartChar = 0; - this->fEndChar = 0; - this->fNum = 0; - this->fNext = NULL; - UErrorCode oldstatus = status; - this->fIncludesSets = new UVector(status); - if (U_FAILURE(oldstatus)) { - status = oldstatus; - } if (U_FAILURE(status)) { return; } - /* test for NULL */ - if(this->fIncludesSets == 0) { + fIncludesSets = new UVector(status); + if (fIncludesSets == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; - return; } - } @@ -611,7 +628,7 @@ RangeDescriptor::RangeDescriptor(UErrorCode &status) { //------------------------------------------------------------------------------------- RangeDescriptor::~RangeDescriptor() { delete fIncludesSets; - fIncludesSets = NULL; + fIncludesSets = nullptr; } //------------------------------------------------------------------------------------- @@ -622,7 +639,7 @@ RangeDescriptor::~RangeDescriptor() { void RangeDescriptor::split(UChar32 where, UErrorCode &status) { U_ASSERT(where>fStartChar && where<=fEndChar); RangeDescriptor *nr = new RangeDescriptor(*this, status); - if(nr == 0) { + if(nr == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return; } @@ -641,27 +658,22 @@ void RangeDescriptor::split(UChar32 where, UErrorCode &status) { //------------------------------------------------------------------------------------- // -// RangeDescriptor::setDictionaryFlag +// RangeDescriptor::isDictionaryRange // -// Character Category Numbers that include characters from -// the original Unicode Set named "dictionary" have bit 14 -// set to 1. The RBBI runtime engine uses this to trigger -// use of the word dictionary. +// Test whether this range includes characters from +// the original Unicode Set named "dictionary". // -// This function looks through the Unicode Sets that it -// (the range) includes, and sets the bit in fNum when -// "dictionary" is among them. +// This function looks through the Unicode Sets that +// the range includes, checking for one named "dictionary" // // TODO: a faster way would be to find the set node for // "dictionary" just once, rather than looking it // up by name every time. // //------------------------------------------------------------------------------------- -void RangeDescriptor::setDictionaryFlag() { - int i; - +bool RangeDescriptor::isDictionaryRange() { static const char16_t *dictionary = u"dictionary"; - for (i=0; isize(); i++) { + for (int32_t i=0; isize(); i++) { RBBINode *usetNode = (RBBINode *)fIncludesSets->elementAt(i); RBBINode *setRef = usetNode->fParent; if (setRef != nullptr) { @@ -669,16 +681,14 @@ void RangeDescriptor::setDictionaryFlag() { if (varRef && varRef->fType == RBBINode::varRef) { const UnicodeString *setName = &varRef->fText; if (setName->compare(dictionary, -1) == 0) { - fNum |= RBBISetBuilder::DICT_BIT; - break; + return true; } } } } + return false; } - - U_NAMESPACE_END #endif /* #if !UCONFIG_NO_BREAK_ITERATION */ diff --git a/deps/icu-small/source/common/rbbisetb.h b/deps/icu-small/source/common/rbbisetb.h index ed6a76b1214621..6409a4ea579832 100644 --- a/deps/icu-small/source/common/rbbisetb.h +++ b/deps/icu-small/source/common/rbbisetb.h @@ -16,9 +16,10 @@ #if !UCONFIG_NO_BREAK_ITERATION +#include "unicode/ucptrie.h" +#include "unicode/umutablecptrie.h" #include "unicode/uobject.h" #include "rbbirb.h" -#include "utrie2.h" #include "uvector.h" U_NAMESPACE_BEGIN @@ -40,25 +41,26 @@ U_NAMESPACE_BEGIN // class RangeDescriptor : public UMemory { public: - UChar32 fStartChar; // Start of range, unicode 32 bit value. - UChar32 fEndChar; // End of range, unicode 32 bit value. - int32_t fNum; // runtime-mapped input value for this range. - UVector *fIncludesSets; // vector of the the original - // Unicode sets that include this range. - // (Contains ptrs to uset nodes) - RangeDescriptor *fNext; // Next RangeDescriptor in the linked list. + UChar32 fStartChar {}; // Start of range, unicode 32 bit value. + UChar32 fEndChar {}; // End of range, unicode 32 bit value. + int32_t fNum {0}; // runtime-mapped input value for this range. + bool fIncludesDict {false}; // True if the range includes $dictionary. + bool fFirstInGroup {false}; // True if first range in a group with the same fNum. + UVector *fIncludesSets {nullptr}; // vector of the the original + // Unicode sets that include this range. + // (Contains ptrs to uset nodes) + RangeDescriptor *fNext {nullptr}; // Next RangeDescriptor in the linked list. RangeDescriptor(UErrorCode &status); RangeDescriptor(const RangeDescriptor &other, UErrorCode &status); ~RangeDescriptor(); void split(UChar32 where, UErrorCode &status); // Spit this range in two at "where", with // where appearing in the second (higher) part. - void setDictionaryFlag(); // Check whether this range appears as part of + bool isDictionaryRange(); // Check whether this range appears as part of // the Unicode set named "dictionary" -private: - RangeDescriptor(const RangeDescriptor &other); // forbid copying of this class - RangeDescriptor &operator=(const RangeDescriptor &other); // forbid copying of this class + RangeDescriptor(const RangeDescriptor &other) = delete; // forbid default copying of this class + RangeDescriptor &operator=(const RangeDescriptor &other) = delete; // forbid assigning of this class }; @@ -89,6 +91,8 @@ class RBBISetBuilder : public UMemory { int32_t getNumCharCategories() const; // CharCategories are the same as input symbol set to the // runtime state machine, which are the same as // columns in the DFA state table + int32_t getDictCategoriesStart() const; // First char category that includes $dictionary, or + // last category + 1 if there are no dictionary categories. int32_t getTrieSize() /*const*/; // Size in bytes of the serialized Trie. void serializeTrie(uint8_t *where); // write out the serialized Trie. UChar32 getFirstChar(int32_t val) const; @@ -101,8 +105,6 @@ class RBBISetBuilder : public UMemory { */ void mergeCategories(IntPair categories); - static constexpr int32_t DICT_BIT = 0x4000; - #ifdef RBBI_DEBUG void printSets(); void printRanges(); @@ -114,24 +116,22 @@ class RBBISetBuilder : public UMemory { #endif private: - void numberSets(); - RBBIRuleBuilder *fRB; // The RBBI Rule Compiler that owns us. UErrorCode *fStatus; RangeDescriptor *fRangeList; // Head of the linked list of RangeDescriptors - UTrie2 *fTrie; // The mapping TRIE that is the end result of processing - uint32_t fTrieSize; // the Unicode Sets. + UMutableCPTrie *fMutableTrie; // The mapping TRIE that is the end result of processing + UCPTrie *fTrie; // the Unicode Sets. + uint32_t fTrieSize; - // Groups correspond to character categories - - // groups of ranges that are in the same original UnicodeSets. - // fGroupCount is the index of the last used group. - // fGroupCount+1 is also the number of columns in the RBBI state table being compiled. - // State table column 0 is not used. Column 1 is for end-of-input. - // column 2 is for group 0. Funny counting. + // Number of range groups, which are groups of ranges that are in the same original UnicodeSets. int32_t fGroupCount; + // The number of the first dictionary char category. + // If there are no Dictionary categories, set to the last category + 1. + int32_t fDictCategoriesStart; + UBool fSawBOF; RBBISetBuilder(const RBBISetBuilder &other); // forbid copying of this class diff --git a/deps/icu-small/source/common/rbbitblb.cpp b/deps/icu-small/source/common/rbbitblb.cpp index 3b1edc6a15c700..65b597c4a936b0 100644 --- a/deps/icu-small/source/common/rbbitblb.cpp +++ b/deps/icu-small/source/common/rbbitblb.cpp @@ -28,6 +28,8 @@ U_NAMESPACE_BEGIN +const int32_t kMaxStateFor8BitsTable = 255; + RBBITableBuilder::RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode, UErrorCode &status) : fRB(rb), fTree(*rootNode), @@ -712,7 +714,6 @@ void RBBITableBuilder::mapLookAheadRules() { return; } fLookAheadRuleMap->setSize(fRB->fScanner->numRules() + 1); - int32_t laSlotsInUse = 0; for (int32_t n=0; nsize(); n++) { RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n); @@ -749,7 +750,7 @@ void RBBITableBuilder::mapLookAheadRules() { } if (laSlotForState == 0) { - laSlotForState = ++laSlotsInUse; + laSlotForState = ++fLASlotsInUse; } // For each look ahead node covered by this state, @@ -805,23 +806,23 @@ void RBBITableBuilder::flagAcceptingStates() { if (sd->fPositions->indexOf(endMarker) >= 0) { // Any non-zero value for fAccepting means this is an accepting node. // The value is what will be returned to the user as the break status. - // If no other value was specified, force it to -1. + // If no other value was specified, force it to ACCEPTING_UNCONDITIONAL (1). if (sd->fAccepting==0) { // State hasn't been marked as accepting yet. Do it now. sd->fAccepting = fLookAheadRuleMap->elementAti(endMarker->fVal); if (sd->fAccepting == 0) { - sd->fAccepting = -1; + sd->fAccepting = ACCEPTING_UNCONDITIONAL; } } - if (sd->fAccepting==-1 && endMarker->fVal != 0) { + if (sd->fAccepting==ACCEPTING_UNCONDITIONAL && endMarker->fVal != 0) { // Both lookahead and non-lookahead accepting for this state. // Favor the look-ahead, because a look-ahead match needs to // immediately stop the run-time engine. First match, not longest. sd->fAccepting = fLookAheadRuleMap->elementAti(endMarker->fVal); } // implicit else: - // if sd->fAccepting already had a value other than 0 or -1, leave it be. + // if sd->fAccepting already had a value other than 0 or 1, leave it be. } } } @@ -855,7 +856,7 @@ void RBBITableBuilder::flagLookAheadStates() { int32_t positionsIdx = sd->fPositions->indexOf(lookAheadNode); if (positionsIdx >= 0) { U_ASSERT(lookAheadNode == sd->fPositions->elementAt(positionsIdx)); - int32_t lookaheadSlot = fLookAheadRuleMap->elementAti(lookAheadNode->fVal); + uint32_t lookaheadSlot = fLookAheadRuleMap->elementAti(lookAheadNode->fVal); U_ASSERT(sd->fLookAhead == 0 || sd->fLookAhead == lookaheadSlot); // if (sd->fLookAhead != 0 && sd->fLookAhead != lookaheadSlot) { // printf("%s:%d Bingo. sd->fLookAhead:%d lookaheadSlot:%d\n", @@ -1148,7 +1149,13 @@ bool RBBITableBuilder::findDuplCharClassFrom(IntPair *categories) { int32_t numCols = fRB->fSetBuilder->getNumCharCategories(); for (; categories->first < numCols-1; categories->first++) { - for (categories->second=categories->first+1; categories->second < numCols; categories->second++) { + // Note: dictionary & non-dictionary columns cannot be merged. + // The limitSecond value prevents considering mixed pairs. + // Dictionary categories are >= DictCategoriesStart. + // Non dict categories are < DictCategoriesStart. + int limitSecond = categories->first < fRB->fSetBuilder->getDictCategoriesStart() ? + fRB->fSetBuilder->getDictCategoriesStart() : numCols; + for (categories->second=categories->first+1; categories->second < limitSecond; categories->second++) { // Initialized to different values to prevent returning true if numStates = 0 (implies no duplicates). uint16_t table_base = 0; uint16_t table_dupl = 1; @@ -1335,11 +1342,18 @@ int32_t RBBITableBuilder::getTableSize() const { numRows = fDStates->size(); numCols = fRB->fSetBuilder->getNumCharCategories(); - rowSize = offsetof(RBBIStateTableRow, fNextState) + sizeof(uint16_t)*numCols; + if (use8BitsForTable()) { + rowSize = offsetof(RBBIStateTableRow8, fNextState) + sizeof(int8_t)*numCols; + } else { + rowSize = offsetof(RBBIStateTableRow16, fNextState) + sizeof(int16_t)*numCols; + } size += numRows * rowSize; return size; } +bool RBBITableBuilder::use8BitsForTable() const { + return fDStates->size() <= kMaxStateFor8BitsTable; +} //----------------------------------------------------------------------------- // @@ -1364,27 +1378,47 @@ void RBBITableBuilder::exportTable(void *where) { return; } - table->fRowLen = offsetof(RBBIStateTableRow, fNextState) + sizeof(uint16_t) * catCount; table->fNumStates = fDStates->size(); + table->fDictCategoriesStart = fRB->fSetBuilder->getDictCategoriesStart(); + table->fLookAheadResultsSize = fLASlotsInUse == ACCEPTING_UNCONDITIONAL ? 0 : fLASlotsInUse + 1; table->fFlags = 0; + if (use8BitsForTable()) { + table->fRowLen = offsetof(RBBIStateTableRow8, fNextState) + sizeof(uint8_t) * catCount; + table->fFlags |= RBBI_8BITS_ROWS; + } else { + table->fRowLen = offsetof(RBBIStateTableRow16, fNextState) + sizeof(int16_t) * catCount; + } if (fRB->fLookAheadHardBreak) { table->fFlags |= RBBI_LOOKAHEAD_HARD_BREAK; } if (fRB->fSetBuilder->sawBOF()) { table->fFlags |= RBBI_BOF_REQUIRED; } - table->fReserved = 0; for (state=0; statefNumStates; state++) { RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state); RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen); - U_ASSERT (-32768 < sd->fAccepting && sd->fAccepting <= 32767); - U_ASSERT (-32768 < sd->fLookAhead && sd->fLookAhead <= 32767); - row->fAccepting = (int16_t)sd->fAccepting; - row->fLookAhead = (int16_t)sd->fLookAhead; - row->fTagIdx = (int16_t)sd->fTagsIdx; - for (col=0; colfNextState[col] = (uint16_t)sd->fDtran->elementAti(col); + if (use8BitsForTable()) { + U_ASSERT (sd->fAccepting <= 255); + U_ASSERT (sd->fLookAhead <= 255); + U_ASSERT (0 <= sd->fTagsIdx && sd->fTagsIdx <= 255); + row->r8.fAccepting = sd->fAccepting; + row->r8.fLookAhead = sd->fLookAhead; + row->r8.fTagsIdx = sd->fTagsIdx; + for (col=0; colfDtran->elementAti(col) <= kMaxStateFor8BitsTable); + row->r8.fNextState[col] = sd->fDtran->elementAti(col); + } + } else { + U_ASSERT (sd->fAccepting <= 0xffff); + U_ASSERT (sd->fLookAhead <= 0xffff); + U_ASSERT (0 <= sd->fTagsIdx && sd->fTagsIdx <= 0xffff); + row->r16.fAccepting = sd->fAccepting; + row->r16.fLookAhead = sd->fLookAhead; + row->r16.fTagsIdx = sd->fTagsIdx; + for (col=0; colr16.fNextState[col] = sd->fDtran->elementAti(col); + } } } } @@ -1520,11 +1554,18 @@ int32_t RBBITableBuilder::getSafeTableSize() const { numRows = fSafeTable->size(); numCols = fRB->fSetBuilder->getNumCharCategories(); - rowSize = offsetof(RBBIStateTableRow, fNextState) + sizeof(uint16_t)*numCols; + if (use8BitsForSafeTable()) { + rowSize = offsetof(RBBIStateTableRow8, fNextState) + sizeof(int8_t)*numCols; + } else { + rowSize = offsetof(RBBIStateTableRow16, fNextState) + sizeof(int16_t)*numCols; + } size += numRows * rowSize; return size; } +bool RBBITableBuilder::use8BitsForSafeTable() const { + return fSafeTable->size() <= kMaxStateFor8BitsTable; +} //----------------------------------------------------------------------------- // @@ -1549,20 +1590,33 @@ void RBBITableBuilder::exportSafeTable(void *where) { return; } - table->fRowLen = offsetof(RBBIStateTableRow, fNextState) + sizeof(uint16_t) * catCount; table->fNumStates = fSafeTable->size(); table->fFlags = 0; - table->fReserved = 0; + if (use8BitsForSafeTable()) { + table->fRowLen = offsetof(RBBIStateTableRow8, fNextState) + sizeof(uint8_t) * catCount; + table->fFlags |= RBBI_8BITS_ROWS; + } else { + table->fRowLen = offsetof(RBBIStateTableRow16, fNextState) + sizeof(int16_t) * catCount; + } for (state=0; statefNumStates; state++) { UnicodeString *rowString = (UnicodeString *)fSafeTable->elementAt(state); RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen); - row->fAccepting = 0; - row->fLookAhead = 0; - row->fTagIdx = 0; - row->fReserved = 0; - for (col=0; colfNextState[col] = rowString->charAt(col); + if (use8BitsForSafeTable()) { + row->r8.fAccepting = 0; + row->r8.fLookAhead = 0; + row->r8.fTagsIdx = 0; + for (col=0; colcharAt(col) <= kMaxStateFor8BitsTable); + row->r8.fNextState[col] = static_cast(rowString->charAt(col)); + } + } else { + row->r16.fAccepting = 0; + row->r16.fLookAhead = 0; + row->r16.fTagsIdx = 0; + for (col=0; colr16.fNextState[col] = rowString->charAt(col); + } } } } @@ -1600,12 +1654,12 @@ void RBBITableBuilder::printStates() { RBBIDebugPrintf("state | i n p u t s y m b o l s \n"); RBBIDebugPrintf(" | Acc LA Tag"); for (c=0; cfSetBuilder->getNumCharCategories(); c++) { - RBBIDebugPrintf(" %2d", c); + RBBIDebugPrintf(" %3d", c); } RBBIDebugPrintf("\n"); RBBIDebugPrintf(" |---------------"); for (c=0; cfSetBuilder->getNumCharCategories(); c++) { - RBBIDebugPrintf("---"); + RBBIDebugPrintf("----"); } RBBIDebugPrintf("\n"); @@ -1614,7 +1668,7 @@ void RBBITableBuilder::printStates() { RBBIDebugPrintf(" %3d | " , n); RBBIDebugPrintf("%3d %3d %5d ", sd->fAccepting, sd->fLookAhead, sd->fTagsIdx); for (c=0; cfSetBuilder->getNumCharCategories(); c++) { - RBBIDebugPrintf(" %2d", sd->fDtran->elementAti(c)); + RBBIDebugPrintf(" %3d", sd->fDtran->elementAti(c)); } RBBIDebugPrintf("\n"); } diff --git a/deps/icu-small/source/common/rbbitblb.h b/deps/icu-small/source/common/rbbitblb.h index c2b574fe1b8f93..fe3db8d7bf1ae8 100644 --- a/deps/icu-small/source/common/rbbitblb.h +++ b/deps/icu-small/source/common/rbbitblb.h @@ -20,6 +20,7 @@ #include "unicode/uobject.h" #include "unicode/rbbi.h" +#include "rbbidata.h" #include "rbbirb.h" #include "rbbinode.h" @@ -53,6 +54,9 @@ class RBBITableBuilder : public UMemory { */ void exportTable(void *where); + /** Use 8 bits to encode the forward table */ + bool use8BitsForTable() const; + /** * Find duplicate (redundant) character classes. Begin looking with categories.first. * Duplicate, if found are returned in the categories parameter. @@ -85,6 +89,8 @@ class RBBITableBuilder : public UMemory { */ void exportSafeTable(void *where); + /** Use 8 bits to encode the safe reverse table */ + bool use8BitsForSafeTable() const; private: void calcNullable(RBBINode *n); @@ -179,9 +185,15 @@ class RBBITableBuilder : public UMemory { /** Map from rule number (fVal in look ahead nodes) to sequential lookahead index. */ UVector32 *fLookAheadRuleMap = nullptr; + /* Counter used when assigning lookahead rule numbers. + * Contains the last look-ahead number already in use. + * The first look-ahead number is 2; Number 1 (ACCEPTING_UNCONDITIONAL) is reserved + * for non-lookahead accepting states. See the declarations of RBBIStateTableRowT. */ + int32_t fLASlotsInUse = ACCEPTING_UNCONDITIONAL; + - RBBITableBuilder(const RBBITableBuilder &other); // forbid copying of this class - RBBITableBuilder &operator=(const RBBITableBuilder &other); // forbid copying of this class + RBBITableBuilder(const RBBITableBuilder &other) = delete; // forbid copying of this class + RBBITableBuilder &operator=(const RBBITableBuilder &other) = delete; // forbid copying of this class }; // @@ -190,8 +202,8 @@ class RBBITableBuilder : public UMemory { class RBBIStateDescriptor : public UMemory { public: UBool fMarked; - int32_t fAccepting; - int32_t fLookAhead; + uint32_t fAccepting; + uint32_t fLookAhead; UVector *fTagVals; int32_t fTagsIdx; UVector *fPositions; // Set of parse tree positions associated diff --git a/deps/icu-small/source/common/resource.h b/deps/icu-small/source/common/resource.h index 5199b858880770..3795694412a058 100644 --- a/deps/icu-small/source/common/resource.h +++ b/deps/icu-small/source/common/resource.h @@ -60,7 +60,7 @@ class U_COMMON_API ResourceArray { /** * @param i Array item index. * @param value Output-only, receives the value of the i'th item. - * @return TRUE if i is non-negative and less than getSize(). + * @return true if i is non-negative and less than getSize(). */ UBool getValue(int32_t i, ResourceValue &value) const; @@ -97,14 +97,14 @@ class U_COMMON_API ResourceTable { * @param i Table item index. * @param key Output-only, receives the key of the i'th item. * @param value Output-only, receives the value of the i'th item. - * @return TRUE if i is non-negative and less than getSize(). + * @return true if i is non-negative and less than getSize(). */ UBool getKeyAndValue(int32_t i, const char *&key, ResourceValue &value) const; /** * @param key Key string to find in the table. * @param value Output-only, receives the value of the item with that key. - * @return TRUE if the table contains the key. + * @return true if the table contains the key. */ UBool findValue(const char *key, ResourceValue &value) const; @@ -141,7 +141,7 @@ class U_COMMON_API ResourceValue : public UObject { inline UnicodeString getUnicodeString(UErrorCode &errorCode) const { int32_t len = 0; const UChar *r = getString(len, errorCode); - return UnicodeString(TRUE, r, len); + return UnicodeString(true, r, len); } /** @@ -152,7 +152,7 @@ class U_COMMON_API ResourceValue : public UObject { inline UnicodeString getAliasUnicodeString(UErrorCode &errorCode) const { int32_t len = 0; const UChar *r = getAliasString(len, errorCode); - return UnicodeString(TRUE, r, len); + return UnicodeString(true, r, len); } /** @@ -199,7 +199,7 @@ class U_COMMON_API ResourceValue : public UObject { * CLDR no-fallback data values of (three empty-set symbols)=={2205, 2205, 2205} * when enumerating tables with fallback from the specific resource bundle to root. * - * @return TRUE if this is a no-inheritance marker string + * @return true if this is a no-inheritance marker string */ virtual UBool isNoInheritanceMarker() const = 0; diff --git a/deps/icu-small/source/common/ruleiter.h b/deps/icu-small/source/common/ruleiter.h index b6edc657aff261..f397f8bccd7817 100644 --- a/deps/icu-small/source/common/ruleiter.h +++ b/deps/icu-small/source/common/ruleiter.h @@ -114,7 +114,7 @@ class RuleCharacterIterator : public UMemory { * character. * @param options one or more of the following options, bitwise-OR-ed * together: PARSE_VARIABLES, PARSE_ESCAPES, SKIP_WHITESPACE. - * @param isEscaped output parameter set to TRUE if the character + * @param isEscaped output parameter set to true if the character * was escaped * @param ec input-output error code. An error will only be set by * this routing if options includes PARSE_VARIABLES and an unknown diff --git a/deps/icu-small/source/common/serv.h b/deps/icu-small/source/common/serv.h index 70695839a8f3ce..6a3d1915afdf5a 100644 --- a/deps/icu-small/source/common/serv.h +++ b/deps/icu-small/source/common/serv.h @@ -138,16 +138,16 @@ class U_COMMON_API ICUServiceKey : public UObject { * must eventually return false. This implementation has no fallbacks * and always returns false.

* - * @return TRUE if the ICUServiceKey changed to a valid fallback value. + * @return true if the ICUServiceKey changed to a valid fallback value. */ virtual UBool fallback(); /** - *

Return TRUE if a key created from id matches, or would eventually + *

Return true if a key created from id matches, or would eventually * fallback to match, the canonical ID of this ICUServiceKey.

* * @param id the id to test. - * @return TRUE if this ICUServiceKey's canonical ID is a fallback of id. + * @return true if this ICUServiceKey's canonical ID is a fallback of id. */ virtual UBool isFallbackOf(const UnicodeString& id) const; @@ -291,15 +291,15 @@ class U_COMMON_API SimpleFactory : public ICUServiceFactory { public: /** *

Construct a SimpleFactory that maps a single ID to a single - * service instance. If visible is TRUE, the ID will be visible. + * service instance. If visible is true, the ID will be visible. * The instance must not be NULL. The SimpleFactory will adopt * the instance, which must not be changed subsequent to this call.

* * @param instanceToAdopt the service instance to adopt. * @param id the ID to assign to this service instance. - * @param visible if TRUE, the ID will be visible. + * @param visible if true, the ID will be visible. */ - SimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible = TRUE); + SimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible = true); /** *

Destructor.

@@ -318,7 +318,7 @@ class U_COMMON_API SimpleFactory : public ICUServiceFactory { virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const; /** - *

This implementation adds a mapping from ID -> this to result if visible is TRUE, + *

This implementation adds a mapping from ID -> this to result if visible is true, * otherwise it removes ID from result.

* * @param result the mapping table to update. @@ -327,7 +327,7 @@ class U_COMMON_API SimpleFactory : public ICUServiceFactory { virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const; /** - *

This implementation returns the factory ID if it equals id and visible is TRUE, + *

This implementation returns the factory ID if it equals id and visible is true, * otherwise it returns the empty string. (This implementation provides * no localized id information.)

* @@ -427,8 +427,8 @@ class U_COMMON_API StringPair : public UMemory { UErrorCode& status); /** - *

Return TRUE if either string of the pair is bogus.

- * @return TRUE if either string of the pair is bogus. + *

Return true if either string of the pair is bogus.

+ * @return true if either string of the pair is bogus. */ UBool isBogus() const; @@ -761,7 +761,7 @@ class U_COMMON_API ICUService : public ICUNotifier { /** *

A convenience override of registerInstance(UObject*, const UnicodeString&, UBool) - * that defaults visible to TRUE.

+ * that defaults visible to true.

* * @param objToAdopt the object to register and adopt. * @param id the ID to assign to this object. @@ -774,7 +774,7 @@ class U_COMMON_API ICUService : public ICUNotifier { /** *

Register a service instance with the provided ID. The ID will be * canonicalized. The canonicalized ID will be returned by - * getVisibleIDs if visible is TRUE. The service instance will be adopted and + * getVisibleIDs if visible is true. The service instance will be adopted and * must not be modified subsequent to this call.

* *

This issues a serviceChanged notification to registered listeners.

@@ -784,7 +784,7 @@ class U_COMMON_API ICUService : public ICUNotifier { * * @param objToAdopt the object to register and adopt. * @param id the ID to assign to this object. - * @param visible TRUE if getVisibleIDs is to return this ID. + * @param visible true if getVisibleIDs is to return this ID. * @param status the error code status. * @return a registry key that can be passed to unregister() to unregister * (and discard) this instance. @@ -820,7 +820,7 @@ class U_COMMON_API ICUService : public ICUNotifier { * * @param rkey the registry key. * @param status the error code status. - * @return TRUE if the call successfully unregistered the factory. + * @return true if the call successfully unregistered the factory. */ virtual UBool unregister(URegistryKey rkey, UErrorCode& status); @@ -833,9 +833,9 @@ class U_COMMON_API ICUService : public ICUNotifier { virtual void reset(void); /** - *

Return TRUE if the service is in its default state.

+ *

Return true if the service is in its default state.

* - *

The default implementation returns TRUE if there are no + *

The default implementation returns true if there are no * factories registered.

*/ virtual UBool isDefault(void) const; @@ -877,7 +877,7 @@ class U_COMMON_API ICUService : public ICUNotifier { * * @param instanceToAdopt the service instance to adopt. * @param id the ID to assign to this service instance. - * @param visible if TRUE, the ID will be visible. + * @param visible if true, the ID will be visible. * @param status the error code status. * @return an instance of ICUServiceFactory that maps this instance to the provided ID. */ @@ -885,7 +885,7 @@ class U_COMMON_API ICUService : public ICUNotifier { /** *

Reinitialize the factory list to its default state. After this call, isDefault() - * must return TRUE.

+ * must return true.

* *

This issues a serviceChanged notification to registered listeners.

* @@ -928,7 +928,7 @@ class U_COMMON_API ICUService : public ICUNotifier { * different listeners.

* * @param l the listener to test. - * @return TRUE if the service accepts the listener. + * @return true if the service accepts the listener. */ virtual UBool acceptsListener(const EventListener& l) const; diff --git a/deps/icu-small/source/common/servnotf.h b/deps/icu-small/source/common/servnotf.h index cf92fc169e927f..7918a672473b10 100644 --- a/deps/icu-small/source/common/servnotf.h +++ b/deps/icu-small/source/common/servnotf.h @@ -105,7 +105,7 @@ private: UVector* listeners; protected: /** - * Subclasses implement this to return TRUE if the listener is + * Subclasses implement this to return true if the listener is * of the appropriate type. */ virtual UBool acceptsListener(const EventListener& l) const = 0; diff --git a/deps/icu-small/source/common/sharedobject.h b/deps/icu-small/source/common/sharedobject.h index 878594c7ffa772..0565de6608a094 100644 --- a/deps/icu-small/source/common/sharedobject.h +++ b/deps/icu-small/source/common/sharedobject.h @@ -90,13 +90,13 @@ class U_COMMON_API SharedObject : public UObject { int32_t getRefCount() const; /** - * If noHardReferences() == TRUE then this object has no hard references. + * If noHardReferences() == true then this object has no hard references. * Must be called only from within the internals of UnifiedCache. */ inline UBool noHardReferences() const { return getRefCount() == 0; } /** - * If hasHardReferences() == TRUE then this object has hard references. + * If hasHardReferences() == true then this object has hard references. * Must be called only from within the internals of UnifiedCache. */ inline UBool hasHardReferences() const { return getRefCount() != 0; } diff --git a/deps/icu-small/source/common/simpleformatter.cpp b/deps/icu-small/source/common/simpleformatter.cpp index 76d8f54efd4aea..f7f7aead6171bb 100644 --- a/deps/icu-small/source/common/simpleformatter.cpp +++ b/deps/icu-small/source/common/simpleformatter.cpp @@ -263,6 +263,8 @@ UnicodeString SimpleFormatter::getTextWithNoArguments( sb.append(compiledPattern + i, n); i += n; } else if (n < offsetsLength) { + // TODO(ICU-20406): This does not distinguish between "{0}{1}" and "{1}{0}". + // Consider removing this function and replacing it with an iterator interface. offsets[n] = sb.length(); } } diff --git a/deps/icu-small/source/common/uassert.h b/deps/icu-small/source/common/uassert.h index 15cd55c873487c..afd31eeffd91a4 100644 --- a/deps/icu-small/source/common/uassert.h +++ b/deps/icu-small/source/common/uassert.h @@ -32,7 +32,7 @@ # include # define U_ASSERT(exp) assert(exp) #elif U_CPLUSPLUS_VERSION -# define U_ASSERT(exp) void() +# define U_ASSERT(exp) (void)0 #else # define U_ASSERT(exp) #endif diff --git a/deps/icu-small/source/common/ubidi_props.cpp b/deps/icu-small/source/common/ubidi_props.cpp index 4141c21938a740..afcc4aaf4f99d7 100644 --- a/deps/icu-small/source/common/ubidi_props.cpp +++ b/deps/icu-small/source/common/ubidi_props.cpp @@ -248,7 +248,7 @@ u_charMirror(UChar32 c) { return ubidi_getMirror(c); } -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 u_getBidiPairedBracket(UChar32 c) { return ubidi_getPairedBracket(c); } diff --git a/deps/icu-small/source/common/ubidiimp.h b/deps/icu-small/source/common/ubidiimp.h index 9746b2bc103102..e48fc6f941621b 100644 --- a/deps/icu-small/source/common/ubidiimp.h +++ b/deps/icu-small/source/common/ubidiimp.h @@ -26,6 +26,14 @@ /* miscellaneous definitions ---------------------------------------------- */ +// ICU-20853=ICU-20935 Solaris #defines CS and ES in sys/regset.h +#ifdef CS +# undef CS +#endif +#ifdef ES +# undef ES +#endif + typedef uint8_t DirProp; typedef uint32_t Flags; @@ -451,26 +459,26 @@ ubidi_getMemory(BidiMemoryForAllocation *pMemory, int32_t *pSize, UBool mayAlloc /* additional macros used by ubidi_open() - always allow allocation */ #define getInitialDirPropsMemory(pBiDi, length) \ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \ - TRUE, (length)) + true, (length)) #define getInitialLevelsMemory(pBiDi, length) \ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \ - TRUE, (length)) + true, (length)) #define getInitialOpeningsMemory(pBiDi, length) \ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->openingsMemory, &(pBiDi)->openingsSize, \ - TRUE, (length)*sizeof(Opening)) + true, (length)*sizeof(Opening)) #define getInitialParasMemory(pBiDi, length) \ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->parasMemory, &(pBiDi)->parasSize, \ - TRUE, (length)*sizeof(Para)) + true, (length)*sizeof(Para)) #define getInitialRunsMemory(pBiDi, length) \ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \ - TRUE, (length)*sizeof(Run)) + true, (length)*sizeof(Run)) #define getInitialIsolatesMemory(pBiDi, length) \ ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->isolatesMemory, &(pBiDi)->isolatesSize, \ - TRUE, (length)*sizeof(Isolate)) + true, (length)*sizeof(Isolate)) #endif diff --git a/deps/icu-small/source/common/ubiditransform.cpp b/deps/icu-small/source/common/ubiditransform.cpp index bb3ce8cb934d43..ab3dcbe14c0cfe 100644 --- a/deps/icu-small/source/common/ubiditransform.cpp +++ b/deps/icu-small/source/common/ubiditransform.cpp @@ -89,7 +89,7 @@ struct UBiDiTransform { uint32_t letters; /* letter option for ArabicShaping */ }; -U_DRAFT UBiDiTransform* U_EXPORT2 +U_CAPI UBiDiTransform* U_EXPORT2 ubiditransform_open(UErrorCode *pErrorCode) { UBiDiTransform *pBiDiTransform = NULL; @@ -102,7 +102,7 @@ ubiditransform_open(UErrorCode *pErrorCode) return pBiDiTransform; } -U_DRAFT void U_EXPORT2 +U_CAPI void U_EXPORT2 ubiditransform_close(UBiDiTransform *pBiDiTransform) { if (pBiDiTransform != NULL) { @@ -434,7 +434,7 @@ findMatchingScheme(UBiDiLevel inLevel, UBiDiLevel outLevel, return NULL; } -U_DRAFT uint32_t U_EXPORT2 +U_CAPI uint32_t U_EXPORT2 ubiditransform_transform(UBiDiTransform *pBiDiTransform, const UChar *src, int32_t srcLength, UChar *dest, int32_t destSize, diff --git a/deps/icu-small/source/common/ucase.cpp b/deps/icu-small/source/common/ucase.cpp index 57a40327905c00..c2180629fb436a 100644 --- a/deps/icu-small/source/common/ucase.cpp +++ b/deps/icu-small/source/common/ucase.cpp @@ -707,6 +707,7 @@ ucase_isCaseSensitive(UChar32 c) { #define is_r(c) ((c)=='r' || (c)=='R') #define is_t(c) ((c)=='t' || (c)=='T') #define is_u(c) ((c)=='u' || (c)=='U') +#define is_y(c) ((c)=='y' || (c)=='Y') #define is_z(c) ((c)=='z' || (c)=='Z') /* separator? */ @@ -804,6 +805,18 @@ ucase_getCaseLocale(const char *locale) { return UCASE_LOC_DUTCH; } } + } else if(c=='h') { + /* hy or hye? *not* hyw */ + c=*locale++; + if(is_y(c)) { + c=*locale++; + if(is_e(c)) { + c=*locale; + } + if(is_sep(c)) { + return UCASE_LOC_ARMENIAN; + } + } } } else { // uppercase c @@ -868,6 +881,18 @@ ucase_getCaseLocale(const char *locale) { return UCASE_LOC_DUTCH; } } + } else if(c=='H') { + /* hy or hye? *not* hyw */ + c=*locale++; + if(is_y(c)) { + c=*locale++; + if(is_e(c)) { + c=*locale; + } + if(is_sep(c)) { + return UCASE_LOC_ARMENIAN; + } + } } } return UCASE_LOC_ROOT; @@ -1229,6 +1254,17 @@ toUpperOrTitle(UChar32 c, */ *pString=nullptr; return 0; /* remove the dot (continue without output) */ + } else if(c==0x0587) { + // See ICU-13416: + // և ligature ech-yiwn + // uppercases to ԵՒ=ech+yiwn by default and in Western Armenian, + // but to ԵՎ=ech+vew in Eastern Armenian. + if(loc==UCASE_LOC_ARMENIAN) { + *pString=upperNotTitle ? u"ԵՎ" : u"Եվ"; + } else { + *pString=upperNotTitle ? u"ԵՒ" : u"Եւ"; + } + return 2; } else { /* no known conditional special case mapping, use a normal mapping */ } diff --git a/deps/icu-small/source/common/ucase.h b/deps/icu-small/source/common/ucase.h index b0a453b87e8afa..a018f82b81b229 100644 --- a/deps/icu-small/source/common/ucase.h +++ b/deps/icu-small/source/common/ucase.h @@ -56,7 +56,8 @@ enum { UCASE_LOC_TURKISH, UCASE_LOC_LITHUANIAN, UCASE_LOC_GREEK, - UCASE_LOC_DUTCH + UCASE_LOC_DUTCH, + UCASE_LOC_ARMENIAN }; /** @@ -117,7 +118,7 @@ ucase_addCaseClosure(UChar32 c, const USetAdder *sa); * the string itself is added as well as part of its code points' closure. * It must be length>=0. * - * @return TRUE if the string was found + * @return true if the string was found */ U_CFUNC UBool U_EXPORT2 ucase_addStringCaseClosure(const UChar *s, int32_t length, const USetAdder *sa); diff --git a/deps/icu-small/source/common/ucase_props_data.h b/deps/icu-small/source/common/ucase_props_data.h index 7c97230957024a..aead6d58d1ec9c 100644 --- a/deps/icu-small/source/common/ucase_props_data.h +++ b/deps/icu-small/source/common/ucase_props_data.h @@ -13,7 +13,7 @@ static const UVersionInfo ucase_props_dataVersion={0xd,0,0,0}; -static const int32_t ucase_props_indexes[UCASE_IX_TOP]={0x10,0x70ca,0x6098,0x687,0x172,0,0,0,0,0,0,0,0,0,0,3}; +static const int32_t ucase_props_indexes[UCASE_IX_TOP]={0x10,0x70c2,0x6098,0x683,0x172,0,0,0,0,0,0,0,0,0,0,3}; static const uint16_t ucase_props_trieIndex[12356]={ 0x336,0x33e,0x346,0x34e,0x35c,0x364,0x36c,0x374,0x37c,0x384,0x38b,0x393,0x39b,0x3a3,0x3ab,0x3b3, @@ -411,18 +411,18 @@ static const uint16_t ucase_props_trieIndex[12356]={ 0,0,0,0,0,4,4,4,4,0,0,0,0,0,0,0, 0,0,0,0,0,0,4,0,0,4,4,0,0,0,0,0, 0,0x64,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,4,0,0,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a, -0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0x179a, -0x179a,0x179a,0x179a,0x179a,0x179a,0x179a,0,0x179a,0,0,0,0,0,0x179a,0,0, -0x17b9,0x17e9,0x1819,0x1849,0x1879,0x18a9,0x18d9,0x1909,0x1939,0x1969,0x1999,0x19c9,0x19f9,0x1a29,0x1a59,0x1a89, -0x1ab9,0x1ae9,0x1b19,0x1b49,0x1b79,0x1ba9,0x1bd9,0x1c09,0x1c39,0x1c69,0x1c99,0x1cc9,0x1cf9,0x1d29,0x1d59,0x1d89, -0x1db9,0x1de9,0x1e19,0x1e49,0x1e79,0x1ea9,0x1ed9,0x1f09,0x1f39,0x1f69,0x1f99,0,4,0x1fc9,0x1ff9,0x2029, +0,4,0,0,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a, +0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0x175a, +0x175a,0x175a,0x175a,0x175a,0x175a,0x175a,0,0x175a,0,0,0,0,0,0x175a,0,0, +0x1779,0x17a9,0x17d9,0x1809,0x1839,0x1869,0x1899,0x18c9,0x18f9,0x1929,0x1959,0x1989,0x19b9,0x19e9,0x1a19,0x1a49, +0x1a79,0x1aa9,0x1ad9,0x1b09,0x1b39,0x1b69,0x1b99,0x1bc9,0x1bf9,0x1c29,0x1c59,0x1c89,0x1cb9,0x1ce9,0x1d19,0x1d49, +0x1d79,0x1da9,0x1dd9,0x1e09,0x1e39,0x1e69,0x1e99,0x1ec9,0x1ef9,0x1f29,0x1f59,0,4,0x1f89,0x1fb9,0x1fe9, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0x44,0x44,0x44, -0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a, -0x207a,0x207a,0x207a,0x207a,0x207a,0x207a,0,0,0x2099,0x20c9,0x20f9,0x2129,0x2159,0x2189,0,0, -0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a, -0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a,0x205a, +0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a, +0x203a,0x203a,0x203a,0x203a,0x203a,0x203a,0,0,0x2059,0x2089,0x20b9,0x20e9,0x2119,0x2149,0,0, +0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a, +0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a,0x201a, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,4,4,0x64,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,4,4,0,4, @@ -458,9 +458,9 @@ static const uint16_t ucase_props_trieIndex[12356]={ 0,0,0,0,4,4,4,4,4,4,4,4,0,0,4,0x64, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,4,4,4,4,4,4,0,0, -0x21b9,0x21e9,0x2219,0x2249,0x2279,0x22c9,0x2319,0x2349,0x2379,0,0,0,0,0,0,0, -0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa, -0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0x23aa,0,0,0x23aa,0x23aa,0x23aa, +0x2179,0x21a9,0x21d9,0x2209,0x2239,0x2289,0x22d9,0x2309,0x2339,0,0,0,0,0,0,0, +0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a, +0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0x236a,0,0,0x236a,0x236a,0x236a, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0x44,0x44,0x44,0,0x64,0x64,0x64,0x64,0x64,0x64,0x44,0x44,0x64,0x64,0x64,0x64, 0x44,0,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0,0,0,0,0x64,0,0, @@ -470,10 +470,10 @@ static const uint16_t ucase_props_trieIndex[12356]={ 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 5,5,0x25,5,5,5,5,5,5,5,5,1,1,1,1,1, -1,1,1,1,1,1,1,1,5,0x23c9,1,1,1,0x23e9,1,1, +1,1,1,1,1,1,1,1,5,0x2389,1,1,1,0x23a9,1,1, 5,5,5,5,0x25,5,5,5,0x25,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,0x2409,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,0x23c9,1, 1,1,1,1,1,1,0x21,1,1,1,1,5,5,5,5,5, 0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44, 0x44,0x44,0x44,0x44,0x44,0x44,0x64,0x64,0x64,0x64,0,0x44,0x64,0x64,0x44,0x64, @@ -481,27 +481,27 @@ static const uint16_t ucase_props_trieIndex[12356]={ 0x64,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44, 0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xffb1,0x92,0xff91, 0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, -0x242a,0x2469,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, +0x23ea,0x2429,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, 0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, -0x92,0xff91,0x24a9,0x2529,0x25a9,0x2629,0x26a9,0x2729,1,1,0x275a,1,0x92,0xff91,0x92,0xff91, +0x92,0xff91,0x2469,0x24e9,0x2569,0x25e9,0x2669,0x26e9,1,1,0x271a,1,0x92,0xff91,0x92,0xff91, 0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xffb1,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, 0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x411,0x411,0x411,0x411, 0x411,0x411,0x411,0x411,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0x411,0x411,0x411,0x411, 0x411,0x411,0,0,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0,0,0x411,0x411,0x411,0x411, 0x411,0x411,0x411,0x411,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0x411,0x411,0x411,0x411, 0x411,0x411,0x411,0x411,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0x411,0x411,0x411,0x411, -0x411,0x411,0,0,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0,0,0x27a9,0x411,0x2829,0x411, -0x28d9,0x411,0x2989,0x411,0,0xfc12,0,0xfc12,0,0xfc12,0,0xfc12,0x411,0x411,0x411,0x411, +0x411,0x411,0,0,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0,0,0x2769,0x411,0x27e9,0x411, +0x2899,0x411,0x2949,0x411,0,0xfc12,0,0xfc12,0,0xfc12,0,0xfc12,0x411,0x411,0x411,0x411, 0x411,0x411,0x411,0x411,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0xfc12,0x2511,0x2511,0x2b11,0x2b11, -0x2b11,0x2b11,0x3211,0x3211,0x4011,0x4011,0x3811,0x3811,0x3f11,0x3f11,0,0,0x2a39,0x2aa9,0x2b19,0x2b89, -0x2bf9,0x2c69,0x2cd9,0x2d49,0x2dbb,0x2e2b,0x2e9b,0x2f0b,0x2f7b,0x2feb,0x305b,0x30cb,0x3139,0x31a9,0x3219,0x3289, -0x32f9,0x3369,0x33d9,0x3449,0x34bb,0x352b,0x359b,0x360b,0x367b,0x36eb,0x375b,0x37cb,0x3839,0x38a9,0x3919,0x3989, -0x39f9,0x3a69,0x3ad9,0x3b49,0x3bbb,0x3c2b,0x3c9b,0x3d0b,0x3d7b,0x3deb,0x3e5b,0x3ecb,0x411,0x411,0x3f39,0x3fb9, -0x4029,0,0x40a9,0x4129,0xfc12,0xfc12,0xdb12,0xdb12,0x41db,4,0x4249,4,4,4,0x4299,0x4319, -0x4389,0,0x4409,0x4489,0xd512,0xd512,0xd512,0xd512,0x453b,4,4,4,0x411,0x411,0x45a9,0x4659, -0,0,0x4729,0x47a9,0xfc12,0xfc12,0xce12,0xce12,0,4,4,4,0x411,0x411,0x4859,0x4909, -0x49d9,0x391,0x4a59,0x4ad9,0xfc12,0xfc12,0xc812,0xc812,0xfc92,4,4,4,0,0,0x4b89,0x4c09, -0x4c79,0,0x4cf9,0x4d79,0xc012,0xc012,0xc112,0xc112,0x4e2b,4,4,0,0,0,0,0, +0x2b11,0x2b11,0x3211,0x3211,0x4011,0x4011,0x3811,0x3811,0x3f11,0x3f11,0,0,0x29f9,0x2a69,0x2ad9,0x2b49, +0x2bb9,0x2c29,0x2c99,0x2d09,0x2d7b,0x2deb,0x2e5b,0x2ecb,0x2f3b,0x2fab,0x301b,0x308b,0x30f9,0x3169,0x31d9,0x3249, +0x32b9,0x3329,0x3399,0x3409,0x347b,0x34eb,0x355b,0x35cb,0x363b,0x36ab,0x371b,0x378b,0x37f9,0x3869,0x38d9,0x3949, +0x39b9,0x3a29,0x3a99,0x3b09,0x3b7b,0x3beb,0x3c5b,0x3ccb,0x3d3b,0x3dab,0x3e1b,0x3e8b,0x411,0x411,0x3ef9,0x3f79, +0x3fe9,0,0x4069,0x40e9,0xfc12,0xfc12,0xdb12,0xdb12,0x419b,4,0x4209,4,4,4,0x4259,0x42d9, +0x4349,0,0x43c9,0x4449,0xd512,0xd512,0xd512,0xd512,0x44fb,4,4,4,0x411,0x411,0x4569,0x4619, +0,0,0x46e9,0x4769,0xfc12,0xfc12,0xce12,0xce12,0,4,4,4,0x411,0x411,0x4819,0x48c9, +0x4999,0x391,0x4a19,0x4a99,0xfc12,0xfc12,0xc812,0xc812,0xfc92,4,4,4,0,0,0x4b49,0x4bc9, +0x4c39,0,0x4cb9,0x4d39,0xc012,0xc012,0xc112,0xc112,0x4deb,4,4,0,0,0,0,0, 0,0,0,0,0,0,0,4,4,4,4,4,0,0,0,0, 0,0,0,0,4,4,0,0,0,0,0,0,4,0,0,4, 0,0,4,4,4,4,4,0,0,0,0,0,0,0,0,0, @@ -515,8 +515,8 @@ static const uint16_t ucase_props_trieIndex[12356]={ 0x64,0x44,0x64,0x64,0x64,0x64,0x64,0x64,0x44,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,2, 0,0,1,2,2,2,1,1,2,2,2,1,0,2,0,0, -0,2,2,2,2,2,0,0,0,0,0,0,2,0,0x4e9a,0, -2,0,0x4eda,0x4f1a,2,2,0,1,2,2,0xe12,2,1,0,0,0, +0,2,2,2,2,2,0,0,0,0,0,0,2,0,0x4e5a,0, +2,0,0x4e9a,0x4eda,2,2,0,1,2,2,0xe12,2,1,0,0,0, 0,1,0,0,1,1,2,2,0,0,0,0,0,2,1,1, 0x21,0x21,0,0,0,0,0xf211,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0x812,0x812,0x812,0x812,0x812,0x812,0x812,0x812, @@ -531,14 +531,14 @@ static const uint16_t ucase_props_trieIndex[12356]={ 0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812, 0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0x1812,0,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811, 0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811, -0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0,0x92,0xff91,0x4f5a,0x4f7a,0x4f9a,0x4fb9,0x4fd9,0x92, -0xff91,0x92,0xff91,0x92,0xff91,0x4ffa,0x501a,0x503a,0x505a,1,0x92,0xff91,1,0x92,0xff91,1, -1,1,1,1,0x25,5,0x507a,0x507a,0x92,0xff91,0x92,0xff91,1,0,0,0, +0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0xe811,0,0x92,0xff91,0x4f1a,0x4f3a,0x4f5a,0x4f79,0x4f99,0x92, +0xff91,0x92,0xff91,0x92,0xff91,0x4fba,0x4fda,0x4ffa,0x501a,1,0x92,0xff91,1,0x92,0xff91,1, +1,1,1,1,0x25,5,0x503a,0x503a,0x92,0xff91,0x92,0xff91,1,0,0,0, 0,0,0,0x92,0xff91,0x92,0xff91,0x44,0x44,0x44,0x92,0xff91,0,0,0,0, -0,0,0,0,0,0,0,0,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099, -0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099, -0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0x5099,0,0x5099,0,0,0,0, -0,0x5099,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059, +0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059, +0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0x5059,0,0x5059,0,0,0,0, +0,0x5059,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0x64,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44, 0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44, @@ -552,7 +552,7 @@ static const uint16_t ucase_props_trieIndex[12356]={ 0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0x92,0xff91,0x92,0xff91, -0x92,0xff91,0x92,0xff91,0x92,0xff91,0x50ba,0x50f9,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, +0x92,0xff91,0x92,0xff91,0x92,0xff91,0x507a,0x50b9,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, 0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0,0x44, 4,4,4,0,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0,4, 0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, @@ -564,11 +564,11 @@ static const uint16_t ucase_props_trieIndex[12356]={ 4,4,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, 1,1,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91, 0x92,0xff91,0x92,0xff91,5,1,1,1,1,1,1,1,1,0x92,0xff91,0x92, -0xff91,0x513a,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,4,4,4,0x92, -0xff91,0x515a,1,0,0x92,0xff91,0x92,0xff91,0x1811,1,0x92,0xff91,0x92,0xff91,0x92,0xff91, -0x92,0xff91,0x92,0xff91,0x92,0xff91,0x517a,0x519a,0x51ba,0x51da,0x517a,1,0x51fa,0x521a,0x523a,0x525a, +0xff91,0x50fa,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,4,4,4,0x92, +0xff91,0x511a,1,0,0x92,0xff91,0x92,0xff91,0x1811,1,0x92,0xff91,0x92,0xff91,0x92,0xff91, +0x92,0xff91,0x92,0xff91,0x92,0xff91,0x513a,0x515a,0x517a,0x519a,0x513a,1,0x51ba,0x51da,0x51fa,0x521a, 0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0x92,0xff91,0,0,0x92,0xff91, -0xe812,0x527a,0x529a,0x92,0xff91,0x92,0xff91,0,0,0,0,0,0,0,0,0, +0xe812,0x523a,0x525a,0x92,0xff91,0x92,0xff91,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0x92,0xff91,0, 5,5,1,0,0,0,0,0,0,0,4,0,0,0,0x64,0, 0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0, @@ -597,17 +597,17 @@ static const uint16_t ucase_props_trieIndex[12356]={ 0,0,0,0,4,4,0,0,0,0,0,4,4,0,0x64,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,0x52b9,1,1,1,1,1,1,1,4,5,5,5,5, +1,1,1,0x5279,1,1,1,1,1,1,1,4,5,5,5,5, 1,1,1,1,1,1,1,1,1,4,4,4,0,0,0,0, -0x52d9,0x5309,0x5339,0x5369,0x5399,0x53c9,0x53f9,0x5429,0x5459,0x5489,0x54b9,0x54e9,0x5519,0x5549,0x5579,0x55a9, -0x5bd9,0x5c09,0x5c39,0x5c69,0x5c99,0x5cc9,0x5cf9,0x5d29,0x5d59,0x5d89,0x5db9,0x5de9,0x5e19,0x5e49,0x5e79,0x5ea9, -0x5ed9,0x5f09,0x5f39,0x5f69,0x5f99,0x5fc9,0x5ff9,0x6029,0x6059,0x6089,0x60b9,0x60e9,0x6119,0x6149,0x6179,0x61a9, -0x55d9,0x5609,0x5639,0x5669,0x5699,0x56c9,0x56f9,0x5729,0x5759,0x5789,0x57b9,0x57e9,0x5819,0x5849,0x5879,0x58a9, -0x58d9,0x5909,0x5939,0x5969,0x5999,0x59c9,0x59f9,0x5a29,0x5a59,0x5a89,0x5ab9,0x5ae9,0x5b19,0x5b49,0x5b79,0x5ba9, +0x5299,0x52c9,0x52f9,0x5329,0x5359,0x5389,0x53b9,0x53e9,0x5419,0x5449,0x5479,0x54a9,0x54d9,0x5509,0x5539,0x5569, +0x5b99,0x5bc9,0x5bf9,0x5c29,0x5c59,0x5c89,0x5cb9,0x5ce9,0x5d19,0x5d49,0x5d79,0x5da9,0x5dd9,0x5e09,0x5e39,0x5e69, +0x5e99,0x5ec9,0x5ef9,0x5f29,0x5f59,0x5f89,0x5fb9,0x5fe9,0x6019,0x6049,0x6079,0x60a9,0x60d9,0x6109,0x6139,0x6169, +0x5599,0x55c9,0x55f9,0x5629,0x5659,0x5689,0x56b9,0x56e9,0x5719,0x5749,0x5779,0x57a9,0x57d9,0x5809,0x5839,0x5869, +0x5899,0x58c9,0x58f9,0x5929,0x5959,0x5989,0x59b9,0x59e9,0x5a19,0x5a49,0x5a79,0x5aa9,0x5ad9,0x5b09,0x5b39,0x5b69, 0,0,0,0,0,4,0,0,4,0,0,0,0,0x64,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0x61d9,0x6259,0x62d9,0x6359,0x6409,0x64b9,0x6559,0,0,0,0,0,0,0,0,0, -0,0,0,0x65f9,0x6679,0x66f9,0x6779,0x67f9,0,0,0,0,0,0,0x64,0, +0x6199,0x6219,0x6299,0x6319,0x63c9,0x6479,0x6519,0,0,0,0,0,0,0,0,0, +0,0,0,0x65b9,0x6639,0x66b9,0x6739,0x67b9,0,0,0,0,0,0,0x64,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 4,4,4,4,0,0,0,4,0,0,0,0,0,0,0,0, @@ -791,7 +791,7 @@ static const uint16_t ucase_props_trieIndex[12356]={ 0,0,0,0 }; -static const uint16_t ucase_props_exceptions[1671]={ +static const uint16_t ucase_props_exceptions[1667]={ 0xc850,0x20,2,0x130,0x131,0x4810,0x20,0x841,0x6b,1,0x212a,0x841,0x73,1,0x17f,0x5c50, 0x20,2,0x130,0x131,0x844,0x4b,1,0x212a,0x844,0x53,1,0x17f,0x806,0x3bc,0x39c,0x841, 0xe5,1,0x212b,0x8c0,1,0x2220,0x73,0x73,0x53,0x53,0x53,0x73,0x1e9e,0x844,0xc5,1, @@ -815,88 +815,88 @@ static const uint16_t ucase_props_exceptions[1671]={ 0x43e,1,0x1c82,0x841,0x441,1,0x1c83,0x841,0x442,2,0x1c84,0x1c85,0x841,0x44a,1,0x1c86, 0x844,0x412,1,0x1c80,0x844,0x414,1,0x1c81,0x844,0x41e,1,0x1c82,0x844,0x421,1,0x1c83, 0x844,0x422,2,0x1c84,0x1c85,0x844,0x42a,1,0x1c86,0x841,0x463,1,0x1c87,0x844,0x462,1, -0x1c87,0x880,0x2220,0x565,0x582,0x535,0x552,0x535,0x582,0x810,0x1c60,0x80c,0x1c90,0x10d0,0x80c,0x1c91, -0x10d1,0x80c,0x1c92,0x10d2,0x80c,0x1c93,0x10d3,0x80c,0x1c94,0x10d4,0x80c,0x1c95,0x10d5,0x80c,0x1c96,0x10d6, -0x80c,0x1c97,0x10d7,0x80c,0x1c98,0x10d8,0x80c,0x1c99,0x10d9,0x80c,0x1c9a,0x10da,0x80c,0x1c9b,0x10db,0x80c, -0x1c9c,0x10dc,0x80c,0x1c9d,0x10dd,0x80c,0x1c9e,0x10de,0x80c,0x1c9f,0x10df,0x80c,0x1ca0,0x10e0,0x80c,0x1ca1, -0x10e1,0x80c,0x1ca2,0x10e2,0x80c,0x1ca3,0x10e3,0x80c,0x1ca4,0x10e4,0x80c,0x1ca5,0x10e5,0x80c,0x1ca6,0x10e6, -0x80c,0x1ca7,0x10e7,0x80c,0x1ca8,0x10e8,0x80c,0x1ca9,0x10e9,0x80c,0x1caa,0x10ea,0x80c,0x1cab,0x10eb,0x80c, -0x1cac,0x10ec,0x80c,0x1cad,0x10ed,0x80c,0x1cae,0x10ee,0x80c,0x1caf,0x10ef,0x80c,0x1cb0,0x10f0,0x80c,0x1cb1, -0x10f1,0x80c,0x1cb2,0x10f2,0x80c,0x1cb3,0x10f3,0x80c,0x1cb4,0x10f4,0x80c,0x1cb5,0x10f5,0x80c,0x1cb6,0x10f6, -0x80c,0x1cb7,0x10f7,0x80c,0x1cb8,0x10f8,0x80c,0x1cb9,0x10f9,0x80c,0x1cba,0x10fa,0x80c,0x1cbd,0x10fd,0x80c, -0x1cbe,0x10fe,0x80c,0x1cbf,0x10ff,0xa10,0x97d0,0xa10,8,0x806,0x13f0,0x13f0,0x806,0x13f1,0x13f1,0x806, -0x13f2,0x13f2,0x806,0x13f3,0x13f3,0x806,0x13f4,0x13f4,0x806,0x13f5,0x13f5,0x806,0x432,0x412,0x806,0x434, -0x414,0x806,0x43e,0x41e,0x806,0x441,0x421,0x846,0x442,0x422,1,0x1c85,0x846,0x442,0x422,1, -0x1c84,0x806,0x44a,0x42a,0x806,0x463,0x462,0x806,0xa64b,0xa64a,0xc10,0xbc0,0x810,0x8a04,0x810,0xee6, -0x810,0x8a38,0x841,0x1e61,1,0x1e9b,0x844,0x1e60,1,0x1e9b,0x880,0x2220,0x68,0x331,0x48,0x331, -0x48,0x331,0x880,0x2220,0x74,0x308,0x54,0x308,0x54,0x308,0x880,0x2220,0x77,0x30a,0x57,0x30a, -0x57,0x30a,0x880,0x2220,0x79,0x30a,0x59,0x30a,0x59,0x30a,0x880,0x2220,0x61,0x2be,0x41,0x2be, -0x41,0x2be,0x806,0x1e61,0x1e60,0xc90,0x1dbf,0x20,0x73,0x73,0x880,0x2220,0x3c5,0x313,0x3a5,0x313, -0x3a5,0x313,0x880,0x3330,0x3c5,0x313,0x300,0x3a5,0x313,0x300,0x3a5,0x313,0x300,0x880,0x3330,0x3c5, -0x313,0x301,0x3a5,0x313,0x301,0x3a5,0x313,0x301,0x880,0x3330,0x3c5,0x313,0x342,0x3a5,0x313,0x342, -0x3a5,0x313,0x342,0x890,8,0x220,0x1f00,0x3b9,0x1f08,0x399,0x890,8,0x220,0x1f01,0x3b9,0x1f09, -0x399,0x890,8,0x220,0x1f02,0x3b9,0x1f0a,0x399,0x890,8,0x220,0x1f03,0x3b9,0x1f0b,0x399,0x890, -8,0x220,0x1f04,0x3b9,0x1f0c,0x399,0x890,8,0x220,0x1f05,0x3b9,0x1f0d,0x399,0x890,8,0x220, -0x1f06,0x3b9,0x1f0e,0x399,0x890,8,0x220,0x1f07,0x3b9,0x1f0f,0x399,0xc90,8,0x220,0x1f00,0x3b9, -0x1f08,0x399,0xc90,8,0x220,0x1f01,0x3b9,0x1f09,0x399,0xc90,8,0x220,0x1f02,0x3b9,0x1f0a,0x399, -0xc90,8,0x220,0x1f03,0x3b9,0x1f0b,0x399,0xc90,8,0x220,0x1f04,0x3b9,0x1f0c,0x399,0xc90,8, -0x220,0x1f05,0x3b9,0x1f0d,0x399,0xc90,8,0x220,0x1f06,0x3b9,0x1f0e,0x399,0xc90,8,0x220,0x1f07, -0x3b9,0x1f0f,0x399,0x890,8,0x220,0x1f20,0x3b9,0x1f28,0x399,0x890,8,0x220,0x1f21,0x3b9,0x1f29, -0x399,0x890,8,0x220,0x1f22,0x3b9,0x1f2a,0x399,0x890,8,0x220,0x1f23,0x3b9,0x1f2b,0x399,0x890, -8,0x220,0x1f24,0x3b9,0x1f2c,0x399,0x890,8,0x220,0x1f25,0x3b9,0x1f2d,0x399,0x890,8,0x220, -0x1f26,0x3b9,0x1f2e,0x399,0x890,8,0x220,0x1f27,0x3b9,0x1f2f,0x399,0xc90,8,0x220,0x1f20,0x3b9, -0x1f28,0x399,0xc90,8,0x220,0x1f21,0x3b9,0x1f29,0x399,0xc90,8,0x220,0x1f22,0x3b9,0x1f2a,0x399, -0xc90,8,0x220,0x1f23,0x3b9,0x1f2b,0x399,0xc90,8,0x220,0x1f24,0x3b9,0x1f2c,0x399,0xc90,8, -0x220,0x1f25,0x3b9,0x1f2d,0x399,0xc90,8,0x220,0x1f26,0x3b9,0x1f2e,0x399,0xc90,8,0x220,0x1f27, -0x3b9,0x1f2f,0x399,0x890,8,0x220,0x1f60,0x3b9,0x1f68,0x399,0x890,8,0x220,0x1f61,0x3b9,0x1f69, -0x399,0x890,8,0x220,0x1f62,0x3b9,0x1f6a,0x399,0x890,8,0x220,0x1f63,0x3b9,0x1f6b,0x399,0x890, -8,0x220,0x1f64,0x3b9,0x1f6c,0x399,0x890,8,0x220,0x1f65,0x3b9,0x1f6d,0x399,0x890,8,0x220, -0x1f66,0x3b9,0x1f6e,0x399,0x890,8,0x220,0x1f67,0x3b9,0x1f6f,0x399,0xc90,8,0x220,0x1f60,0x3b9, -0x1f68,0x399,0xc90,8,0x220,0x1f61,0x3b9,0x1f69,0x399,0xc90,8,0x220,0x1f62,0x3b9,0x1f6a,0x399, -0xc90,8,0x220,0x1f63,0x3b9,0x1f6b,0x399,0xc90,8,0x220,0x1f64,0x3b9,0x1f6c,0x399,0xc90,8, -0x220,0x1f65,0x3b9,0x1f6d,0x399,0xc90,8,0x220,0x1f66,0x3b9,0x1f6e,0x399,0xc90,8,0x220,0x1f67, -0x3b9,0x1f6f,0x399,0x880,0x2220,0x1f70,0x3b9,0x1fba,0x399,0x1fba,0x345,0x890,9,0x220,0x3b1,0x3b9, -0x391,0x399,0x880,0x2220,0x3ac,0x3b9,0x386,0x399,0x386,0x345,0x880,0x2220,0x3b1,0x342,0x391,0x342, -0x391,0x342,0x880,0x3330,0x3b1,0x342,0x3b9,0x391,0x342,0x399,0x391,0x342,0x345,0xc90,9,0x220, -0x3b1,0x3b9,0x391,0x399,0x846,0x3b9,0x399,1,0x345,0x880,0x2220,0x1f74,0x3b9,0x1fca,0x399,0x1fca, -0x345,0x890,9,0x220,0x3b7,0x3b9,0x397,0x399,0x880,0x2220,0x3ae,0x3b9,0x389,0x399,0x389,0x345, -0x880,0x2220,0x3b7,0x342,0x397,0x342,0x397,0x342,0x880,0x3330,0x3b7,0x342,0x3b9,0x397,0x342,0x399, -0x397,0x342,0x345,0xc90,9,0x220,0x3b7,0x3b9,0x397,0x399,0x880,0x3330,0x3b9,0x308,0x300,0x399, -0x308,0x300,0x399,0x308,0x300,0x8c0,1,0x3330,0x3b9,0x308,0x301,0x399,0x308,0x301,0x399,0x308, -0x301,0x390,0x880,0x2220,0x3b9,0x342,0x399,0x342,0x399,0x342,0x880,0x3330,0x3b9,0x308,0x342,0x399, -0x308,0x342,0x399,0x308,0x342,0x880,0x3330,0x3c5,0x308,0x300,0x3a5,0x308,0x300,0x3a5,0x308,0x300, -0x8c0,1,0x3330,0x3c5,0x308,0x301,0x3a5,0x308,0x301,0x3a5,0x308,0x301,0x3b0,0x880,0x2220,0x3c1, -0x313,0x3a1,0x313,0x3a1,0x313,0x880,0x2220,0x3c5,0x342,0x3a5,0x342,0x3a5,0x342,0x880,0x3330,0x3c5, -0x308,0x342,0x3a5,0x308,0x342,0x3a5,0x308,0x342,0x880,0x2220,0x1f7c,0x3b9,0x1ffa,0x399,0x1ffa,0x345, -0x890,9,0x220,0x3c9,0x3b9,0x3a9,0x399,0x880,0x2220,0x3ce,0x3b9,0x38f,0x399,0x38f,0x345,0x880, -0x2220,0x3c9,0x342,0x3a9,0x342,0x3a9,0x342,0x880,0x3330,0x3c9,0x342,0x3b9,0x3a9,0x342,0x399,0x3a9, -0x342,0x345,0xc90,9,0x220,0x3c9,0x3b9,0x3a9,0x399,0xc50,0x1d5d,1,0x3a9,0xc50,0x20bf,1, -0x4b,0xc50,0x2046,1,0xc5,0xc10,0x29f7,0xc10,0xee6,0xc10,0x29e7,0xc10,0x2a2b,0xc10,0x2a28,0xc10, -0x2a1c,0xc10,0x29fd,0xc10,0x2a1f,0xc10,0x2a1e,0xc10,0x2a3f,0xc10,0x1c60,0x841,0xa64b,1,0x1c88,0x844, -0xa64a,1,0x1c88,0xc10,0x8a04,0xc10,0xa528,0xc10,0xa544,0xc10,0xa54f,0xc10,0xa54b,0xc10,0xa541,0xc10, -0xa512,0xc10,0xa52a,0xc10,0xa515,0x810,0x3a0,0xc10,0xa543,0xc10,0x8a38,0xc10,0x3a0,0x806,0x13a0,0x13a0, -0x806,0x13a1,0x13a1,0x806,0x13a2,0x13a2,0x806,0x13a3,0x13a3,0x806,0x13a4,0x13a4,0x806,0x13a5,0x13a5,0x806, -0x13a6,0x13a6,0x806,0x13a7,0x13a7,0x806,0x13a8,0x13a8,0x806,0x13a9,0x13a9,0x806,0x13aa,0x13aa,0x806,0x13ab, -0x13ab,0x806,0x13ac,0x13ac,0x806,0x13ad,0x13ad,0x806,0x13ae,0x13ae,0x806,0x13af,0x13af,0x806,0x13b0,0x13b0, -0x806,0x13b1,0x13b1,0x806,0x13b2,0x13b2,0x806,0x13b3,0x13b3,0x806,0x13b4,0x13b4,0x806,0x13b5,0x13b5,0x806, -0x13b6,0x13b6,0x806,0x13b7,0x13b7,0x806,0x13b8,0x13b8,0x806,0x13b9,0x13b9,0x806,0x13ba,0x13ba,0x806,0x13bb, -0x13bb,0x806,0x13bc,0x13bc,0x806,0x13bd,0x13bd,0x806,0x13be,0x13be,0x806,0x13bf,0x13bf,0x806,0x13c0,0x13c0, -0x806,0x13c1,0x13c1,0x806,0x13c2,0x13c2,0x806,0x13c3,0x13c3,0x806,0x13c4,0x13c4,0x806,0x13c5,0x13c5,0x806, -0x13c6,0x13c6,0x806,0x13c7,0x13c7,0x806,0x13c8,0x13c8,0x806,0x13c9,0x13c9,0x806,0x13ca,0x13ca,0x806,0x13cb, -0x13cb,0x806,0x13cc,0x13cc,0x806,0x13cd,0x13cd,0x806,0x13ce,0x13ce,0x806,0x13cf,0x13cf,0x806,0x13d0,0x13d0, -0x806,0x13d1,0x13d1,0x806,0x13d2,0x13d2,0x806,0x13d3,0x13d3,0x806,0x13d4,0x13d4,0x806,0x13d5,0x13d5,0x806, -0x13d6,0x13d6,0x806,0x13d7,0x13d7,0x806,0x13d8,0x13d8,0x806,0x13d9,0x13d9,0x806,0x13da,0x13da,0x806,0x13db, -0x13db,0x806,0x13dc,0x13dc,0x806,0x13dd,0x13dd,0x806,0x13de,0x13de,0x806,0x13df,0x13df,0x806,0x13e0,0x13e0, -0x806,0x13e1,0x13e1,0x806,0x13e2,0x13e2,0x806,0x13e3,0x13e3,0x806,0x13e4,0x13e4,0x806,0x13e5,0x13e5,0x806, -0x13e6,0x13e6,0x806,0x13e7,0x13e7,0x806,0x13e8,0x13e8,0x806,0x13e9,0x13e9,0x806,0x13ea,0x13ea,0x806,0x13eb, -0x13eb,0x806,0x13ec,0x13ec,0x806,0x13ed,0x13ed,0x806,0x13ee,0x13ee,0x806,0x13ef,0x13ef,0x880,0x2220,0x66, -0x66,0x46,0x46,0x46,0x66,0x880,0x2220,0x66,0x69,0x46,0x49,0x46,0x69,0x880,0x2220,0x66, -0x6c,0x46,0x4c,0x46,0x6c,0x880,0x3330,0x66,0x66,0x69,0x46,0x46,0x49,0x46,0x66,0x69, -0x880,0x3330,0x66,0x66,0x6c,0x46,0x46,0x4c,0x46,0x66,0x6c,0x8c0,1,0x2220,0x73,0x74, -0x53,0x54,0x53,0x74,0xfb06,0x8c0,1,0x2220,0x73,0x74,0x53,0x54,0x53,0x74,0xfb05,0x880, -0x2220,0x574,0x576,0x544,0x546,0x544,0x576,0x880,0x2220,0x574,0x565,0x544,0x535,0x544,0x565,0x880, -0x2220,0x574,0x56b,0x544,0x53b,0x544,0x56b,0x880,0x2220,0x57e,0x576,0x54e,0x546,0x54e,0x576,0x880, -0x2220,0x574,0x56d,0x544,0x53d,0x544,0x56d +0x1c87,0x4880,0x20,0x565,0x582,0x810,0x1c60,0x80c,0x1c90,0x10d0,0x80c,0x1c91,0x10d1,0x80c,0x1c92,0x10d2, +0x80c,0x1c93,0x10d3,0x80c,0x1c94,0x10d4,0x80c,0x1c95,0x10d5,0x80c,0x1c96,0x10d6,0x80c,0x1c97,0x10d7,0x80c, +0x1c98,0x10d8,0x80c,0x1c99,0x10d9,0x80c,0x1c9a,0x10da,0x80c,0x1c9b,0x10db,0x80c,0x1c9c,0x10dc,0x80c,0x1c9d, +0x10dd,0x80c,0x1c9e,0x10de,0x80c,0x1c9f,0x10df,0x80c,0x1ca0,0x10e0,0x80c,0x1ca1,0x10e1,0x80c,0x1ca2,0x10e2, +0x80c,0x1ca3,0x10e3,0x80c,0x1ca4,0x10e4,0x80c,0x1ca5,0x10e5,0x80c,0x1ca6,0x10e6,0x80c,0x1ca7,0x10e7,0x80c, +0x1ca8,0x10e8,0x80c,0x1ca9,0x10e9,0x80c,0x1caa,0x10ea,0x80c,0x1cab,0x10eb,0x80c,0x1cac,0x10ec,0x80c,0x1cad, +0x10ed,0x80c,0x1cae,0x10ee,0x80c,0x1caf,0x10ef,0x80c,0x1cb0,0x10f0,0x80c,0x1cb1,0x10f1,0x80c,0x1cb2,0x10f2, +0x80c,0x1cb3,0x10f3,0x80c,0x1cb4,0x10f4,0x80c,0x1cb5,0x10f5,0x80c,0x1cb6,0x10f6,0x80c,0x1cb7,0x10f7,0x80c, +0x1cb8,0x10f8,0x80c,0x1cb9,0x10f9,0x80c,0x1cba,0x10fa,0x80c,0x1cbd,0x10fd,0x80c,0x1cbe,0x10fe,0x80c,0x1cbf, +0x10ff,0xa10,0x97d0,0xa10,8,0x806,0x13f0,0x13f0,0x806,0x13f1,0x13f1,0x806,0x13f2,0x13f2,0x806,0x13f3, +0x13f3,0x806,0x13f4,0x13f4,0x806,0x13f5,0x13f5,0x806,0x432,0x412,0x806,0x434,0x414,0x806,0x43e,0x41e, +0x806,0x441,0x421,0x846,0x442,0x422,1,0x1c85,0x846,0x442,0x422,1,0x1c84,0x806,0x44a,0x42a, +0x806,0x463,0x462,0x806,0xa64b,0xa64a,0xc10,0xbc0,0x810,0x8a04,0x810,0xee6,0x810,0x8a38,0x841,0x1e61, +1,0x1e9b,0x844,0x1e60,1,0x1e9b,0x880,0x2220,0x68,0x331,0x48,0x331,0x48,0x331,0x880,0x2220, +0x74,0x308,0x54,0x308,0x54,0x308,0x880,0x2220,0x77,0x30a,0x57,0x30a,0x57,0x30a,0x880,0x2220, +0x79,0x30a,0x59,0x30a,0x59,0x30a,0x880,0x2220,0x61,0x2be,0x41,0x2be,0x41,0x2be,0x806,0x1e61, +0x1e60,0xc90,0x1dbf,0x20,0x73,0x73,0x880,0x2220,0x3c5,0x313,0x3a5,0x313,0x3a5,0x313,0x880,0x3330, +0x3c5,0x313,0x300,0x3a5,0x313,0x300,0x3a5,0x313,0x300,0x880,0x3330,0x3c5,0x313,0x301,0x3a5,0x313, +0x301,0x3a5,0x313,0x301,0x880,0x3330,0x3c5,0x313,0x342,0x3a5,0x313,0x342,0x3a5,0x313,0x342,0x890, +8,0x220,0x1f00,0x3b9,0x1f08,0x399,0x890,8,0x220,0x1f01,0x3b9,0x1f09,0x399,0x890,8,0x220, +0x1f02,0x3b9,0x1f0a,0x399,0x890,8,0x220,0x1f03,0x3b9,0x1f0b,0x399,0x890,8,0x220,0x1f04,0x3b9, +0x1f0c,0x399,0x890,8,0x220,0x1f05,0x3b9,0x1f0d,0x399,0x890,8,0x220,0x1f06,0x3b9,0x1f0e,0x399, +0x890,8,0x220,0x1f07,0x3b9,0x1f0f,0x399,0xc90,8,0x220,0x1f00,0x3b9,0x1f08,0x399,0xc90,8, +0x220,0x1f01,0x3b9,0x1f09,0x399,0xc90,8,0x220,0x1f02,0x3b9,0x1f0a,0x399,0xc90,8,0x220,0x1f03, +0x3b9,0x1f0b,0x399,0xc90,8,0x220,0x1f04,0x3b9,0x1f0c,0x399,0xc90,8,0x220,0x1f05,0x3b9,0x1f0d, +0x399,0xc90,8,0x220,0x1f06,0x3b9,0x1f0e,0x399,0xc90,8,0x220,0x1f07,0x3b9,0x1f0f,0x399,0x890, +8,0x220,0x1f20,0x3b9,0x1f28,0x399,0x890,8,0x220,0x1f21,0x3b9,0x1f29,0x399,0x890,8,0x220, +0x1f22,0x3b9,0x1f2a,0x399,0x890,8,0x220,0x1f23,0x3b9,0x1f2b,0x399,0x890,8,0x220,0x1f24,0x3b9, +0x1f2c,0x399,0x890,8,0x220,0x1f25,0x3b9,0x1f2d,0x399,0x890,8,0x220,0x1f26,0x3b9,0x1f2e,0x399, +0x890,8,0x220,0x1f27,0x3b9,0x1f2f,0x399,0xc90,8,0x220,0x1f20,0x3b9,0x1f28,0x399,0xc90,8, +0x220,0x1f21,0x3b9,0x1f29,0x399,0xc90,8,0x220,0x1f22,0x3b9,0x1f2a,0x399,0xc90,8,0x220,0x1f23, +0x3b9,0x1f2b,0x399,0xc90,8,0x220,0x1f24,0x3b9,0x1f2c,0x399,0xc90,8,0x220,0x1f25,0x3b9,0x1f2d, +0x399,0xc90,8,0x220,0x1f26,0x3b9,0x1f2e,0x399,0xc90,8,0x220,0x1f27,0x3b9,0x1f2f,0x399,0x890, +8,0x220,0x1f60,0x3b9,0x1f68,0x399,0x890,8,0x220,0x1f61,0x3b9,0x1f69,0x399,0x890,8,0x220, +0x1f62,0x3b9,0x1f6a,0x399,0x890,8,0x220,0x1f63,0x3b9,0x1f6b,0x399,0x890,8,0x220,0x1f64,0x3b9, +0x1f6c,0x399,0x890,8,0x220,0x1f65,0x3b9,0x1f6d,0x399,0x890,8,0x220,0x1f66,0x3b9,0x1f6e,0x399, +0x890,8,0x220,0x1f67,0x3b9,0x1f6f,0x399,0xc90,8,0x220,0x1f60,0x3b9,0x1f68,0x399,0xc90,8, +0x220,0x1f61,0x3b9,0x1f69,0x399,0xc90,8,0x220,0x1f62,0x3b9,0x1f6a,0x399,0xc90,8,0x220,0x1f63, +0x3b9,0x1f6b,0x399,0xc90,8,0x220,0x1f64,0x3b9,0x1f6c,0x399,0xc90,8,0x220,0x1f65,0x3b9,0x1f6d, +0x399,0xc90,8,0x220,0x1f66,0x3b9,0x1f6e,0x399,0xc90,8,0x220,0x1f67,0x3b9,0x1f6f,0x399,0x880, +0x2220,0x1f70,0x3b9,0x1fba,0x399,0x1fba,0x345,0x890,9,0x220,0x3b1,0x3b9,0x391,0x399,0x880,0x2220, +0x3ac,0x3b9,0x386,0x399,0x386,0x345,0x880,0x2220,0x3b1,0x342,0x391,0x342,0x391,0x342,0x880,0x3330, +0x3b1,0x342,0x3b9,0x391,0x342,0x399,0x391,0x342,0x345,0xc90,9,0x220,0x3b1,0x3b9,0x391,0x399, +0x846,0x3b9,0x399,1,0x345,0x880,0x2220,0x1f74,0x3b9,0x1fca,0x399,0x1fca,0x345,0x890,9,0x220, +0x3b7,0x3b9,0x397,0x399,0x880,0x2220,0x3ae,0x3b9,0x389,0x399,0x389,0x345,0x880,0x2220,0x3b7,0x342, +0x397,0x342,0x397,0x342,0x880,0x3330,0x3b7,0x342,0x3b9,0x397,0x342,0x399,0x397,0x342,0x345,0xc90, +9,0x220,0x3b7,0x3b9,0x397,0x399,0x880,0x3330,0x3b9,0x308,0x300,0x399,0x308,0x300,0x399,0x308, +0x300,0x8c0,1,0x3330,0x3b9,0x308,0x301,0x399,0x308,0x301,0x399,0x308,0x301,0x390,0x880,0x2220, +0x3b9,0x342,0x399,0x342,0x399,0x342,0x880,0x3330,0x3b9,0x308,0x342,0x399,0x308,0x342,0x399,0x308, +0x342,0x880,0x3330,0x3c5,0x308,0x300,0x3a5,0x308,0x300,0x3a5,0x308,0x300,0x8c0,1,0x3330,0x3c5, +0x308,0x301,0x3a5,0x308,0x301,0x3a5,0x308,0x301,0x3b0,0x880,0x2220,0x3c1,0x313,0x3a1,0x313,0x3a1, +0x313,0x880,0x2220,0x3c5,0x342,0x3a5,0x342,0x3a5,0x342,0x880,0x3330,0x3c5,0x308,0x342,0x3a5,0x308, +0x342,0x3a5,0x308,0x342,0x880,0x2220,0x1f7c,0x3b9,0x1ffa,0x399,0x1ffa,0x345,0x890,9,0x220,0x3c9, +0x3b9,0x3a9,0x399,0x880,0x2220,0x3ce,0x3b9,0x38f,0x399,0x38f,0x345,0x880,0x2220,0x3c9,0x342,0x3a9, +0x342,0x3a9,0x342,0x880,0x3330,0x3c9,0x342,0x3b9,0x3a9,0x342,0x399,0x3a9,0x342,0x345,0xc90,9, +0x220,0x3c9,0x3b9,0x3a9,0x399,0xc50,0x1d5d,1,0x3a9,0xc50,0x20bf,1,0x4b,0xc50,0x2046,1, +0xc5,0xc10,0x29f7,0xc10,0xee6,0xc10,0x29e7,0xc10,0x2a2b,0xc10,0x2a28,0xc10,0x2a1c,0xc10,0x29fd,0xc10, +0x2a1f,0xc10,0x2a1e,0xc10,0x2a3f,0xc10,0x1c60,0x841,0xa64b,1,0x1c88,0x844,0xa64a,1,0x1c88,0xc10, +0x8a04,0xc10,0xa528,0xc10,0xa544,0xc10,0xa54f,0xc10,0xa54b,0xc10,0xa541,0xc10,0xa512,0xc10,0xa52a,0xc10, +0xa515,0x810,0x3a0,0xc10,0xa543,0xc10,0x8a38,0xc10,0x3a0,0x806,0x13a0,0x13a0,0x806,0x13a1,0x13a1,0x806, +0x13a2,0x13a2,0x806,0x13a3,0x13a3,0x806,0x13a4,0x13a4,0x806,0x13a5,0x13a5,0x806,0x13a6,0x13a6,0x806,0x13a7, +0x13a7,0x806,0x13a8,0x13a8,0x806,0x13a9,0x13a9,0x806,0x13aa,0x13aa,0x806,0x13ab,0x13ab,0x806,0x13ac,0x13ac, +0x806,0x13ad,0x13ad,0x806,0x13ae,0x13ae,0x806,0x13af,0x13af,0x806,0x13b0,0x13b0,0x806,0x13b1,0x13b1,0x806, +0x13b2,0x13b2,0x806,0x13b3,0x13b3,0x806,0x13b4,0x13b4,0x806,0x13b5,0x13b5,0x806,0x13b6,0x13b6,0x806,0x13b7, +0x13b7,0x806,0x13b8,0x13b8,0x806,0x13b9,0x13b9,0x806,0x13ba,0x13ba,0x806,0x13bb,0x13bb,0x806,0x13bc,0x13bc, +0x806,0x13bd,0x13bd,0x806,0x13be,0x13be,0x806,0x13bf,0x13bf,0x806,0x13c0,0x13c0,0x806,0x13c1,0x13c1,0x806, +0x13c2,0x13c2,0x806,0x13c3,0x13c3,0x806,0x13c4,0x13c4,0x806,0x13c5,0x13c5,0x806,0x13c6,0x13c6,0x806,0x13c7, +0x13c7,0x806,0x13c8,0x13c8,0x806,0x13c9,0x13c9,0x806,0x13ca,0x13ca,0x806,0x13cb,0x13cb,0x806,0x13cc,0x13cc, +0x806,0x13cd,0x13cd,0x806,0x13ce,0x13ce,0x806,0x13cf,0x13cf,0x806,0x13d0,0x13d0,0x806,0x13d1,0x13d1,0x806, +0x13d2,0x13d2,0x806,0x13d3,0x13d3,0x806,0x13d4,0x13d4,0x806,0x13d5,0x13d5,0x806,0x13d6,0x13d6,0x806,0x13d7, +0x13d7,0x806,0x13d8,0x13d8,0x806,0x13d9,0x13d9,0x806,0x13da,0x13da,0x806,0x13db,0x13db,0x806,0x13dc,0x13dc, +0x806,0x13dd,0x13dd,0x806,0x13de,0x13de,0x806,0x13df,0x13df,0x806,0x13e0,0x13e0,0x806,0x13e1,0x13e1,0x806, +0x13e2,0x13e2,0x806,0x13e3,0x13e3,0x806,0x13e4,0x13e4,0x806,0x13e5,0x13e5,0x806,0x13e6,0x13e6,0x806,0x13e7, +0x13e7,0x806,0x13e8,0x13e8,0x806,0x13e9,0x13e9,0x806,0x13ea,0x13ea,0x806,0x13eb,0x13eb,0x806,0x13ec,0x13ec, +0x806,0x13ed,0x13ed,0x806,0x13ee,0x13ee,0x806,0x13ef,0x13ef,0x880,0x2220,0x66,0x66,0x46,0x46,0x46, +0x66,0x880,0x2220,0x66,0x69,0x46,0x49,0x46,0x69,0x880,0x2220,0x66,0x6c,0x46,0x4c,0x46, +0x6c,0x880,0x3330,0x66,0x66,0x69,0x46,0x46,0x49,0x46,0x66,0x69,0x880,0x3330,0x66,0x66, +0x6c,0x46,0x46,0x4c,0x46,0x66,0x6c,0x8c0,1,0x2220,0x73,0x74,0x53,0x54,0x53,0x74, +0xfb06,0x8c0,1,0x2220,0x73,0x74,0x53,0x54,0x53,0x74,0xfb05,0x880,0x2220,0x574,0x576,0x544, +0x546,0x544,0x576,0x880,0x2220,0x574,0x565,0x544,0x535,0x544,0x565,0x880,0x2220,0x574,0x56b,0x544, +0x53b,0x544,0x56b,0x880,0x2220,0x57e,0x576,0x54e,0x546,0x54e,0x576,0x880,0x2220,0x574,0x56d,0x544, +0x53d,0x544,0x56d }; static const uint16_t ucase_props_unfold[370]={ diff --git a/deps/icu-small/source/common/ucasemap_imp.h b/deps/icu-small/source/common/ucasemap_imp.h index 7788fd93710305..e17a0ae5a36b6d 100644 --- a/deps/icu-small/source/common/ucasemap_imp.h +++ b/deps/icu-small/source/common/ucasemap_imp.h @@ -68,15 +68,15 @@ class BreakIterator; // unicode/brkiter.h class ByteSink; class Locale; // unicode/locid.h -/** Returns TRUE if the options are valid. Otherwise FALSE, and sets an error. */ +/** Returns true if the options are valid. Otherwise false, and sets an error. */ inline UBool ustrcase_checkTitleAdjustmentOptions(uint32_t options, UErrorCode &errorCode) { - if (U_FAILURE(errorCode)) { return FALSE; } + if (U_FAILURE(errorCode)) { return false; } if ((options & U_TITLECASE_ADJUSTMENT_MASK) == U_TITLECASE_ADJUSTMENT_MASK) { // Both options together. errorCode = U_ILLEGAL_ARGUMENT_ERROR; - return FALSE; + return false; } - return TRUE; + return true; } inline UBool ustrcase_isLNS(UChar32 c) { diff --git a/deps/icu-small/source/common/ucln_cmn.h b/deps/icu-small/source/common/ucln_cmn.h index b837fb946296a1..44b73e94da791f 100644 --- a/deps/icu-small/source/common/ucln_cmn.h +++ b/deps/icu-small/source/common/ucln_cmn.h @@ -38,6 +38,8 @@ typedef enum ECleanupCommonType { UCLN_COMMON_SERVICE, UCLN_COMMON_LOCALE_KEY_TYPE, UCLN_COMMON_LOCALE, + UCLN_COMMON_LOCALE_ALIAS, + UCLN_COMMON_LOCALE_KNOWN_CANONICALIZED, UCLN_COMMON_LOCALE_AVAILABLE, UCLN_COMMON_LIKELY_SUBTAGS, UCLN_COMMON_LOCALE_DISTANCE, diff --git a/deps/icu-small/source/common/ucln_imp.h b/deps/icu-small/source/common/ucln_imp.h index 2e985669793b82..b08c6e8368b1a3 100644 --- a/deps/icu-small/source/common/ucln_imp.h +++ b/deps/icu-small/source/common/ucln_imp.h @@ -78,7 +78,7 @@ * Use the ANSI C 'atexit' function. Note that this mechanism does not * guarantee the order of cleanup relative to other users of ICU! */ -static UBool gAutoCleanRegistered = FALSE; +static UBool gAutoCleanRegistered = false; static void ucln_atexit_handler() { @@ -88,7 +88,7 @@ static void ucln_atexit_handler() static void ucln_registerAutomaticCleanup() { if(!gAutoCleanRegistered) { - gAutoCleanRegistered = TRUE; + gAutoCleanRegistered = true; atexit(&ucln_atexit_handler); } } @@ -135,7 +135,7 @@ U_CAPI void U_EXPORT2 UCLN_FINI () */ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - BOOL status = TRUE; + BOOL status = true; switch(fdwReason) { case DLL_PROCESS_ATTACH: diff --git a/deps/icu-small/source/common/ucnv_bld.cpp b/deps/icu-small/source/common/ucnv_bld.cpp index 1c2363ea89981f..0e198892f1bdfb 100644 --- a/deps/icu-small/source/common/ucnv_bld.cpp +++ b/deps/icu-small/source/common/ucnv_bld.cpp @@ -262,7 +262,7 @@ static UBool U_CALLCONV ucnv_cleanup(void) { } U_CAPI void U_EXPORT2 -ucnv_enableCleanup() { +ucnv_enableCleanup(void) { ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup); } diff --git a/deps/icu-small/source/common/ucnv_bld.h b/deps/icu-small/source/common/ucnv_bld.h index caa263f56d938b..43e6c09ac0b0f8 100644 --- a/deps/icu-small/source/common/ucnv_bld.h +++ b/deps/icu-small/source/common/ucnv_bld.h @@ -101,8 +101,8 @@ struct UConverterSharedData { const UConverterStaticData *staticData; /* pointer to the static (non changing) data. */ - UBool sharedDataCached; /* TRUE: shared data is in cache, don't destroy on ucnv_close() if 0 ref. FALSE: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */ - /** If FALSE, then referenceCounter is not used. Must not change after initialization. */ + UBool sharedDataCached; /* true: shared data is in cache, don't destroy on ucnv_close() if 0 ref. false: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */ + /** If false, then referenceCounter is not used. Must not change after initialization. */ UBool isReferenceCounted; const UConverterImpl *impl; /* vtable-style struct of mostly function pointers */ @@ -128,7 +128,7 @@ struct UConverterSharedData { #define UCNV_IMMUTABLE_SHARED_DATA_INITIALIZER(pStaticData, pImpl) \ { \ sizeof(UConverterSharedData), ~((uint32_t)0), \ - NULL, pStaticData, FALSE, FALSE, pImpl, \ + NULL, pStaticData, false, false, pImpl, \ 0, UCNV_MBCS_TABLE_INITIALIZER \ } @@ -181,9 +181,9 @@ struct UConverter { uint32_t options; /* options flags from UConverterOpen, may contain additional bits */ - UBool sharedDataIsCached; /* TRUE: shared data is in cache, don't destroy on ucnv_close() if 0 ref. FALSE: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */ - UBool isCopyLocal; /* TRUE if UConverter is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */ - UBool isExtraLocal; /* TRUE if extraInfo is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */ + UBool sharedDataIsCached; /* true: shared data is in cache, don't destroy on ucnv_close() if 0 ref. false: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */ + UBool isCopyLocal; /* true if UConverter is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */ + UBool isExtraLocal; /* true if extraInfo is not owned and not released in ucnv_close() (stack-allocated, safeClone(), etc.) */ UBool useFallback; int8_t toULength; /* number of bytes in toUBytes */ @@ -289,7 +289,7 @@ ucnv_swap(const UDataSwapper *ds, UErrorCode *pErrorCode); U_CAPI void U_EXPORT2 -ucnv_enableCleanup(); +ucnv_enableCleanup(void); #endif diff --git a/deps/icu-small/source/common/ucnv_cnv.h b/deps/icu-small/source/common/ucnv_cnv.h index a996e2959784cf..345a1998e44883 100644 --- a/deps/icu-small/source/common/ucnv_cnv.h +++ b/deps/icu-small/source/common/ucnv_cnv.h @@ -59,7 +59,7 @@ typedef struct { } UConverterLoadArgs; #define UCNV_LOAD_ARGS_INITIALIZER \ - { (int32_t)sizeof(UConverterLoadArgs), 0, FALSE, FALSE, 0, 0, NULL, NULL, NULL } + { (int32_t)sizeof(UConverterLoadArgs), 0, false, false, 0, 0, NULL, NULL, NULL } typedef void (*UConverterLoad) (UConverterSharedData *sharedData, UConverterLoadArgs *pArgs, @@ -267,8 +267,8 @@ extern const UConverterSharedData U_CDECL_END /** Always use fallbacks from codepage to Unicode */ -#define TO_U_USE_FALLBACK(useFallback) TRUE -#define UCNV_TO_U_USE_FALLBACK(cnv) TRUE +#define TO_U_USE_FALLBACK(useFallback) true +#define UCNV_TO_U_USE_FALLBACK(cnv) true /** Use fallbacks from Unicode to codepage when cnv->useFallback or for private-use code points */ #define IS_PRIVATE_USE(c) ((uint32_t)((c)-0xe000)<0x1900 || (uint32_t)((c)-0xf0000)<0x20000) diff --git a/deps/icu-small/source/common/ucnv_u8.cpp b/deps/icu-small/source/common/ucnv_u8.cpp index 878d67304c7d89..9cf4a81ab2ef36 100644 --- a/deps/icu-small/source/common/ucnv_u8.cpp +++ b/deps/icu-small/source/common/ucnv_u8.cpp @@ -707,9 +707,9 @@ ucnv_UTF8FromUTF8(UConverterFromUnicodeArgs *pFromUArgs, // Do not go back into the bytes that will be read for finishing a partial // sequence from the previous buffer. - int32_t length=count-toULimit; + int32_t length=count-toULength; U8_TRUNCATE_IF_INCOMPLETE(source, 0, length); - count=toULimit+length; + count=toULength+length; } if(c!=0) { diff --git a/deps/icu-small/source/common/ucnvmbcs.h b/deps/icu-small/source/common/ucnvmbcs.h index a750b92e499c6e..ddc55b20fec271 100644 --- a/deps/icu-small/source/common/ucnvmbcs.h +++ b/deps/icu-small/source/common/ucnvmbcs.h @@ -420,7 +420,7 @@ typedef struct UConverterMBCSTable { NULL, \ 0, \ 0, 0, \ - FALSE, \ + false, \ 0, \ \ /* roundtrips */ \ diff --git a/deps/icu-small/source/common/ucol_swp.h b/deps/icu-small/source/common/ucol_swp.h index fd8be9aa54ff45..0c2990a85ecfc2 100644 --- a/deps/icu-small/source/common/ucol_swp.h +++ b/deps/icu-small/source/common/ucol_swp.h @@ -31,7 +31,7 @@ * Does the data look like a collation binary? * @internal */ -U_INTERNAL UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ucol_looksLikeCollationBinary(const UDataSwapper *ds, const void *inData, int32_t length); diff --git a/deps/icu-small/source/common/ucurr.cpp b/deps/icu-small/source/common/ucurr.cpp index 391b08083b899a..8d213dfcfcb516 100644 --- a/deps/icu-small/source/common/ucurr.cpp +++ b/deps/icu-small/source/common/ucurr.cpp @@ -91,6 +91,8 @@ static const char VAR_DELIM = '_'; // Tag for localized display names (symbols) of currencies static const char CURRENCIES[] = "Currencies"; static const char CURRENCIES_NARROW[] = "Currencies%narrow"; +static const char CURRENCIES_FORMAL[] = "Currencies%formal"; +static const char CURRENCIES_VARIANT[] = "Currencies%variant"; static const char CURRENCYPLURALS[] = "CurrencyPlurals"; // ISO codes mapping table @@ -649,7 +651,7 @@ ucurr_getName(const UChar* currency, } int32_t choice = (int32_t) nameStyle; - if (choice < 0 || choice > 2) { + if (choice < 0 || choice > 4) { *ec = U_ILLEGAL_ARGUMENT_ERROR; return 0; } @@ -684,9 +686,22 @@ ucurr_getName(const UChar* currency, ec2 = U_ZERO_ERROR; LocalUResourceBundlePointer rb(ures_open(U_ICUDATA_CURR, loc, &ec2)); - if (nameStyle == UCURR_NARROW_SYMBOL_NAME) { + if (nameStyle == UCURR_NARROW_SYMBOL_NAME || nameStyle == UCURR_FORMAL_SYMBOL_NAME || nameStyle == UCURR_VARIANT_SYMBOL_NAME) { CharString key; - key.append(CURRENCIES_NARROW, ec2); + switch (nameStyle) { + case UCURR_NARROW_SYMBOL_NAME: + key.append(CURRENCIES_NARROW, ec2); + break; + case UCURR_FORMAL_SYMBOL_NAME: + key.append(CURRENCIES_FORMAL, ec2); + break; + case UCURR_VARIANT_SYMBOL_NAME: + key.append(CURRENCIES_VARIANT, ec2); + break; + default: + *ec = U_UNSUPPORTED_ERROR; + return 0; + } key.append("/", ec2); key.append(buf, ec2); s = ures_getStringByKeyWithFallback(rb.getAlias(), key.data(), len, &ec2); @@ -1610,7 +1625,7 @@ ucurr_getDefaultFractionDigits(const UChar* currency, UErrorCode* ec) { return ucurr_getDefaultFractionDigitsForUsage(currency,UCURR_USAGE_STANDARD,ec); } -U_DRAFT int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucurr_getDefaultFractionDigitsForUsage(const UChar* currency, const UCurrencyUsage usage, UErrorCode* ec) { int32_t fracDigits = 0; if (U_SUCCESS(*ec)) { @@ -1633,7 +1648,7 @@ ucurr_getRoundingIncrement(const UChar* currency, UErrorCode* ec) { return ucurr_getRoundingIncrementForUsage(currency, UCURR_USAGE_STANDARD, ec); } -U_DRAFT double U_EXPORT2 +U_CAPI double U_EXPORT2 ucurr_getRoundingIncrementForUsage(const UChar* currency, const UCurrencyUsage usage, UErrorCode* ec) { double result = 0.0; @@ -2259,7 +2274,6 @@ ucurr_countCurrencies(const char* locale, // local variables UErrorCode localStatus = U_ZERO_ERROR; char id[ULOC_FULLNAME_CAPACITY]; - uloc_getKeywordValue(locale, "currency", id, ULOC_FULLNAME_CAPACITY, &localStatus); // get country or country_variant in `id' idForLocale(locale, id, sizeof(id), ec); @@ -2375,7 +2389,6 @@ ucurr_forLocaleAndDate(const char* locale, // local variables UErrorCode localStatus = U_ZERO_ERROR; char id[ULOC_FULLNAME_CAPACITY]; - resLen = uloc_getKeywordValue(locale, "currency", id, ULOC_FULLNAME_CAPACITY, &localStatus); // get country or country_variant in `id' idForLocale(locale, id, sizeof(id), ec); diff --git a/deps/icu-small/source/common/uelement.h b/deps/icu-small/source/common/uelement.h index 9d45f09fb87f65..e4d16afe4e2753 100644 --- a/deps/icu-small/source/common/uelement.h +++ b/deps/icu-small/source/common/uelement.h @@ -46,7 +46,7 @@ typedef union UElement UElement; * An element-equality (boolean) comparison function. * @param e1 An element (object or integer) * @param e2 An element (object or integer) - * @return TRUE if the two elements are equal. + * @return true if the two elements are equal. */ typedef UBool U_CALLCONV UElementsAreEqual(const UElement e1, const UElement e2); diff --git a/deps/icu-small/source/common/uinvchar.cpp b/deps/icu-small/source/common/uinvchar.cpp index ac9716066f22b7..7fce257baf0912 100644 --- a/deps/icu-small/source/common/uinvchar.cpp +++ b/deps/icu-small/source/common/uinvchar.cpp @@ -579,7 +579,7 @@ uprv_ebcdicToLowercaseAscii(char c) { return (char)lowercaseAsciiFromEbcdic[(uint8_t)c]; } -U_INTERNAL uint8_t* U_EXPORT2 +U_CAPI uint8_t* U_EXPORT2 uprv_aestrncpy(uint8_t *dst, const uint8_t *src, int32_t n) { uint8_t *orig_dst = dst; @@ -600,7 +600,7 @@ uprv_aestrncpy(uint8_t *dst, const uint8_t *src, int32_t n) return orig_dst; } -U_INTERNAL uint8_t* U_EXPORT2 +U_CAPI uint8_t* U_EXPORT2 uprv_eastrncpy(uint8_t *dst, const uint8_t *src, int32_t n) { uint8_t *orig_dst = dst; diff --git a/deps/icu-small/source/common/uinvchar.h b/deps/icu-small/source/common/uinvchar.h index a43cfcd98286fe..9b7a9bd114172e 100644 --- a/deps/icu-small/source/common/uinvchar.h +++ b/deps/icu-small/source/common/uinvchar.h @@ -33,11 +33,11 @@ * * @param s Input string pointer. * @param length Length of the string, can be -1 if NUL-terminated. - * @return TRUE if s contains only invariant characters. + * @return true if s contains only invariant characters. * * @internal (ICU 2.8) */ -U_INTERNAL UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uprv_isInvariantString(const char *s, int32_t length); /** @@ -46,11 +46,11 @@ uprv_isInvariantString(const char *s, int32_t length); * * @param s Input string pointer. * @param length Length of the string, can be -1 if NUL-terminated. - * @return TRUE if s contains only invariant characters. + * @return true if s contains only invariant characters. * * @internal (ICU 2.8) */ -U_INTERNAL UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uprv_isInvariantUString(const UChar *s, int32_t length); /** @@ -141,7 +141,7 @@ uprv_isEbcdicAtSign(char c); * Compare two EBCDIC invariant-character strings in ASCII order. * @internal */ -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uprv_compareInvEbcdicAsAscii(const char *s1, const char *s2); /** @@ -161,7 +161,7 @@ uprv_compareInvEbcdicAsAscii(const char *s1, const char *s2); * Converts an EBCDIC invariant character to ASCII. * @internal */ -U_INTERNAL char U_EXPORT2 +U_CAPI char U_EXPORT2 uprv_ebcdicToAscii(char c); /** @@ -181,7 +181,7 @@ uprv_ebcdicToAscii(char c); * Converts an EBCDIC invariant character to lowercase ASCII. * @internal */ -U_INTERNAL char U_EXPORT2 +U_CAPI char U_EXPORT2 uprv_ebcdicToLowercaseAscii(char c); /** @@ -202,7 +202,7 @@ uprv_ebcdicToLowercaseAscii(char c); * @internal * @see uprv_strncpy */ -U_INTERNAL uint8_t* U_EXPORT2 +U_CAPI uint8_t* U_EXPORT2 uprv_aestrncpy(uint8_t *dst, const uint8_t *src, int32_t n); @@ -211,7 +211,7 @@ uprv_aestrncpy(uint8_t *dst, const uint8_t *src, int32_t n); * @internal * @see uprv_strncpy */ -U_INTERNAL uint8_t* U_EXPORT2 +U_CAPI uint8_t* U_EXPORT2 uprv_eastrncpy(uint8_t *dst, const uint8_t *src, int32_t n); diff --git a/deps/icu-small/source/common/uloc.cpp b/deps/icu-small/source/common/uloc.cpp index 0e235d7958ceb1..522f33dbe243a9 100644 --- a/deps/icu-small/source/common/uloc.cpp +++ b/deps/icu-small/source/common/uloc.cpp @@ -50,9 +50,6 @@ #include "uassert.h" #include "charstr.h" -#include -#include /* for sprintf */ - U_NAMESPACE_USE /* ### Declarations **************************************************/ @@ -60,12 +57,6 @@ U_NAMESPACE_USE /* Locale stuff from locid.cpp */ U_CFUNC void locale_set_default(const char *id); U_CFUNC const char *locale_get_default(void); -U_CFUNC int32_t -locale_getKeywords(const char *localeID, - char prev, - char *keywords, int32_t keywordCapacity, - UBool valuesToo, - UErrorCode *status); /* ### Data tables **************************************************/ @@ -601,12 +592,12 @@ compareKeywordStructs(const void * /*context*/, const void *left, const void *ri return uprv_strcmp(leftString, rightString); } -static void -_getKeywords(const char *localeID, - char prev, - ByteSink& sink, - UBool valuesToo, - UErrorCode *status) +U_CFUNC void +ulocimp_getKeywords(const char *localeID, + char prev, + ByteSink& sink, + UBool valuesToo, + UErrorCode *status) { KeywordStruct keywordList[ULOC_MAX_NO_KEYWORDS]; @@ -722,18 +713,18 @@ _getKeywords(const char *localeID, } } -U_CFUNC int32_t -locale_getKeywords(const char *localeID, - char prev, - char *keywords, int32_t keywordCapacity, - UBool valuesToo, - UErrorCode *status) { +U_CAPI int32_t U_EXPORT2 +uloc_getKeywordValue(const char* localeID, + const char* keywordName, + char* buffer, int32_t bufferCapacity, + UErrorCode* status) +{ if (U_FAILURE(*status)) { return 0; } - CheckedArrayByteSink sink(keywords, keywordCapacity); - _getKeywords(localeID, prev, sink, valuesToo, status); + CheckedArrayByteSink sink(buffer, bufferCapacity); + ulocimp_getKeywordValue(localeID, keywordName, sink, status); int32_t reslen = sink.NumberOfBytesAppended(); @@ -744,26 +735,22 @@ locale_getKeywords(const char *localeID, if (sink.Overflowed()) { *status = U_BUFFER_OVERFLOW_ERROR; } else { - u_terminateChars(keywords, keywordCapacity, reslen, status); + u_terminateChars(buffer, bufferCapacity, reslen, status); } return reslen; } -U_CAPI int32_t U_EXPORT2 -uloc_getKeywordValue(const char* localeID, - const char* keywordName, - char* buffer, int32_t bufferCapacity, - UErrorCode* status) +U_CAPI void U_EXPORT2 +ulocimp_getKeywordValue(const char* localeID, + const char* keywordName, + icu::ByteSink& sink, + UErrorCode* status) { - if (buffer != nullptr) { - buffer[0] = '\0'; - } const char* startSearchHere = NULL; const char* nextSeparator = NULL; char keywordNameBuffer[ULOC_KEYWORD_BUFFER_LEN]; char localeKeywordNameBuffer[ULOC_KEYWORD_BUFFER_LEN]; - int32_t result = 0; if(status && U_SUCCESS(*status) && localeID) { char tempBuffer[ULOC_FULLNAME_CAPACITY]; @@ -771,12 +758,12 @@ uloc_getKeywordValue(const char* localeID, if (keywordName == NULL || keywordName[0] == 0) { *status = U_ILLEGAL_ARGUMENT_ERROR; - return 0; + return; } locale_canonKeywordName(keywordNameBuffer, keywordName, status); if(U_FAILURE(*status)) { - return 0; + return; } if (_hasBCP47Extension(localeID)) { @@ -788,7 +775,7 @@ uloc_getKeywordValue(const char* localeID, startSearchHere = locale_getKeywordsStart(tmpLocaleID); if(startSearchHere == NULL) { /* no keywords, return at once */ - return 0; + return; } /* find the first keyword */ @@ -800,7 +787,7 @@ uloc_getKeywordValue(const char* localeID, nextSeparator = uprv_strchr(startSearchHere, '='); if(!nextSeparator) { *status = U_ILLEGAL_ARGUMENT_ERROR; /* key must have =value */ - return 0; + return; } /* strip leading & trailing spaces (TC decided to tolerate these) */ while(*startSearchHere == ' ') { @@ -814,20 +801,20 @@ uloc_getKeywordValue(const char* localeID, /* copy & normalize keyName from locale */ if (startSearchHere == keyValueTail) { *status = U_ILLEGAL_ARGUMENT_ERROR; /* empty keyword name in passed-in locale */ - return 0; + return; } keyValueLen = 0; while (startSearchHere < keyValueTail) { if (!UPRV_ISALPHANUM(*startSearchHere)) { *status = U_ILLEGAL_ARGUMENT_ERROR; /* malformed keyword name */ - return 0; + return; } if (keyValueLen < ULOC_KEYWORD_BUFFER_LEN - 1) { localeKeywordNameBuffer[keyValueLen++] = uprv_tolower(*startSearchHere++); } else { /* keyword name too long for internal buffer */ *status = U_INTERNAL_PROGRAM_ERROR; - return 0; + return; } } localeKeywordNameBuffer[keyValueLen] = 0; /* terminate */ @@ -848,28 +835,20 @@ uloc_getKeywordValue(const char* localeID, /* Now copy the value, but check well-formedness */ if (nextSeparator == keyValueTail) { *status = U_ILLEGAL_ARGUMENT_ERROR; /* empty key value name in passed-in locale */ - return 0; + return; } - keyValueLen = 0; while (nextSeparator < keyValueTail) { if (!UPRV_ISALPHANUM(*nextSeparator) && !UPRV_OK_VALUE_PUNCTUATION(*nextSeparator)) { *status = U_ILLEGAL_ARGUMENT_ERROR; /* malformed key value */ - return 0; - } - if (keyValueLen < bufferCapacity) { - /* Should we lowercase value to return here? Tests expect as-is. */ - buffer[keyValueLen++] = *nextSeparator++; - } else { /* keep advancing so we return correct length in case of overflow */ - keyValueLen++; - nextSeparator++; + return; } + /* Should we lowercase value to return here? Tests expect as-is. */ + sink.Append(nextSeparator++, 1); } - result = u_terminateChars(buffer, bufferCapacity, keyValueLen, status); - return result; + return; } } } - return 0; } U_CAPI int32_t U_EXPORT2 @@ -892,7 +871,6 @@ uloc_setKeywordValue(const char* keywordName, char* startSearchHere = NULL; char* keywordStart = NULL; CharString updatedKeysAndValues; - int32_t updatedKeysAndValuesLen; UBool handledInputKeyAndValue = FALSE; char keyValuePrefix = '@'; @@ -1072,18 +1050,10 @@ uloc_setKeywordValue(const char* keywordName, return bufLen; } - updatedKeysAndValuesLen = updatedKeysAndValues.length(); - /* needLen = length of the part before '@' + length of updated key-value part including '@' */ - needLen = (int32_t)(startSearchHere - buffer) + updatedKeysAndValuesLen; - if(needLen >= bufferCapacity) { - *status = U_BUFFER_OVERFLOW_ERROR; - return needLen; /* no change */ - } - if (updatedKeysAndValuesLen > 0) { - uprv_strncpy(startSearchHere, updatedKeysAndValues.data(), updatedKeysAndValuesLen); - } - buffer[needLen]=0; - return needLen; + // needLen = length of the part before '@' + needLen = (int32_t)(startSearchHere - buffer); + return needLen + updatedKeysAndValues.extract( + startSearchHere, bufferCapacity - needLen, *status); } /* ### ID parsing implementation **************************************************/ @@ -1148,7 +1118,7 @@ uloc_getCurrentLanguageID(const char* oldID){ * * TODO try to use this in Locale */ -static CharString +CharString U_EXPORT2 ulocimp_getLanguage(const char *localeID, const char **pEnd, UErrorCode &status) { @@ -1193,21 +1163,7 @@ ulocimp_getLanguage(const char *localeID, return result; } -U_CFUNC int32_t -ulocimp_getLanguage(const char *localeID, - char *language, int32_t languageCapacity, - const char **pEnd) { - ErrorCode status; - CharString result = ulocimp_getLanguage(localeID, pEnd, status); - if (status.isFailure()) { - return 0; - } - int32_t reslen = result.length(); - uprv_memcpy(language, result.data(), std::min(reslen, languageCapacity)); - return reslen; -} - -static CharString +CharString U_EXPORT2 ulocimp_getScript(const char *localeID, const char **pEnd, UErrorCode &status) { @@ -1241,21 +1197,7 @@ ulocimp_getScript(const char *localeID, return result; } -U_CFUNC int32_t -ulocimp_getScript(const char *localeID, - char *script, int32_t scriptCapacity, - const char **pEnd) { - ErrorCode status; - CharString result = ulocimp_getScript(localeID, pEnd, status); - if (status.isFailure()) { - return 0; - } - int32_t reslen = result.length(); - uprv_memcpy(script, result.data(), std::min(reslen, scriptCapacity)); - return reslen; -} - -static CharString +CharString U_EXPORT2 ulocimp_getCountry(const char *localeID, const char **pEnd, UErrorCode &status) { @@ -1290,29 +1232,15 @@ ulocimp_getCountry(const char *localeID, return result; } -U_CFUNC int32_t -ulocimp_getCountry(const char *localeID, - char *country, int32_t countryCapacity, - const char **pEnd) { - ErrorCode status; - CharString result = ulocimp_getCountry(localeID, pEnd, status); - if (status.isFailure()) { - return 0; - } - int32_t reslen = result.length(); - uprv_memcpy(country, result.data(), std::min(reslen, countryCapacity)); - return reslen; -} - /** * @param needSeparator if true, then add leading '_' if any variants * are added to 'variant' */ static void -_getVariantEx(const char *localeID, - char prev, - ByteSink& sink, - UBool needSeparator) { +_getVariant(const char *localeID, + char prev, + ByteSink& sink, + UBool needSeparator) { UBool hasVariant = FALSE; /* get one or more variant tags and separate them with '_' */ @@ -1353,23 +1281,6 @@ _getVariantEx(const char *localeID, } } -static int32_t -_getVariantEx(const char *localeID, - char prev, - char *variant, int32_t variantCapacity, - UBool needSeparator) { - CheckedArrayByteSink sink(variant, variantCapacity); - _getVariantEx(localeID, prev, sink, needSeparator); - return sink.NumberOfBytesAppended(); -} - -static int32_t -_getVariant(const char *localeID, - char prev, - char *variant, int32_t variantCapacity) { - return _getVariantEx(localeID, prev, variant, variantCapacity, FALSE); -} - /* Keyword enumeration */ typedef struct UKeywordsContext { @@ -1466,9 +1377,6 @@ U_CAPI UEnumeration* U_EXPORT2 uloc_openKeywords(const char* localeID, UErrorCode* status) { - int32_t i=0; - char keywords[256]; - int32_t keywordsCapacity = 256; char tempBuffer[ULOC_FULLNAME_CAPACITY]; const char* tmpLocaleID; @@ -1486,34 +1394,42 @@ uloc_openKeywords(const char* localeID, } /* Skip the language */ - ulocimp_getLanguage(tmpLocaleID, NULL, 0, &tmpLocaleID); + ulocimp_getLanguage(tmpLocaleID, &tmpLocaleID, *status); + if (U_FAILURE(*status)) { + return 0; + } + if(_isIDSeparator(*tmpLocaleID)) { const char *scriptID; /* Skip the script if available */ - ulocimp_getScript(tmpLocaleID+1, NULL, 0, &scriptID); + ulocimp_getScript(tmpLocaleID+1, &scriptID, *status); + if (U_FAILURE(*status)) { + return 0; + } if(scriptID != tmpLocaleID+1) { /* Found optional script */ tmpLocaleID = scriptID; } /* Skip the Country */ if (_isIDSeparator(*tmpLocaleID)) { - ulocimp_getCountry(tmpLocaleID+1, NULL, 0, &tmpLocaleID); - if(_isIDSeparator(*tmpLocaleID)) { - _getVariant(tmpLocaleID+1, *tmpLocaleID, NULL, 0); + ulocimp_getCountry(tmpLocaleID+1, &tmpLocaleID, *status); + if (U_FAILURE(*status)) { + return 0; } } } /* keywords are located after '@' */ if((tmpLocaleID = locale_getKeywordsStart(tmpLocaleID)) != NULL) { - i=locale_getKeywords(tmpLocaleID+1, '@', keywords, keywordsCapacity, FALSE, status); - } - - if(i) { - return uloc_openKeywordList(keywords, i, status); - } else { - return NULL; + CharString keywords; + CharStringByteSink sink(&keywords); + ulocimp_getKeywords(tmpLocaleID+1, '@', sink, FALSE, status); + if (U_FAILURE(*status)) { + return NULL; + } + return uloc_openKeywordList(keywords.data(), keywords.length(), status); } + return NULL; } @@ -1605,7 +1521,7 @@ _canonicalize(const char* localeID, variantSize = -tag.length(); { CharStringByteSink s(&tag); - _getVariantEx(tmpLocaleID+1, *tmpLocaleID, s, FALSE); + _getVariant(tmpLocaleID+1, *tmpLocaleID, s, FALSE); } variantSize += tag.length(); if (variantSize > 0) { @@ -1667,7 +1583,7 @@ _canonicalize(const char* localeID, int32_t posixVariantSize = -tag.length(); { CharStringByteSink s(&tag); - _getVariantEx(tmpLocaleID+1, '@', s, (UBool)(variantSize > 0)); + _getVariant(tmpLocaleID+1, '@', s, (UBool)(variantSize > 0)); } posixVariantSize += tag.length(); if (posixVariantSize > 0) { @@ -1696,7 +1612,7 @@ _canonicalize(const char* localeID, (!separatorIndicator || separatorIndicator > keywordAssign)) { sink.Append("@", 1); ++fieldCount; - _getKeywords(tmpLocaleID+1, '@', sink, TRUE, err); + ulocimp_getKeywords(tmpLocaleID+1, '@', sink, TRUE, err); } } } @@ -1745,7 +1661,6 @@ uloc_getLanguage(const char* localeID, UErrorCode* err) { /* uloc_getLanguage will return a 2 character iso-639 code if one exists. *CWB*/ - int32_t i=0; if (err==NULL || U_FAILURE(*err)) { return 0; @@ -1755,8 +1670,7 @@ uloc_getLanguage(const char* localeID, localeID=uloc_getDefault(); } - i=ulocimp_getLanguage(localeID, language, languageCapacity, NULL); - return u_terminateChars(language, languageCapacity, i, err); + return ulocimp_getLanguage(localeID, NULL, *err).extract(language, languageCapacity, *err); } U_CAPI int32_t U_EXPORT2 @@ -1765,8 +1679,6 @@ uloc_getScript(const char* localeID, int32_t scriptCapacity, UErrorCode* err) { - int32_t i=0; - if(err==NULL || U_FAILURE(*err)) { return 0; } @@ -1776,11 +1688,15 @@ uloc_getScript(const char* localeID, } /* skip the language */ - ulocimp_getLanguage(localeID, NULL, 0, &localeID); + ulocimp_getLanguage(localeID, &localeID, *err); + if (U_FAILURE(*err)) { + return 0; + } + if(_isIDSeparator(*localeID)) { - i=ulocimp_getScript(localeID+1, script, scriptCapacity, NULL); + return ulocimp_getScript(localeID+1, NULL, *err).extract(script, scriptCapacity, *err); } - return u_terminateChars(script, scriptCapacity, i, err); + return u_terminateChars(script, scriptCapacity, 0, err); } U_CAPI int32_t U_EXPORT2 @@ -1789,8 +1705,6 @@ uloc_getCountry(const char* localeID, int32_t countryCapacity, UErrorCode* err) { - int32_t i=0; - if(err==NULL || U_FAILURE(*err)) { return 0; } @@ -1800,20 +1714,27 @@ uloc_getCountry(const char* localeID, } /* Skip the language */ - ulocimp_getLanguage(localeID, NULL, 0, &localeID); + ulocimp_getLanguage(localeID, &localeID, *err); + if (U_FAILURE(*err)) { + return 0; + } + if(_isIDSeparator(*localeID)) { const char *scriptID; /* Skip the script if available */ - ulocimp_getScript(localeID+1, NULL, 0, &scriptID); + ulocimp_getScript(localeID+1, &scriptID, *err); + if (U_FAILURE(*err)) { + return 0; + } if(scriptID != localeID+1) { /* Found optional script */ localeID = scriptID; } if(_isIDSeparator(*localeID)) { - i=ulocimp_getCountry(localeID+1, country, countryCapacity, NULL); + return ulocimp_getCountry(localeID+1, NULL, *err).extract(country, countryCapacity, *err); } } - return u_terminateChars(country, countryCapacity, i, err); + return u_terminateChars(country, countryCapacity, 0, err); } U_CAPI int32_t U_EXPORT2 @@ -1840,11 +1761,18 @@ uloc_getVariant(const char* localeID, } /* Skip the language */ - ulocimp_getLanguage(tmpLocaleID, NULL, 0, &tmpLocaleID); + ulocimp_getLanguage(tmpLocaleID, &tmpLocaleID, *err); + if (U_FAILURE(*err)) { + return 0; + } + if(_isIDSeparator(*tmpLocaleID)) { const char *scriptID; /* Skip the script if available */ - ulocimp_getScript(tmpLocaleID+1, NULL, 0, &scriptID); + ulocimp_getScript(tmpLocaleID+1, &scriptID, *err); + if (U_FAILURE(*err)) { + return 0; + } if(scriptID != tmpLocaleID+1) { /* Found optional script */ tmpLocaleID = scriptID; @@ -1852,7 +1780,10 @@ uloc_getVariant(const char* localeID, /* Skip the Country */ if (_isIDSeparator(*tmpLocaleID)) { const char *cntryID; - ulocimp_getCountry(tmpLocaleID+1, NULL, 0, &cntryID); + ulocimp_getCountry(tmpLocaleID+1, &cntryID, *err); + if (U_FAILURE(*err)) { + return 0; + } if (cntryID != tmpLocaleID+1) { /* Found optional country */ tmpLocaleID = cntryID; @@ -1862,18 +1793,24 @@ uloc_getVariant(const char* localeID, if (tmpLocaleID != cntryID && _isIDSeparator(tmpLocaleID[1])) { tmpLocaleID++; } - i=_getVariant(tmpLocaleID+1, *tmpLocaleID, variant, variantCapacity); + + CheckedArrayByteSink sink(variant, variantCapacity); + _getVariant(tmpLocaleID+1, *tmpLocaleID, sink, FALSE); + + i = sink.NumberOfBytesAppended(); + + if (U_FAILURE(*err)) { + return i; + } + + if (sink.Overflowed()) { + *err = U_BUFFER_OVERFLOW_ERROR; + return i; + } } } } - /* removed by weiv. We don't want to handle POSIX variants anymore. Use canonicalization function */ - /* if we do not have a variant tag yet then try a POSIX variant after '@' */ -/* - if(!haveVariant && (localeID=uprv_strrchr(localeID, '@'))!=NULL) { - i=_getVariant(localeID+1, '@', variant, variantCapacity); - } -*/ return u_terminateChars(variant, variantCapacity, i, err); } @@ -1905,7 +1842,7 @@ uloc_getName(const char* localeID, return reslen; } -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_getName(const char* localeID, ByteSink& sink, UErrorCode* err) @@ -1941,7 +1878,7 @@ uloc_getBaseName(const char* localeID, return reslen; } -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_getBaseName(const char* localeID, ByteSink& sink, UErrorCode* err) @@ -1977,7 +1914,7 @@ uloc_canonicalize(const char* localeID, return reslen; } -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_canonicalize(const char* localeID, ByteSink& sink, UErrorCode* err) @@ -2058,22 +1995,22 @@ uloc_getLCID(const char* localeID) // uprv_convertToLCID does not support keywords other than collation. // Remove all keywords except collation. int32_t len; - char collVal[ULOC_KEYWORDS_CAPACITY]; char tmpLocaleID[ULOC_FULLNAME_CAPACITY]; - len = uloc_getKeywordValue(localeID, "collation", collVal, - UPRV_LENGTHOF(collVal) - 1, &status); - - if (U_SUCCESS(status) && len > 0) { - collVal[len] = 0; + CharString collVal; + { + CharStringByteSink sink(&collVal); + ulocimp_getKeywordValue(localeID, "collation", sink, &status); + } + if (U_SUCCESS(status) && !collVal.isEmpty()) { len = uloc_getBaseName(localeID, tmpLocaleID, UPRV_LENGTHOF(tmpLocaleID) - 1, &status); if (U_SUCCESS(status) && len > 0) { tmpLocaleID[len] = 0; - len = uloc_setKeywordValue("collation", collVal, tmpLocaleID, + len = uloc_setKeywordValue("collation", collVal.data(), tmpLocaleID, UPRV_LENGTHOF(tmpLocaleID) - len - 1, &status); if (U_SUCCESS(status) && len > 0) { diff --git a/deps/icu-small/source/common/uloc_tag.cpp b/deps/icu-small/source/common/uloc_tag.cpp index 3bdeddbe066d96..d2d938753182d8 100644 --- a/deps/icu-small/source/common/uloc_tag.cpp +++ b/deps/icu-small/source/common/uloc_tag.cpp @@ -15,6 +15,7 @@ #include "unicode/uenum.h" #include "unicode/uloc.h" #include "ustr_imp.h" +#include "bytesinkutil.h" #include "charstr.h" #include "cmemory.h" #include "cstring.h" @@ -53,7 +54,7 @@ typedef struct ULanguageTag { VariantListEntry *variants; ExtensionListEntry *extensions; const char *privateuse; - const char *grandfathered; + const char *legacy; } ULanguageTag; #define MINLEN 2 @@ -85,8 +86,9 @@ static const char LOCALE_TYPE_YES[] = "yes"; Updated on 2018-09-12 from https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry . - This table has 2 parts. The parts for Grandfathered tags is generated by the - following scripts from the IANA language tag registry. + This table has 2 parts. The part for + legacy language tags (marked as “Type: grandfathered” in BCP 47) + is generated by the following scripts from the IANA language tag registry. curl https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry |\ egrep -A 7 'Type: grandfathered' | \ @@ -100,8 +102,8 @@ static const char LOCALE_TYPE_YES[] = "yes"; values. They may have to be removed for the strict BCP 47 compliance. */ -static const char* const GRANDFATHERED[] = { -/* grandfathered preferred */ +static const char* const LEGACY[] = { +/* legacy preferred */ "art-lojban", "jbo", "en-gb-oed", "en-gb-oxendict", "i-ami", "ami", @@ -124,7 +126,7 @@ static const char* const GRANDFATHERED[] = { "zh-min-nan", "nan", "zh-xiang", "hsn", - // Grandfathered tags with no preferred value in the IANA + // Legacy tags with no preferred value in the IANA // registry. Kept for now for the backward compatibility // because ICU has mapped them this way. "cel-gaulish", "xtg-x-cel-gaulish", @@ -346,7 +348,7 @@ ultag_getPrivateUse(const ULanguageTag* langtag); #if 0 static const char* -ultag_getGrandfathered(const ULanguageTag* langtag); +ultag_getLegacy(const ULanguageTag* langtag); #endif U_NAMESPACE_BEGIN @@ -986,7 +988,7 @@ _initializeULanguageTag(ULanguageTag* langtag) { langtag->variants = NULL; langtag->extensions = NULL; - langtag->grandfathered = EMPTY; + langtag->legacy = EMPTY; langtag->privateuse = EMPTY; } @@ -1268,35 +1270,17 @@ _appendKeywordsToLanguageTag(const char* localeID, icu::ByteSink& sink, UBool st UBool isBcpUExt; while (TRUE) { - icu::CharString buf; key = uenum_next(keywordEnum.getAlias(), NULL, status); if (key == NULL) { break; } - char* buffer; - int32_t resultCapacity = ULOC_KEYWORD_AND_VALUES_CAPACITY; - - for (;;) { - buffer = buf.getAppendBuffer( - /*minCapacity=*/resultCapacity, - /*desiredCapacityHint=*/resultCapacity, - resultCapacity, - tmpStatus); - - if (U_FAILURE(tmpStatus)) { - break; - } - len = uloc_getKeywordValue( - localeID, key, buffer, resultCapacity, &tmpStatus); - - if (tmpStatus != U_BUFFER_OVERFLOW_ERROR) { - break; - } - - resultCapacity = len; - tmpStatus = U_ZERO_ERROR; + icu::CharString buf; + { + icu::CharStringByteSink sink(&buf); + ulocimp_getKeywordValue(localeID, key, sink, &tmpStatus); } + len = buf.length(); if (U_FAILURE(tmpStatus)) { if (tmpStatus == U_MEMORY_ALLOCATION_ERROR) { @@ -1312,11 +1296,6 @@ _appendKeywordsToLanguageTag(const char* localeID, icu::ByteSink& sink, UBool st continue; } - buf.append(buffer, len, tmpStatus); - if (tmpStatus == U_STRING_NOT_TERMINATED_WARNING) { - tmpStatus = U_ZERO_ERROR; // Terminators provided by CharString. - } - keylen = (int32_t)uprv_strlen(key); isBcpUExt = (keylen > 1); @@ -1395,32 +1374,18 @@ _appendKeywordsToLanguageTag(const char* localeID, icu::ByteSink& sink, UBool st no known mapping. This implementation normalizes the value to lower case */ - icu::CharString* extBuf = extBufPool.create(); + icu::CharString* extBuf = extBufPool.create(buf, tmpStatus); + if (extBuf == nullptr) { *status = U_MEMORY_ALLOCATION_ERROR; break; } - int32_t bcpValueLen = static_cast(uprv_strlen(bcpValue)); - int32_t resultCapacity; - char* pExtBuf = extBuf->getAppendBuffer( - /*minCapacity=*/bcpValueLen, - /*desiredCapacityHint=*/bcpValueLen, - resultCapacity, - tmpStatus); - if (U_FAILURE(tmpStatus)) { - *status = tmpStatus; - break; - } - - uprv_strcpy(pExtBuf, bcpValue); - T_CString_toLowerCase(pExtBuf); - - extBuf->append(pExtBuf, bcpValueLen, tmpStatus); if (U_FAILURE(tmpStatus)) { *status = tmpStatus; break; } + T_CString_toLowerCase(extBuf->data()); bcpValue = extBuf->data(); } } else { @@ -2023,11 +1988,12 @@ _appendPrivateuseToLanguageTag(const char* localeID, icu::ByteSink& sink, UBool #define PRIV 0x0080 /** - * Ticket #12705 - Visual Studio 2015 Update 3 contains a new code optimizer which has problems optimizing - * this function. (See https://blogs.msdn.microsoft.com/vcblog/2016/05/04/new-code-optimizer/ ) - * As a workaround, we will turn off optimization just for this function on VS2015 Update 3 and above. + * Ticket #12705 - The optimizer in Visual Studio 2015 Update 3 has problems optimizing this function. + * As a work-around, optimization is disabled for this function on VS2015 and VS2017. + * This work-around should be removed once the following versions of Visual Studio are no + * longer supported: All versions of VS2015/VS2017, and versions of VS2019 below 16.4. */ -#if (defined(_MSC_VER) && (_MSC_VER >= 1900) && defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190024210)) +#if defined(_MSC_VER) && (_MSC_VER >= 1900) && (_MSC_VER < 1924) #pragma optimize( "", off ) #endif @@ -2042,7 +2008,7 @@ ultag_parse(const char* tag, int32_t tagLen, int32_t* parsedLen, UErrorCode* sta char *pExtValueSubtag, *pExtValueSubtagEnd; int32_t i; UBool privateuseVar = FALSE; - int32_t grandfatheredLen = 0; + int32_t legacyLen = 0; if (parsedLen != NULL) { *parsedLen = 0; @@ -2082,25 +2048,25 @@ ultag_parse(const char* tag, int32_t tagLen, int32_t* parsedLen, UErrorCode* sta } size_t parsedLenDelta = 0; - // Grandfathered tag will be consider together. Grandfathered tag with intervening + // Legacy tag will be consider together. Legacy tag with intervening // script and region such as art-DE-lojban or art-Latn-lojban won't be // matched. - /* check if the tag is grandfathered */ - for (i = 0; i < UPRV_LENGTHOF(GRANDFATHERED); i += 2) { - int32_t checkGrandfatheredLen = static_cast(uprv_strlen(GRANDFATHERED[i])); - if (tagLen < checkGrandfatheredLen) { + /* check if the tag is legacy */ + for (i = 0; i < UPRV_LENGTHOF(LEGACY); i += 2) { + int32_t checkLegacyLen = static_cast(uprv_strlen(LEGACY[i])); + if (tagLen < checkLegacyLen) { continue; } - if (tagLen > checkGrandfatheredLen && tagBuf[checkGrandfatheredLen] != '-') { + if (tagLen > checkLegacyLen && tagBuf[checkLegacyLen] != '-') { // make sure next char is '-'. continue; } - if (uprv_strnicmp(GRANDFATHERED[i], tagBuf, checkGrandfatheredLen) == 0) { + if (uprv_strnicmp(LEGACY[i], tagBuf, checkLegacyLen) == 0) { int32_t newTagLength; - grandfatheredLen = checkGrandfatheredLen; /* back up for output parsedLen */ - int32_t replacementLen = static_cast(uprv_strlen(GRANDFATHERED[i+1])); - newTagLength = replacementLen + tagLen - checkGrandfatheredLen; + legacyLen = checkLegacyLen; /* back up for output parsedLen */ + int32_t replacementLen = static_cast(uprv_strlen(LEGACY[i+1])); + newTagLength = replacementLen + tagLen - checkLegacyLen; if (tagLen < newTagLength) { uprv_free(tagBuf); tagBuf = (char*)uprv_malloc(newTagLength + 1); @@ -2111,16 +2077,16 @@ ultag_parse(const char* tag, int32_t tagLen, int32_t* parsedLen, UErrorCode* sta t->buf = tagBuf; tagLen = newTagLength; } - parsedLenDelta = checkGrandfatheredLen - replacementLen; - uprv_strcpy(t->buf, GRANDFATHERED[i + 1]); - if (checkGrandfatheredLen != tagLen) { - uprv_strcpy(t->buf + replacementLen, tag + checkGrandfatheredLen); + parsedLenDelta = checkLegacyLen - replacementLen; + uprv_strcpy(t->buf, LEGACY[i + 1]); + if (checkLegacyLen != tagLen) { + uprv_strcpy(t->buf + replacementLen, tag + checkLegacyLen); } break; } } - if (grandfatheredLen == 0) { + if (legacyLen == 0) { for (i = 0; i < UPRV_LENGTHOF(REDUNDANT); i += 2) { const char* redundantTag = REDUNDANT[i]; size_t redundantTagLen = uprv_strlen(redundantTag); @@ -2440,10 +2406,8 @@ ultag_parse(const char* tag, int32_t tagLen, int32_t* parsedLen, UErrorCode* sta return t.orphan(); } -/** -* Ticket #12705 - Turn optimization back on. -*/ -#if (defined(_MSC_VER) && (_MSC_VER >= 1900) && defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190024210)) +// Ticket #12705 - Turn optimization back on. +#if defined(_MSC_VER) && (_MSC_VER >= 1900) && (_MSC_VER < 1924) #pragma optimize( "", on ) #endif @@ -2608,8 +2572,8 @@ ultag_getPrivateUse(const ULanguageTag* langtag) { #if 0 static const char* -ultag_getGrandfathered(const ULanguageTag* langtag) { - return langtag->grandfathered; +ultag_getLegacy(const ULanguageTag* langtag) { + return langtag->legacy; } #endif @@ -2720,14 +2684,17 @@ ulocimp_toLanguageTag(const char* localeID, key = uenum_next(kwdEnum.getAlias(), &len, &tmpStatus); if (len == 1 && *key == PRIVATEUSE) { - char buf[ULOC_KEYWORD_AND_VALUES_CAPACITY]; - buf[0] = PRIVATEUSE; - buf[1] = SEP; - len = uloc_getKeywordValue(localeID, key, &buf[2], sizeof(buf) - 2, &tmpStatus); + icu::CharString buf; + { + icu::CharStringByteSink sink(&buf); + ulocimp_getKeywordValue(localeID, key, sink, &tmpStatus); + } if (U_SUCCESS(tmpStatus)) { - if (ultag_isPrivateuseValueSubtags(&buf[2], len)) { + if (ultag_isPrivateuseValueSubtags(buf.data(), buf.length())) { /* return private use only tag */ - sink.Append(buf, len + 2); + static const char PREFIX[] = { PRIVATEUSE, SEP }; + sink.Append(PREFIX, sizeof(PREFIX)); + sink.Append(buf.data(), buf.length()); done = TRUE; } else if (strict) { *status = U_ILLEGAL_ARGUMENT_ERROR; diff --git a/deps/icu-small/source/common/ulocimp.h b/deps/icu-small/source/common/ulocimp.h index 98b95dddfe75bc..a686759f32e3e1 100644 --- a/deps/icu-small/source/common/ulocimp.h +++ b/deps/icu-small/source/common/ulocimp.h @@ -13,6 +13,8 @@ #include "unicode/bytestream.h" #include "unicode/uloc.h" +#include "charstr.h" + /** * Create an iterator over the specified keywords list * @param keywordList double-null terminated list. Will be copied. @@ -38,7 +40,7 @@ uloc_getTableStringWithFallback( int32_t *pLength, UErrorCode *pErrorCode); -/*returns TRUE if a is an ID separator FALSE otherwise*/ +/*returns true if a is an ID separator false otherwise*/ #define _isIDSeparator(a) (a == '_' || a == '-') U_CFUNC const char* @@ -47,42 +49,55 @@ uloc_getCurrentCountryID(const char* oldID); U_CFUNC const char* uloc_getCurrentLanguageID(const char* oldID); -U_CFUNC int32_t +U_CFUNC void +ulocimp_getKeywords(const char *localeID, + char prev, + icu::ByteSink& sink, + UBool valuesToo, + UErrorCode *status); + +icu::CharString U_EXPORT2 ulocimp_getLanguage(const char *localeID, - char *language, int32_t languageCapacity, - const char **pEnd); + const char **pEnd, + UErrorCode &status); -U_CFUNC int32_t +icu::CharString U_EXPORT2 ulocimp_getScript(const char *localeID, - char *script, int32_t scriptCapacity, - const char **pEnd); + const char **pEnd, + UErrorCode &status); -U_CFUNC int32_t +icu::CharString U_EXPORT2 ulocimp_getCountry(const char *localeID, - char *country, int32_t countryCapacity, - const char **pEnd); + const char **pEnd, + UErrorCode &status); -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_getName(const char* localeID, icu::ByteSink& sink, UErrorCode* err); -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_getBaseName(const char* localeID, icu::ByteSink& sink, UErrorCode* err); -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_canonicalize(const char* localeID, icu::ByteSink& sink, UErrorCode* err); +U_CAPI void U_EXPORT2 +ulocimp_getKeywordValue(const char* localeID, + const char* keywordName, + icu::ByteSink& sink, + UErrorCode* status); + /** * Writes a well-formed language tag for this locale ID. * - * **Note**: When `strict` is FALSE, any locale fields which do not satisfy the + * **Note**: When `strict` is false, any locale fields which do not satisfy the * BCP47 syntax requirement will be omitted from the result. When `strict` is - * TRUE, this function sets U_ILLEGAL_ARGUMENT_ERROR to the `err` if any locale + * true, this function sets U_ILLEGAL_ARGUMENT_ERROR to the `err` if any locale * fields do not satisfy the BCP47 syntax requirement. * * @param localeID the input locale ID @@ -96,7 +111,7 @@ ulocimp_canonicalize(const char* localeID, * * @internal ICU 64 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_toLanguageTag(const char* localeID, icu::ByteSink& sink, UBool strict, @@ -107,13 +122,17 @@ ulocimp_toLanguageTag(const char* localeID, * If the specified language tag contains any ill-formed subtags, * the first such subtag and all following subtags are ignored. *

- * This implements the 'Language-Tag' production of BCP47, and so - * supports grandfathered (regular and irregular) as well as private - * use language tags. Private use tags are represented as 'x-whatever', - * and grandfathered tags are converted to their canonical replacements - * where they exist. Note that a few grandfathered tags have no modern - * replacement, these will be converted using the fallback described in + * This implements the 'Language-Tag' production of BCP 47, and so + * supports legacy language tags (marked as “Type: grandfathered” in BCP 47) + * (regular and irregular) as well as private use language tags. + * + * Private use tags are represented as 'x-whatever', + * and legacy tags are converted to their canonical replacements where they exist. + * + * Note that a few legacy tags have no modern replacement; + * these will be converted using the fallback described in * the first paragraph, so some information might be lost. + * * @param langtag the input BCP47 language tag. * @param tagLen the length of langtag, or -1 to call uprv_strlen(). * @param sink the output sink receiving a locale ID for the @@ -135,7 +154,7 @@ ulocimp_forLanguageTag(const char* langtag, * Get the region to use for supplemental data lookup. Uses * (1) any region specified by locale tag "rg"; if none then * (2) any unicode_region_tag in the locale ID; if none then - * (3) if inferRegion is TRUE, the region suggested by + * (3) if inferRegion is true, the region suggested by * getLikelySubtags on the localeID. * If no region is found, returns length 0. * @@ -143,7 +162,7 @@ ulocimp_forLanguageTag(const char* langtag, * The complete locale ID (with keywords) from which * to get the region to use for supplemental data. * @param inferRegion - * If TRUE, will try to infer region from localeID if + * If true, will try to infer region from localeID if * no other region is found. * @param region * Buffer in which to put the region ID found; should @@ -189,7 +208,7 @@ ulocimp_getRegionForSupplementalData(const char *localeID, UBool inferRegion, * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR. * @internal ICU 64 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_addLikelySubtags(const char* localeID, icu::ByteSink& sink, UErrorCode* err); @@ -223,7 +242,7 @@ ulocimp_addLikelySubtags(const char* localeID, * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR. * @internal ICU 64 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ulocimp_minimizeSubtags(const char* localeID, icu::ByteSink& sink, UErrorCode* err); @@ -279,4 +298,10 @@ ulocimp_toBcpType(const char* key, const char* type, UBool* isKnownKey, UBool* i U_CFUNC const char* ulocimp_toLegacyType(const char* key, const char* type, UBool* isKnownKey, UBool* isSpecialType); +/* Function for testing purpose */ +U_CAPI const char* const* ulocimp_getKnownCanonicalizedLocaleForTest(int32_t* length); + +// Return true if the value is already canonicalized. +U_CAPI bool ulocimp_isCanonicalizedLocaleForTest(const char* localeName); + #endif diff --git a/deps/icu-small/source/common/umutex.h b/deps/icu-small/source/common/umutex.h index 7588bcc5d9aed6..57955353d0d6ff 100644 --- a/deps/icu-small/source/common/umutex.h +++ b/deps/icu-small/source/common/umutex.h @@ -262,13 +262,13 @@ class U_COMMON_API UMutex { * the global ICU mutex. Recursive locks are an error * and may cause a deadlock on some platforms. */ -U_INTERNAL void U_EXPORT2 umtx_lock(UMutex* mutex); +U_CAPI void U_EXPORT2 umtx_lock(UMutex* mutex); /* Unlock a mutex. * @param mutex The given mutex to be unlocked. Pass NULL to specify * the global ICU mutex. */ -U_INTERNAL void U_EXPORT2 umtx_unlock (UMutex* mutex); +U_CAPI void U_EXPORT2 umtx_unlock (UMutex* mutex); U_NAMESPACE_END diff --git a/deps/icu-small/source/common/unicode/appendable.h b/deps/icu-small/source/common/unicode/appendable.h index 4beacaf6583620..fc99254de14e58 100644 --- a/deps/icu-small/source/common/unicode/appendable.h +++ b/deps/icu-small/source/common/unicode/appendable.h @@ -45,7 +45,7 @@ class UnicodeString; * * The methods do not take UErrorCode parameters. * If an error occurs (e.g., out-of-memory), - * in addition to returning FALSE from failing operations, + * in addition to returning false from failing operations, * the implementation must prevent unexpected behavior (e.g., crashes) * from further calls and should make the error condition available separately * (e.g., store a UErrorCode, make/keep a UnicodeString bogus). @@ -62,7 +62,7 @@ class U_COMMON_API Appendable : public UObject { /** * Appends a 16-bit code unit. * @param c code unit - * @return TRUE if the operation succeeded + * @return true if the operation succeeded * @stable ICU 4.8 */ virtual UBool appendCodeUnit(char16_t c) = 0; @@ -71,7 +71,7 @@ class U_COMMON_API Appendable : public UObject { * Appends a code point. * The default implementation calls appendCodeUnit(char16_t) once or twice. * @param c code point 0..0x10ffff - * @return TRUE if the operation succeeded + * @return true if the operation succeeded * @stable ICU 4.8 */ virtual UBool appendCodePoint(UChar32 c); @@ -81,7 +81,7 @@ class U_COMMON_API Appendable : public UObject { * The default implementation calls appendCodeUnit(char16_t) for each code unit. * @param s string, must not be NULL if length!=0 * @param length string length, or -1 if NUL-terminated - * @return TRUE if the operation succeeded + * @return true if the operation succeeded * @stable ICU 4.8 */ virtual UBool appendString(const char16_t *s, int32_t length); @@ -90,9 +90,9 @@ class U_COMMON_API Appendable : public UObject { * Tells the object that the caller is going to append roughly * appendCapacity char16_ts. A subclass might use this to pre-allocate * a larger buffer if necessary. - * The default implementation does nothing. (It always returns TRUE.) + * The default implementation does nothing. (It always returns true.) * @param appendCapacity estimated number of char16_ts that will be appended - * @return TRUE if the operation succeeded + * @return true if the operation succeeded * @stable ICU 4.8 */ virtual UBool reserveAppendCapacity(int32_t appendCapacity); @@ -171,7 +171,7 @@ class U_COMMON_API UnicodeStringAppendable : public Appendable { /** * Appends a 16-bit code unit to the string. * @param c code unit - * @return TRUE if the operation succeeded + * @return true if the operation succeeded * @stable ICU 4.8 */ virtual UBool appendCodeUnit(char16_t c); @@ -179,7 +179,7 @@ class U_COMMON_API UnicodeStringAppendable : public Appendable { /** * Appends a code point to the string. * @param c code point 0..0x10ffff - * @return TRUE if the operation succeeded + * @return true if the operation succeeded * @stable ICU 4.8 */ virtual UBool appendCodePoint(UChar32 c); @@ -188,7 +188,7 @@ class U_COMMON_API UnicodeStringAppendable : public Appendable { * Appends a string to the UnicodeString. * @param s string, must not be NULL if length!=0 * @param length string length, or -1 if NUL-terminated - * @return TRUE if the operation succeeded + * @return true if the operation succeeded * @stable ICU 4.8 */ virtual UBool appendString(const char16_t *s, int32_t length); @@ -197,7 +197,7 @@ class U_COMMON_API UnicodeStringAppendable : public Appendable { * Tells the UnicodeString that the caller is going to append roughly * appendCapacity char16_ts. * @param appendCapacity estimated number of char16_ts that will be appended - * @return TRUE if the operation succeeded + * @return true if the operation succeeded * @stable ICU 4.8 */ virtual UBool reserveAppendCapacity(int32_t appendCapacity); diff --git a/deps/icu-small/source/common/unicode/brkiter.h b/deps/icu-small/source/common/unicode/brkiter.h index b944497345479b..9bba5fcccc319d 100644 --- a/deps/icu-small/source/common/unicode/brkiter.h +++ b/deps/icu-small/source/common/unicode/brkiter.h @@ -564,7 +564,7 @@ class U_COMMON_API BreakIterator : public UObject { * BreakIterator::createXXXInstance to avoid undefined behavior. * @param key the registry key returned by a previous call to registerInstance * @param status the in/out status code, no special meanings are assigned - * @return TRUE if the iterator for the key was successfully unregistered + * @return true if the iterator for the key was successfully unregistered * @stable ICU 2.4 */ static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status); @@ -655,7 +655,7 @@ class U_COMMON_API BreakIterator : public UObject { inline UBool BreakIterator::isBufferClone() { - return FALSE; + return false; } #endif /* U_HIDE_DEPRECATED_API */ diff --git a/deps/icu-small/source/common/unicode/bytestream.h b/deps/icu-small/source/common/unicode/bytestream.h index 33505a34299818..73d498397c744c 100644 --- a/deps/icu-small/source/common/unicode/bytestream.h +++ b/deps/icu-small/source/common/unicode/bytestream.h @@ -197,7 +197,7 @@ class U_COMMON_API CheckedArrayByteSink : public ByteSink { * Returns the sink to its original state, without modifying the buffer. * Useful for reusing both the buffer and the sink for multiple streams. * Resets the state to NumberOfBytesWritten()=NumberOfBytesAppended()=0 - * and Overflowed()=FALSE. + * and Overflowed()=false. * @return *this * @stable ICU 4.6 */ @@ -236,7 +236,7 @@ class U_COMMON_API CheckedArrayByteSink : public ByteSink { /** * Returns true if any bytes were discarded, i.e., if there was an * attempt to write more than 'capacity' bytes. - * @return TRUE if more than 'capacity' bytes were Append()ed + * @return true if more than 'capacity' bytes were Append()ed * @stable ICU 4.2 */ UBool Overflowed() const { return overflowed_; } diff --git a/deps/icu-small/source/common/unicode/bytestrie.h b/deps/icu-small/source/common/unicode/bytestrie.h index 51405f64a10e64..85f802df420262 100644 --- a/deps/icu-small/source/common/unicode/bytestrie.h +++ b/deps/icu-small/source/common/unicode/bytestrie.h @@ -97,14 +97,13 @@ class U_COMMON_API BytesTrie : public UMemory { return *this; } -#ifndef U_HIDE_DRAFT_API /** * Returns the state of this trie as a 64-bit integer. * The state value is never 0. * * @return opaque state value * @see resetToState64 - * @draft ICU 65 + * @stable ICU 65 */ uint64_t getState64() const { return (static_cast(remainingMatchLength_ + 2) << kState64RemainingShift) | @@ -123,14 +122,13 @@ class U_COMMON_API BytesTrie : public UMemory { * @see getState64 * @see resetToState * @see reset - * @draft ICU 65 + * @stable ICU 65 */ BytesTrie &resetToState64(uint64_t state) { remainingMatchLength_ = static_cast(state >> kState64RemainingShift) - 2; pos_ = bytes_ + (state & kState64PosMask); return *this; } -#endif /* U_HIDE_DRAFT_API */ /** * BytesTrie state object, for saving a trie's current state @@ -253,16 +251,16 @@ class U_COMMON_API BytesTrie : public UMemory { /** * Determines whether all byte sequences reachable from the current state * map to the same value. - * @param uniqueValue Receives the unique value, if this function returns TRUE. + * @param uniqueValue Receives the unique value, if this function returns true. * (output-only) - * @return TRUE if all byte sequences reachable from the current state + * @return true if all byte sequences reachable from the current state * map to the same value. * @stable ICU 4.8 */ inline UBool hasUniqueValue(int32_t &uniqueValue) const { const uint8_t *pos=pos_; // Skip the rest of a pending linear-match node. - return pos!=NULL && findUniqueValue(pos+remainingMatchLength_+1, FALSE, uniqueValue); + return pos!=NULL && findUniqueValue(pos+remainingMatchLength_+1, false, uniqueValue); } /** @@ -321,7 +319,7 @@ class U_COMMON_API BytesTrie : public UMemory { Iterator &reset(); /** - * @return TRUE if there are more elements. + * @return true if there are more elements. * @stable ICU 4.8 */ UBool hasNext() const; @@ -337,7 +335,7 @@ class U_COMMON_API BytesTrie : public UMemory { * pass the U_SUCCESS() test, or else the function returns * immediately. Check for U_FAILURE() on output or use with * function chaining. (See User Guide for details.) - * @return TRUE if there is another element. + * @return true if there is another element. * @stable ICU 4.8 */ UBool next(UErrorCode &errorCode); diff --git a/deps/icu-small/source/common/unicode/bytestriebuilder.h b/deps/icu-small/source/common/unicode/bytestriebuilder.h index e58f18755ef959..eafe5a28c3ef05 100644 --- a/deps/icu-small/source/common/unicode/bytestriebuilder.h +++ b/deps/icu-small/source/common/unicode/bytestriebuilder.h @@ -101,9 +101,10 @@ class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder { * Multiple calls to buildStringPiece() return StringPieces referring to the * builder's same byte array, without rebuilding. * If buildStringPiece() is called after build(), the trie will be - * re-serialized into a new array. - * If build() is called after buildStringPiece(), the trie object will become - * the owner of the previously returned array. + * re-serialized into a new array (because build() passes on ownership). + * If build() is called after buildStringPiece(), the trie object returned + * by build() will become the owner of the underlying string for the + * previously returned StringPiece. * After clear() has been called, a new array will be used as well. * @param buildOption Build option, see UStringTrieBuildOption. * @param errorCode Standard ICU error code. Its input value must @@ -139,7 +140,7 @@ class U_COMMON_API BytesTrieBuilder : public StringTrieBuilder { virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t count) const; virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const; - virtual UBool matchNodesCanHaveValues() const { return FALSE; } + virtual UBool matchNodesCanHaveValues() const { return false; } virtual int32_t getMaxBranchLinearSubNodeLength() const { return BytesTrie::kMaxBranchLinearSubNodeLength; } virtual int32_t getMinLinearMatch() const { return BytesTrie::kMinLinearMatch; } diff --git a/deps/icu-small/source/common/unicode/caniter.h b/deps/icu-small/source/common/unicode/caniter.h index 87c946c2b4db56..8ba4cc7daad3c1 100644 --- a/deps/icu-small/source/common/unicode/caniter.h +++ b/deps/icu-small/source/common/unicode/caniter.h @@ -25,11 +25,11 @@ */ /** Should permutation skip characters with combining class zero - * Should be either TRUE or FALSE. This is a compile time option + * Should be either true or false. This is a compile time option * @stable ICU 2.4 */ #ifndef CANITER_SKIP_ZEROES -#define CANITER_SKIP_ZEROES TRUE +#define CANITER_SKIP_ZEROES true #endif U_NAMESPACE_BEGIN diff --git a/deps/icu-small/source/common/unicode/chariter.h b/deps/icu-small/source/common/unicode/chariter.h index 7e4f446bb0f8a8..f7ecd8e0036ce2 100644 --- a/deps/icu-small/source/common/unicode/chariter.h +++ b/deps/icu-small/source/common/unicode/chariter.h @@ -65,7 +65,7 @@ U_NAMESPACE_BEGIN * check for the end of the iteration. When there are no more * characters in the text object: *

    - *
  • The hasNext() function returns FALSE.
  • + *
  • The hasNext() function returns false.
  • *
  • nextPostInc() and next32PostInc() return DONE * when one attempts to read beyond the end of the text object.
  • *
@@ -165,11 +165,11 @@ class U_COMMON_API ForwardCharacterIterator : public UObject { virtual UChar32 next32PostInc(void) = 0; /** - * Returns FALSE if there are no more code units or code points + * Returns false if there are no more code units or code points * at or after the current position in the iteration range. * This is used with nextPostInc() or next32PostInc() in forward * iteration. - * @returns FALSE if there are no more code units or code points + * @returns false if there are no more code units or code points * at or after the current position in the iteration range. * @stable ICU 2.0 */ @@ -535,12 +535,12 @@ class U_COMMON_API CharacterIterator : public ForwardCharacterIterator { virtual UChar32 previous32(void) = 0; /** - * Returns FALSE if there are no more code units or code points + * Returns false if there are no more code units or code points * before the current position in the iteration range. * This is used with previous() or previous32() in backward * iteration. - * @return FALSE if there are no more code units or code points - * before the current position in the iteration range, return TRUE otherwise. + * @return false if there are no more code units or code points + * before the current position in the iteration range, return true otherwise. * @stable ICU 2.0 */ virtual UBool hasPrevious() = 0; diff --git a/deps/icu-small/source/common/unicode/docmain.h b/deps/icu-small/source/common/unicode/docmain.h index 2b38692997dd9a..f09d7e1dc29cec 100644 --- a/deps/icu-small/source/common/unicode/docmain.h +++ b/deps/icu-small/source/common/unicode/docmain.h @@ -53,10 +53,10 @@ * *

Architecture (User's Guide)

* * *
@@ -149,7 +149,7 @@ * * * Number Range Formatting
(includes currency and unit ranges) - * (no C API) + * unumberrangeformatter.h * icu::number::NumberRangeFormatter * * diff --git a/deps/icu-small/source/common/unicode/dtintrv.h b/deps/icu-small/source/common/unicode/dtintrv.h index 325faa3ccb92cb..7932ea660fa4dd 100644 --- a/deps/icu-small/source/common/unicode/dtintrv.h +++ b/deps/icu-small/source/common/unicode/dtintrv.h @@ -106,14 +106,14 @@ class U_COMMON_API DateInterval : public UObject { /** * Equality operator. - * @return TRUE if the two DateIntervals are the same + * @return true if the two DateIntervals are the same * @stable ICU 4.0 */ virtual UBool operator==(const DateInterval& other) const; /** * Non-equality operator - * @return TRUE if the two DateIntervals are not the same + * @return true if the two DateIntervals are not the same * @stable ICU 4.0 */ inline UBool operator!=(const DateInterval& other) const; diff --git a/deps/icu-small/source/common/unicode/edits.h b/deps/icu-small/source/common/unicode/edits.h index c3ceaccb3b3802..bfa07fa6765b73 100644 --- a/deps/icu-small/source/common/unicode/edits.h +++ b/deps/icu-small/source/common/unicode/edits.h @@ -159,7 +159,7 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * @param outErrorCode Set to an error code if it does not contain one already * and an error occurred while recording edits. * Otherwise unchanged. - * @return TRUE if U_FAILURE(outErrorCode) + * @return true if U_FAILURE(outErrorCode) * @stable ICU 59 */ UBool copyErrorTo(UErrorCode &outErrorCode) const; @@ -171,7 +171,7 @@ class U_COMMON_API Edits U_FINAL : public UMemory { */ int32_t lengthDelta() const { return delta; } /** - * @return TRUE if there are any change edits + * @return true if there are any change edits * @stable ICU 59 */ UBool hasChanges() const { return numChanges != 0; } @@ -207,8 +207,8 @@ class U_COMMON_API Edits U_FINAL : public UMemory { */ Iterator() : array(nullptr), index(0), length(0), - remaining(0), onlyChanges_(FALSE), coarse(FALSE), - dir(0), changed(FALSE), oldLength_(0), newLength_(0), + remaining(0), onlyChanges_(false), coarse(false), + dir(0), changed(false), oldLength_(0), newLength_(0), srcIndex(0), replIndex(0), destIndex(0) {} /** * Copy constructor. @@ -226,7 +226,7 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) - * @return TRUE if there is another edit + * @return true if there is another edit * @stable ICU 59 */ UBool next(UErrorCode &errorCode) { return next(onlyChanges_, errorCode); } @@ -247,11 +247,11 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) - * @return TRUE if the edit for the source index was found + * @return true if the edit for the source index was found * @stable ICU 59 */ UBool findSourceIndex(int32_t i, UErrorCode &errorCode) { - return findIndex(i, TRUE, errorCode) == 0; + return findIndex(i, true, errorCode) == 0; } /** @@ -270,11 +270,11 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) - * @return TRUE if the edit for the destination index was found + * @return true if the edit for the destination index was found * @stable ICU 60 */ UBool findDestinationIndex(int32_t i, UErrorCode &errorCode) { - return findIndex(i, FALSE, errorCode) == 0; + return findIndex(i, false, errorCode) == 0; } /** @@ -328,8 +328,8 @@ class U_COMMON_API Edits U_FINAL : public UMemory { /** * Returns whether the edit currently represented by the iterator is a change edit. * - * @return TRUE if this edit replaces oldLength() units with newLength() different ones. - * FALSE if oldLength units remain unchanged. + * @return true if this edit replaces oldLength() units with newLength() different ones. + * false if oldLength units remain unchanged. * @stable ICU 59 */ UBool hasChange() const { return changed; } @@ -347,8 +347,8 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * {@link #destinationIndex}, or in the replacement string, which starts at * {@link #replacementIndex}. * - * @return the number of units in the modified string, if hasChange() is TRUE. - * Same as oldLength if hasChange() is FALSE. + * @return the number of units in the modified string, if hasChange() is true. + * Same as oldLength if hasChange() is false. * @stable ICU 59 */ int32_t newLength() const { return newLength_; } @@ -436,7 +436,7 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * @stable ICU 59 */ Iterator getCoarseChangesIterator() const { - return Iterator(array, length, TRUE, TRUE); + return Iterator(array, length, true, true); } /** @@ -448,7 +448,7 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * @stable ICU 59 */ Iterator getCoarseIterator() const { - return Iterator(array, length, FALSE, TRUE); + return Iterator(array, length, false, true); } /** @@ -460,7 +460,7 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * @stable ICU 59 */ Iterator getFineChangesIterator() const { - return Iterator(array, length, TRUE, FALSE); + return Iterator(array, length, true, false); } /** @@ -471,7 +471,7 @@ class U_COMMON_API Edits U_FINAL : public UMemory { * @stable ICU 59 */ Iterator getFineIterator() const { - return Iterator(array, length, FALSE, FALSE); + return Iterator(array, length, false, false); } /** diff --git a/deps/icu-small/source/common/unicode/filteredbrk.h b/deps/icu-small/source/common/unicode/filteredbrk.h index 42936763259e2d..8b07e39ae12bb6 100644 --- a/deps/icu-small/source/common/unicode/filteredbrk.h +++ b/deps/icu-small/source/common/unicode/filteredbrk.h @@ -85,8 +85,8 @@ class U_COMMON_API FilteredBreakIteratorBuilder : public UObject { * by the iterator. * @param string the string to suppress, such as "Mr." * @param status error code - * @return returns TRUE if the string was not present and now added, - * FALSE if the call was a no-op because the string was already being suppressed. + * @return returns true if the string was not present and now added, + * false if the call was a no-op because the string was already being suppressed. * @stable ICU 56 */ virtual UBool suppressBreakAfter(const UnicodeString& string, UErrorCode& status) = 0; @@ -98,8 +98,8 @@ class U_COMMON_API FilteredBreakIteratorBuilder : public UObject { * locale data which may be suppressing certain strings. * @param string the exception to remove * @param status error code - * @return returns TRUE if the string was present and now removed, - * FALSE if the call was a no-op because the string was not being suppressed. + * @return returns true if the string was present and now removed, + * false if the call was a no-op because the string was not being suppressed. * @stable ICU 56 */ virtual UBool unsuppressBreakAfter(const UnicodeString& string, UErrorCode& status) = 0; diff --git a/deps/icu-small/source/common/unicode/icudataver.h b/deps/icu-small/source/common/unicode/icudataver.h index d5c728da880f8f..a82cb3d89d9d99 100644 --- a/deps/icu-small/source/common/unicode/icudataver.h +++ b/deps/icu-small/source/common/unicode/icudataver.h @@ -38,6 +38,6 @@ * * @stable ICU 49 */ -U_STABLE void U_EXPORT2 u_getDataVersion(UVersionInfo dataVersionFillin, UErrorCode *status); +U_CAPI void U_EXPORT2 u_getDataVersion(UVersionInfo dataVersionFillin, UErrorCode *status); #endif diff --git a/deps/icu-small/source/common/unicode/icuplug.h b/deps/icu-small/source/common/unicode/icuplug.h index 827cbe94b61cf8..2bd51ff8dfc050 100644 --- a/deps/icu-small/source/common/unicode/icuplug.h +++ b/deps/icu-small/source/common/unicode/icuplug.h @@ -208,7 +208,7 @@ typedef UPlugTokenReturn (U_EXPORT2 UPlugEntrypoint) ( * @param dontUnload set true if this plugin can't be unloaded * @internal ICU 4.4 Technology Preview */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uplug_setPlugNoUnload(UPlugData *plug, UBool dontUnload); /** @@ -217,7 +217,7 @@ uplug_setPlugNoUnload(UPlugData *plug, UBool dontUnload); * @param level the level of this plugin * @internal ICU 4.4 Technology Preview */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uplug_setPlugLevel(UPlugData *plug, UPlugLevel level); /** @@ -226,7 +226,7 @@ uplug_setPlugLevel(UPlugData *plug, UPlugLevel level); * @return the level of this plugin * @internal ICU 4.4 Technology Preview */ -U_INTERNAL UPlugLevel U_EXPORT2 +U_CAPI UPlugLevel U_EXPORT2 uplug_getPlugLevel(UPlugData *plug); /** @@ -236,7 +236,7 @@ uplug_getPlugLevel(UPlugData *plug); * @return the lowest level of plug which can currently load * @internal ICU 4.4 Technology Preview */ -U_INTERNAL UPlugLevel U_EXPORT2 +U_CAPI UPlugLevel U_EXPORT2 uplug_getCurrentLevel(void); @@ -245,7 +245,7 @@ uplug_getCurrentLevel(void); * @return The error code of this plugin's load attempt. * @internal ICU 4.4 Technology Preview */ -U_INTERNAL UErrorCode U_EXPORT2 +U_CAPI UErrorCode U_EXPORT2 uplug_getPlugLoadStatus(UPlugData *plug); /** @@ -254,7 +254,7 @@ uplug_getPlugLoadStatus(UPlugData *plug); * @param name the name of this plugin. The first UPLUG_NAME_MAX characters willi be copied into a new buffer. * @internal ICU 4.4 Technology Preview */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uplug_setPlugName(UPlugData *plug, const char *name); /** @@ -263,7 +263,7 @@ uplug_setPlugName(UPlugData *plug, const char *name); * @return the name of this plugin * @internal ICU 4.4 Technology Preview */ -U_INTERNAL const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 uplug_getPlugName(UPlugData *plug); /** @@ -272,7 +272,7 @@ uplug_getPlugName(UPlugData *plug); * @return the symbol name, or NULL * @internal ICU 4.4 Technology Preview */ -U_INTERNAL const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 uplug_getSymbolName(UPlugData *plug); /** @@ -282,7 +282,7 @@ uplug_getSymbolName(UPlugData *plug); * @return the library name, or NULL * @internal ICU 4.4 Technology Preview */ -U_INTERNAL const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 uplug_getLibraryName(UPlugData *plug, UErrorCode *status); /** @@ -292,7 +292,7 @@ uplug_getLibraryName(UPlugData *plug, UErrorCode *status); * @return the library, or NULL * @internal ICU 4.4 Technology Preview */ -U_INTERNAL void * U_EXPORT2 +U_CAPI void * U_EXPORT2 uplug_getLibrary(UPlugData *plug); /** @@ -301,7 +301,7 @@ uplug_getLibrary(UPlugData *plug); * @return the context, or NULL if not set * @internal ICU 4.4 Technology Preview */ -U_INTERNAL void * U_EXPORT2 +U_CAPI void * U_EXPORT2 uplug_getContext(UPlugData *plug); /** @@ -310,7 +310,7 @@ uplug_getContext(UPlugData *plug); * @param context new context to set * @internal ICU 4.4 Technology Preview */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uplug_setContext(UPlugData *plug, void *context); @@ -321,7 +321,7 @@ uplug_setContext(UPlugData *plug, void *context); * @return configuration string, or else null. * @internal ICU 4.4 Technology Preview */ -U_INTERNAL const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 uplug_getConfiguration(UPlugData *plug); /** @@ -339,7 +339,7 @@ uplug_getConfiguration(UPlugData *plug); * @return the next oldest plugin, or NULL if no more. * @internal ICU 4.4 Technology Preview */ -U_INTERNAL UPlugData* U_EXPORT2 +U_CAPI UPlugData* U_EXPORT2 uplug_nextPlug(UPlugData *prior); /** @@ -354,7 +354,7 @@ uplug_nextPlug(UPlugData *prior); * @return the new UPlugData associated with this plugin, or NULL if error. * @internal ICU 4.4 Technology Preview */ -U_INTERNAL UPlugData* U_EXPORT2 +U_CAPI UPlugData* U_EXPORT2 uplug_loadPlugFromEntrypoint(UPlugEntrypoint *entrypoint, const char *config, UErrorCode *status); @@ -368,7 +368,7 @@ uplug_loadPlugFromEntrypoint(UPlugEntrypoint *entrypoint, const char *config, UE * @return the new UPlugData associated with this plugin, or NULL if error. * @internal ICU 4.4 Technology Preview */ -U_INTERNAL UPlugData* U_EXPORT2 +U_CAPI UPlugData* U_EXPORT2 uplug_loadPlugFromLibrary(const char *libName, const char *sym, const char *config, UErrorCode *status); /** @@ -378,7 +378,7 @@ uplug_loadPlugFromLibrary(const char *libName, const char *sym, const char *conf * @param status error result * @internal ICU 4.4 Technology Preview */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 uplug_removePlug(UPlugData *plug, UErrorCode *status); #endif /* U_HIDE_INTERNAL_API */ diff --git a/deps/icu-small/source/common/unicode/idna.h b/deps/icu-small/source/common/unicode/idna.h index 6dfcfe48db28f1..1305dc604842eb 100644 --- a/deps/icu-small/source/common/unicode/idna.h +++ b/deps/icu-small/source/common/unicode/idna.h @@ -95,7 +95,7 @@ class U_COMMON_API IDNA : public UObject { /** * Converts a single domain name label into its ASCII form for DNS lookup. - * If any processing step fails, then info.hasErrors() will be TRUE and + * If any processing step fails, then info.hasErrors() will be true and * the result might not be an ASCII string. * The label might be modified according to the types of errors. * Labels with severe errors will be left in (or turned into) their Unicode form. @@ -119,7 +119,7 @@ class U_COMMON_API IDNA : public UObject { /** * Converts a single domain name label into its Unicode form for human-readable display. - * If any processing step fails, then info.hasErrors() will be TRUE. + * If any processing step fails, then info.hasErrors() will be true. * The label might be modified according to the types of errors. * * The UErrorCode indicates an error only in exceptional cases, @@ -141,7 +141,7 @@ class U_COMMON_API IDNA : public UObject { /** * Converts a whole domain name into its ASCII form for DNS lookup. - * If any processing step fails, then info.hasErrors() will be TRUE and + * If any processing step fails, then info.hasErrors() will be true and * the result might not be an ASCII string. * The domain name might be modified according to the types of errors. * Labels with severe errors will be left in (or turned into) their Unicode form. @@ -165,7 +165,7 @@ class U_COMMON_API IDNA : public UObject { /** * Converts a whole domain name into its Unicode form for human-readable display. - * If any processing step fails, then info.hasErrors() will be TRUE. + * If any processing step fails, then info.hasErrors() will be true. * The domain name might be modified according to the types of errors. * * The UErrorCode indicates an error only in exceptional cases, @@ -273,10 +273,10 @@ class U_COMMON_API IDNAInfo : public UMemory { * Constructor for stack allocation. * @stable ICU 4.6 */ - IDNAInfo() : errors(0), labelErrors(0), isTransDiff(FALSE), isBiDi(FALSE), isOkBiDi(TRUE) {} + IDNAInfo() : errors(0), labelErrors(0), isTransDiff(false), isBiDi(false), isOkBiDi(true) {} /** * Were there IDNA processing errors? - * @return TRUE if there were processing errors + * @return true if there were processing errors * @stable ICU 4.6 */ UBool hasErrors() const { return errors!=0; } @@ -288,7 +288,7 @@ class U_COMMON_API IDNAInfo : public UMemory { */ uint32_t getErrors() const { return errors; } /** - * Returns TRUE if transitional and nontransitional processing produce different results. + * Returns true if transitional and nontransitional processing produce different results. * This is the case when the input label or domain name contains * one or more deviation characters outside a Punycode label (see UTS #46). *
    @@ -297,7 +297,7 @@ class U_COMMON_API IDNAInfo : public UMemory { *
  • With transitional processing, such characters are * mapped (sharp s/sigma) or removed (joiner/nonjoiner). *
- * @return TRUE if transitional and nontransitional processing produce different results + * @return true if transitional and nontransitional processing produce different results * @stable ICU 4.6 */ UBool isTransitionalDifferent() const { return isTransDiff; } @@ -310,9 +310,9 @@ class U_COMMON_API IDNAInfo : public UMemory { void reset() { errors=labelErrors=0; - isTransDiff=FALSE; - isBiDi=FALSE; - isOkBiDi=TRUE; + isTransDiff=false; + isBiDi=false; + isOkBiDi=true; } uint32_t errors, labelErrors; diff --git a/deps/icu-small/source/common/unicode/localebuilder.h b/deps/icu-small/source/common/unicode/localebuilder.h index c5836fe27021b3..27a894de101def 100644 --- a/deps/icu-small/source/common/unicode/localebuilder.h +++ b/deps/icu-small/source/common/unicode/localebuilder.h @@ -1,5 +1,5 @@ // © 2018 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html #ifndef __LOCALEBUILDER_H__ #define __LOCALEBUILDER_H__ @@ -92,11 +92,12 @@ class U_COMMON_API LocaleBuilder : public UObject { /** * Resets the LocaleBuilder to match the provided * [Unicode Locale Identifier](http://www.unicode.org/reports/tr35/tr35.html#unicode_locale_id) . - * Discards the existing state. the empty string cause the builder to be - * reset, like {@link #clear}. Grandfathered tags are converted to their - * canonical form before being processed. Otherwise, the language - * tag must be well-formed, or else the build() method will later - * report an U_ILLEGAL_ARGUMENT_ERROR. + * Discards the existing state. + * The empty string causes the builder to be reset, like {@link #clear}. + * Legacy language tags (marked as “Type: grandfathered” in BCP 47) + * are converted to their canonical form before being processed. + * Otherwise, the language tag must be well-formed, + * or else the build() method will later report an U_ILLEGAL_ARGUMENT_ERROR. * *

This method clears the internal UErrorCode. * @@ -278,18 +279,16 @@ class U_COMMON_API LocaleBuilder : public UObject { */ Locale build(UErrorCode& status); -#ifndef U_HIDE_DRAFT_API /** * Sets the UErrorCode if an error occurred while recording sets. * Preserves older error codes in the outErrorCode. * @param outErrorCode Set to an error code that occurred while setting subtags. * Unchanged if there is no such error or if outErrorCode * already contained an error. - * @return TRUE if U_FAILURE(outErrorCode) - * @draft ICU 65 + * @return true if U_FAILURE(outErrorCode) + * @stable ICU 65 */ UBool copyErrorTo(UErrorCode &outErrorCode) const; -#endif /* U_HIDE_DRAFT_API */ private: friend class LocaleMatcher::Result; diff --git a/deps/icu-small/source/common/unicode/localematcher.h b/deps/icu-small/source/common/unicode/localematcher.h index 2e1a7a349f3983..63a68b0b7fb3d3 100644 --- a/deps/icu-small/source/common/unicode/localematcher.h +++ b/deps/icu-small/source/common/unicode/localematcher.h @@ -1,5 +1,5 @@ // © 2019 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html#License +// License & terms of use: http://www.unicode.org/copyright.html // localematcher.h // created: 2019may08 Markus W. Scherer @@ -20,26 +20,24 @@ * \brief C++ API: Locale matcher: User's desired locales vs. application's supported locales. */ -#ifndef U_FORCE_HIDE_DRAFT_API - /** * Builder option for whether the language subtag or the script subtag is most important. * - * @see Builder#setFavorSubtag(ULocMatchFavorSubtag) - * @draft ICU 65 + * @see LocaleMatcher::Builder#setFavorSubtag(ULocMatchFavorSubtag) + * @stable ICU 65 */ enum ULocMatchFavorSubtag { /** * Language differences are most important, then script differences, then region differences. * (This is the default behavior.) * - * @draft ICU 65 + * @stable ICU 65 */ ULOCMATCH_FAVOR_LANGUAGE, /** * Makes script differences matter relatively more than language differences. * - * @draft ICU 65 + * @stable ICU 65 */ ULOCMATCH_FAVOR_SCRIPT }; @@ -51,14 +49,14 @@ typedef enum ULocMatchFavorSubtag ULocMatchFavorSubtag; * Builder option for whether all desired locales are treated equally or * earlier ones are preferred. * - * @see Builder#setDemotionPerDesiredLocale(ULocMatchDemotion) - * @draft ICU 65 + * @see LocaleMatcher::Builder#setDemotionPerDesiredLocale(ULocMatchDemotion) + * @stable ICU 65 */ enum ULocMatchDemotion { /** * All desired locales are treated equally. * - * @draft ICU 65 + * @stable ICU 65 */ ULOCMATCH_DEMOTION_NONE, /** @@ -85,7 +83,7 @@ enum ULocMatchDemotion { * this is possible in future versions of the data.) * * - * @draft ICU 65 + * @stable ICU 65 */ ULOCMATCH_DEMOTION_REGION }; @@ -93,6 +91,8 @@ enum ULocMatchDemotion { typedef enum ULocMatchDemotion ULocMatchDemotion; #endif +#ifndef U_FORCE_HIDE_DRAFT_API + /** * Builder option for whether to include or ignore one-way (fallback) match data. * The LocaleMatcher uses CLDR languageMatch data which includes fallback (oneway=true) entries. @@ -107,7 +107,7 @@ typedef enum ULocMatchDemotion ULocMatchDemotion; * if there is a decent match for the original UI language, we want to use it, * but not if it is merely a fallback. * - * @see Builder#setDirection(ULocMatchDirection) + * @see LocaleMatcher::Builder#setDirection(ULocMatchDirection) * @draft ICU 67 */ enum ULocMatchDirection { @@ -129,6 +129,8 @@ enum ULocMatchDirection { typedef enum ULocMatchDirection ULocMatchDirection; #endif +#endif // U_FORCE_HIDE_DRAFT_API + struct UHashtable; U_NAMESPACE_BEGIN @@ -181,7 +183,7 @@ class XLikelySubtags; * *

This class is not intended for public subclassing. * - * @draft ICU 65 + * @stable ICU 65 */ class U_COMMON_API LocaleMatcher : public UMemory { public: @@ -189,7 +191,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * Data for the best-matching pair of a desired and a supported locale. * Movable but not copyable. * - * @draft ICU 65 + * @stable ICU 65 */ class U_COMMON_API Result : public UMemory { public: @@ -198,14 +200,14 @@ class U_COMMON_API LocaleMatcher : public UMemory { * This object will have the same contents that the source object had. * * @param src Result to move contents from. - * @draft ICU 65 + * @stable ICU 65 */ Result(Result &&src) U_NOEXCEPT; /** * Destructor. * - * @draft ICU 65 + * @stable ICU 65 */ ~Result(); @@ -214,28 +216,27 @@ class U_COMMON_API LocaleMatcher : public UMemory { * This object will have the same contents that the source object had. * * @param src Result to move contents from. - * @draft ICU 65 + * @stable ICU 65 */ Result &operator=(Result &&src) U_NOEXCEPT; -#ifndef U_HIDE_DRAFT_API /** * Returns the best-matching desired locale. * nullptr if the list of desired locales is empty or if none matched well enough. * * @return the best-matching desired locale, or nullptr. - * @draft ICU 65 + * @stable ICU 65 */ inline const Locale *getDesiredLocale() const { return desiredLocale; } /** * Returns the best-matching supported locale. * If none matched well enough, this is the default locale. - * The default locale is nullptr if the list of supported locales is empty and - * no explicit default locale is set. + * The default locale is nullptr if Builder::setNoDefaultLocale() was called, + * or if the list of supported locales is empty and no explicit default locale is set. * * @return the best-matching supported locale, or nullptr. - * @draft ICU 65 + * @stable ICU 65 */ inline const Locale *getSupportedLocale() const { return supportedLocale; } @@ -244,7 +245,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * -1 if the list of desired locales is empty or if none matched well enough. * * @return the index of the best-matching desired locale, or -1. - * @draft ICU 65 + * @stable ICU 65 */ inline int32_t getDesiredIndex() const { return desiredIndex; } @@ -256,7 +257,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * -1 if the list of supported locales is empty or if none matched well enough. * * @return the index of the best-matching supported locale, or -1. - * @draft ICU 65 + * @stable ICU 65 */ inline int32_t getSupportedIndex() const { return supportedIndex; } @@ -270,10 +271,9 @@ class U_COMMON_API LocaleMatcher : public UMemory { *

Example: desired=ar-SA-u-nu-latn, supported=ar-EG, resolved locale=ar-SA-u-nu-latn * * @return a locale combining the best-matching desired and supported locales. - * @draft ICU 65 + * @stable ICU 65 */ Locale makeResolvedLocale(UErrorCode &errorCode) const; -#endif // U_HIDE_DRAFT_API private: Result(const Locale *desired, const Locale *supported, @@ -298,8 +298,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * LocaleMatcher builder. * Movable but not copyable. * - * @see LocaleMatcher#builder() - * @draft ICU 65 + * @stable ICU 65 */ class U_COMMON_API Builder : public UMemory { public: @@ -307,7 +306,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * Constructs a builder used in chaining parameters for building a LocaleMatcher. * * @return a new Builder object - * @draft ICU 65 + * @stable ICU 65 */ Builder() {} @@ -316,14 +315,14 @@ class U_COMMON_API LocaleMatcher : public UMemory { * This builder will have the same contents that the source builder had. * * @param src Builder to move contents from. - * @draft ICU 65 + * @stable ICU 65 */ Builder(Builder &&src) U_NOEXCEPT; /** * Destructor. * - * @draft ICU 65 + * @stable ICU 65 */ ~Builder(); @@ -332,11 +331,10 @@ class U_COMMON_API LocaleMatcher : public UMemory { * This builder will have the same contents that the source builder had. * * @param src Builder to move contents from. - * @draft ICU 65 + * @stable ICU 65 */ Builder &operator=(Builder &&src) U_NOEXCEPT; -#ifndef U_HIDE_DRAFT_API /** * Parses an Accept-Language string * (RFC 2616 Section 14.4), @@ -346,7 +344,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * * @param locales the Accept-Language string of locales to set * @return this Builder object - * @draft ICU 65 + * @stable ICU 65 */ Builder &setSupportedLocalesFromListString(StringPiece locales); @@ -357,7 +355,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * * @param locales the list of locale * @return this Builder object - * @draft ICU 65 + * @stable ICU 65 */ Builder &setSupportedLocales(Locale::Iterator &locales); @@ -372,7 +370,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * @param begin Start of range. * @param end Exclusive end of range. * @return this Builder object - * @draft ICU 65 + * @stable ICU 65 */ template Builder &setSupportedLocales(Iter begin, Iter end) { @@ -397,7 +395,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * @param end Exclusive end of range. * @param converter Converter from *begin to const Locale & or compatible. * @return this Builder object - * @draft ICU 65 + * @stable ICU 65 */ template Builder &setSupportedLocalesViaConverter(Iter begin, Iter end, Conv converter) { @@ -415,17 +413,31 @@ class U_COMMON_API LocaleMatcher : public UMemory { * * @param locale another locale * @return this Builder object - * @draft ICU 65 + * @stable ICU 65 */ Builder &addSupportedLocale(const Locale &locale); +#ifndef U_HIDE_DRAFT_API + /** + * Sets no default locale. + * There will be no explicit or implicit default locale. + * If there is no good match, then the matcher will return nullptr for the + * best supported locale. + * + * @draft ICU 68 + */ + Builder &setNoDefaultLocale(); +#endif // U_HIDE_DRAFT_API + /** * Sets the default locale; if nullptr, or if it is not set explicitly, * then the first supported locale is used as the default locale. + * There is no default locale at all (nullptr will be returned instead) + * if setNoDefaultLocale() is called. * * @param defaultLocale the default locale (will be copied) * @return this Builder object - * @draft ICU 65 + * @stable ICU 65 */ Builder &setDefaultLocale(const Locale *defaultLocale); @@ -437,7 +449,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * * @param subtag the subtag to favor * @return this Builder object - * @draft ICU 65 + * @stable ICU 65 */ Builder &setFavorSubtag(ULocMatchFavorSubtag subtag); @@ -447,10 +459,11 @@ class U_COMMON_API LocaleMatcher : public UMemory { * * @param demotion the demotion per desired locale to set. * @return this Builder object - * @draft ICU 65 + * @stable ICU 65 */ Builder &setDemotionPerDesiredLocale(ULocMatchDemotion demotion); +#ifndef U_HIDE_DRAFT_API /** * Option for whether to include or ignore one-way (fallback) match data. * By default, they are included. @@ -465,6 +478,32 @@ class U_COMMON_API LocaleMatcher : public UMemory { } return *this; } +#endif // U_HIDE_DRAFT_API + +#ifndef U_HIDE_DRAFT_API + /** + * Sets the maximum distance for an acceptable match. + * The matcher will return a match for a pair of locales only if + * they match at least as well as the pair given here. + * + * For example, setMaxDistance(en-US, en-GB) limits matches to ones where the + * (desired, support) locales have a distance no greater than a region subtag difference. + * This is much stricter than the CLDR default. + * + * The details of locale matching are subject to changes in + * CLDR data and in the algorithm. + * Specifying a maximum distance in relative terms via a sample pair of locales + * insulates from changes that affect all distance metrics similarly, + * but some changes will necessarily affect relative distances between + * different pairs of locales. + * + * @param desired the desired locale for distance comparison. + * @param supported the supported locale for distance comparison. + * @return this Builder object + * @draft ICU 68 + */ + Builder &setMaxDistance(const Locale &desired, const Locale &supported); +#endif // U_HIDE_DRAFT_API /** * Sets the UErrorCode if an error occurred while setting parameters. @@ -473,8 +512,8 @@ class U_COMMON_API LocaleMatcher : public UMemory { * @param outErrorCode Set to an error code if it does not contain one already * and an error occurred while setting parameters. * Otherwise unchanged. - * @return TRUE if U_FAILURE(outErrorCode) - * @draft ICU 65 + * @return true if U_FAILURE(outErrorCode) + * @stable ICU 65 */ UBool copyErrorTo(UErrorCode &outErrorCode) const; @@ -485,11 +524,10 @@ class U_COMMON_API LocaleMatcher : public UMemory { * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) - * @return new LocaleMatcher. - * @draft ICU 65 + * @return LocaleMatcher + * @stable ICU 65 */ LocaleMatcher build(UErrorCode &errorCode) const; -#endif // U_HIDE_DRAFT_API private: friend class LocaleMatcher; @@ -505,8 +543,11 @@ class U_COMMON_API LocaleMatcher : public UMemory { int32_t thresholdDistance_ = -1; ULocMatchDemotion demotion_ = ULOCMATCH_DEMOTION_REGION; Locale *defaultLocale_ = nullptr; + bool withDefault_ = true; ULocMatchFavorSubtag favor_ = ULOCMATCH_FAVOR_LANGUAGE; ULocMatchDirection direction_ = ULOCMATCH_DIRECTION_WITH_ONE_WAY; + Locale *maxDistanceDesired_ = nullptr; + Locale *maxDistanceSupported_ = nullptr; }; // FYI No public LocaleMatcher constructors in C++; use the Builder. @@ -515,13 +556,13 @@ class U_COMMON_API LocaleMatcher : public UMemory { * Move copy constructor; might modify the source. * This matcher will have the same settings that the source matcher had. * @param src source matcher - * @draft ICU 65 + * @stable ICU 65 */ LocaleMatcher(LocaleMatcher &&src) U_NOEXCEPT; /** * Destructor. - * @draft ICU 65 + * @stable ICU 65 */ ~LocaleMatcher(); @@ -531,11 +572,10 @@ class U_COMMON_API LocaleMatcher : public UMemory { * The behavior is undefined if *this and src are the same object. * @param src source matcher * @return *this - * @draft ICU 65 + * @stable ICU 65 */ LocaleMatcher &operator=(LocaleMatcher &&src) U_NOEXCEPT; -#ifndef U_HIDE_DRAFT_API /** * Returns the supported locale which best matches the desired locale. * @@ -544,7 +584,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) * @return the best-matching supported locale. - * @draft ICU 65 + * @stable ICU 65 */ const Locale *getBestMatch(const Locale &desiredLocale, UErrorCode &errorCode) const; @@ -556,7 +596,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) * @return the best-matching supported locale. - * @draft ICU 65 + * @stable ICU 65 */ const Locale *getBestMatch(Locale::Iterator &desiredLocales, UErrorCode &errorCode) const; @@ -572,7 +612,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) * @return the best-matching supported locale. - * @draft ICU 65 + * @stable ICU 65 */ const Locale *getBestMatchForListString(StringPiece desiredLocaleList, UErrorCode &errorCode) const; @@ -586,7 +626,7 @@ class U_COMMON_API LocaleMatcher : public UMemory { * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) * @return the best-matching pair of the desired and a supported locale. - * @draft ICU 65 + * @stable ICU 65 */ Result getBestMatchResult(const Locale &desiredLocale, UErrorCode &errorCode) const; @@ -600,9 +640,25 @@ class U_COMMON_API LocaleMatcher : public UMemory { * or else the function returns immediately. Check for U_FAILURE() * on output or use with function chaining. (See User Guide for details.) * @return the best-matching pair of a desired and a supported locale. - * @draft ICU 65 + * @stable ICU 65 */ Result getBestMatchResult(Locale::Iterator &desiredLocales, UErrorCode &errorCode) const; + +#ifndef U_HIDE_DRAFT_API + /** + * Returns true if the pair of locales matches acceptably. + * This is influenced by Builder options such as setDirection(), setFavorSubtag(), + * and setMaxDistance(). + * + * @param desired The desired locale. + * @param supported The supported locale. + * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, + * or else the function returns immediately. Check for U_FAILURE() + * on output or use with function chaining. (See User Guide for details.) + * @return true if the pair of locales matches acceptably. + * @draft ICU 68 + */ + UBool isMatch(const Locale &desired, const Locale &supported, UErrorCode &errorCode) const; #endif // U_HIDE_DRAFT_API #ifndef U_HIDE_INTERNAL_API @@ -660,6 +716,5 @@ class U_COMMON_API LocaleMatcher : public UMemory { U_NAMESPACE_END -#endif // U_FORCE_HIDE_DRAFT_API #endif // U_SHOW_CPLUSPLUS_API #endif // __LOCALEMATCHER_H__ diff --git a/deps/icu-small/source/common/unicode/localpointer.h b/deps/icu-small/source/common/unicode/localpointer.h index 61c3020918e578..2a65f2d382d2d8 100644 --- a/deps/icu-small/source/common/unicode/localpointer.h +++ b/deps/icu-small/source/common/unicode/localpointer.h @@ -88,13 +88,13 @@ class LocalPointerBase { ~LocalPointerBase() { /* delete ptr; */ } /** * NULL check. - * @return TRUE if ==NULL + * @return true if ==NULL * @stable ICU 4.4 */ UBool isNull() const { return ptr==NULL; } /** * NULL check. - * @return TRUE if !=NULL + * @return true if !=NULL * @stable ICU 4.4 */ UBool isValid() const { return ptr!=NULL; } diff --git a/deps/icu-small/source/common/unicode/locid.h b/deps/icu-small/source/common/unicode/locid.h index ee8697b0a57f3e..877c8014b0b3a7 100644 --- a/deps/icu-small/source/common/unicode/locid.h +++ b/deps/icu-small/source/common/unicode/locid.h @@ -253,7 +253,7 @@ class U_COMMON_API Locale : public UObject { /** * Construct a locale from language, country, variant. * If an error occurs, then the constructed object will be "bogus" - * (isBogus() will return TRUE). + * (isBogus() will return true). * * @param language Lowercase two-letter or three-letter ISO-639 code. * This parameter can instead be an ICU style C locale (e.g. "en_US"), @@ -393,13 +393,17 @@ class U_COMMON_API Locale : public UObject { * If the specified language tag contains any ill-formed subtags, * the first such subtag and all following subtags are ignored. *

- * This implements the 'Language-Tag' production of BCP47, and so - * supports grandfathered (regular and irregular) as well as private - * use language tags. Private use tags are represented as 'x-whatever', - * and grandfathered tags are converted to their canonical replacements - * where they exist. Note that a few grandfathered tags have no modern - * replacement, these will be converted using the fallback described in + * This implements the 'Language-Tag' production of BCP 47, and so + * supports legacy language tags (marked as “Type: grandfathered” in BCP 47) + * (regular and irregular) as well as private use language tags. + * + * Private use tags are represented as 'x-whatever', + * and legacy tags are converted to their canonical replacements where they exist. + * + * Note that a few legacy tags have no modern replacement; + * these will be converted using the fallback described in * the first paragraph, so some information might be lost. + * * @param tag the input BCP47 language tag. * @param status error information if creating the Locale failed. * @return the Locale for the specified BCP47 language tag. @@ -795,14 +799,14 @@ class U_COMMON_API Locale : public UObject { /** * Returns whether this locale's script is written right-to-left. * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags(). - * If no likely script is known, then FALSE is returned. + * If no likely script is known, then false is returned. * * A script is right-to-left according to the CLDR script metadata * which corresponds to whether the script's letters have Bidi_Class=R or AL. * - * Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl". + * Returns true for "ar" and "en-Hebr", false for "zh" and "fa-Cyrl". * - * @return TRUE if the locale's script is written right-to-left + * @return true if the locale's script is written right-to-left * @stable ICU 54 */ UBool isRightToLeft() const; @@ -956,7 +960,7 @@ class U_COMMON_API Locale : public UObject { /** * Gets the bogus state. Locale object can be bogus if it doesn't exist - * @return FALSE if it is a real locale, TRUE if it is a bogus locale + * @return false if it is a real locale, true if it is a bogus locale * @stable ICU 2.1 */ inline UBool isBogus(void) const; @@ -1005,32 +1009,31 @@ class U_COMMON_API Locale : public UObject { */ virtual UClassID getDynamicClassID() const; -#ifndef U_HIDE_DRAFT_API /** * A Locale iterator interface similar to a Java Iterator. - * @draft ICU 65 + * @stable ICU 65 */ class U_COMMON_API Iterator /* not : public UObject because this is an interface/mixin class */ { public: - /** @draft ICU 65 */ + /** @stable ICU 65 */ virtual ~Iterator(); /** - * @return TRUE if next() can be called again. - * @draft ICU 65 + * @return true if next() can be called again. + * @stable ICU 65 */ virtual UBool hasNext() const = 0; /** * @return the next locale. - * @draft ICU 65 + * @stable ICU 65 */ virtual const Locale &next() = 0; }; /** * A generic Locale iterator implementation over Locale input iterators. - * @draft ICU 65 + * @stable ICU 65 */ template class RangeIterator : public Iterator, public UMemory { @@ -1042,19 +1045,19 @@ class U_COMMON_API Locale : public UObject { * * @param begin Start of range. * @param end Exclusive end of range. - * @draft ICU 65 + * @stable ICU 65 */ RangeIterator(Iter begin, Iter end) : it_(begin), end_(end) {} /** - * @return TRUE if next() can be called again. - * @draft ICU 65 + * @return true if next() can be called again. + * @stable ICU 65 */ UBool hasNext() const override { return it_ != end_; } /** * @return the next locale. - * @draft ICU 65 + * @stable ICU 65 */ const Locale &next() override { return *it_++; } @@ -1066,7 +1069,7 @@ class U_COMMON_API Locale : public UObject { /** * A generic Locale iterator implementation over Locale input iterators. * Calls the converter to convert each *begin to a const Locale &. - * @draft ICU 65 + * @stable ICU 65 */ template class ConvertingIterator : public Iterator, public UMemory { @@ -1079,20 +1082,20 @@ class U_COMMON_API Locale : public UObject { * @param begin Start of range. * @param end Exclusive end of range. * @param converter Converter from *begin to const Locale & or compatible. - * @draft ICU 65 + * @stable ICU 65 */ ConvertingIterator(Iter begin, Iter end, Conv converter) : it_(begin), end_(end), converter_(converter) {} /** - * @return TRUE if next() can be called again. - * @draft ICU 65 + * @return true if next() can be called again. + * @stable ICU 65 */ UBool hasNext() const override { return it_ != end_; } /** * @return the next locale. - * @draft ICU 65 + * @stable ICU 65 */ const Locale &next() override { return converter_(*it_++); } @@ -1101,7 +1104,6 @@ class U_COMMON_API Locale : public UObject { const Iter end_; Conv converter_; }; -#endif // U_HIDE_DRAFT_API protected: /* only protected for testing purposes. DO NOT USE. */ #ifndef U_HIDE_INTERNAL_API diff --git a/deps/icu-small/source/common/unicode/messagepattern.h b/deps/icu-small/source/common/unicode/messagepattern.h index 04f00a8757d783..98e7b70b1fcc13 100644 --- a/deps/icu-small/source/common/unicode/messagepattern.h +++ b/deps/icu-small/source/common/unicode/messagepattern.h @@ -265,7 +265,7 @@ typedef enum UMessagePatternArgType UMessagePatternArgType; /** * \def UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE - * Returns TRUE if the argument type has a plural style part sequence and semantics, + * Returns true if the argument type has a plural style part sequence and semantics, * for example UMSGPAT_ARG_TYPE_PLURAL and UMSGPAT_ARG_TYPE_SELECTORDINAL. * @stable ICU 50 */ @@ -523,14 +523,14 @@ class U_COMMON_API MessagePattern : public UObject { /** * @param other another object to compare with. - * @return TRUE if this object is equivalent to the other one. + * @return true if this object is equivalent to the other one. * @stable ICU 4.8 */ UBool operator==(const MessagePattern &other) const; /** * @param other another object to compare with. - * @return FALSE if this object is equivalent to the other one. + * @return false if this object is equivalent to the other one. * @stable ICU 4.8 */ inline UBool operator!=(const MessagePattern &other) const { @@ -564,7 +564,7 @@ class U_COMMON_API MessagePattern : public UObject { /** * Does the parsed pattern have named arguments like {first_name}? - * @return TRUE if the parsed pattern has at least one named argument. + * @return true if the parsed pattern has at least one named argument. * @stable ICU 4.8 */ UBool hasNamedArguments() const { @@ -573,7 +573,7 @@ class U_COMMON_API MessagePattern : public UObject { /** * Does the parsed pattern have numbered arguments like {2}? - * @return TRUE if the parsed pattern has at least one numbered argument. + * @return true if the parsed pattern has at least one numbered argument. * @stable ICU 4.8 */ UBool hasNumberedArguments() const { @@ -664,7 +664,7 @@ class U_COMMON_API MessagePattern : public UObject { * Compares the part's substring with the input string s. * @param part a part of this MessagePattern. * @param s a string. - * @return TRUE if getSubstring(part).equals(s). + * @return true if getSubstring(part).equals(s). * @stable ICU 4.8 */ UBool partSubstringMatches(const Part &part, const UnicodeString &s) const { @@ -785,7 +785,7 @@ class U_COMMON_API MessagePattern : public UObject { * Indicates whether the Part type has a numeric value. * If so, then that numeric value can be retrieved via MessagePattern.getNumericValue(). * @param type The Part type to be tested. - * @return TRUE if the Part type has a numeric value. + * @return true if the Part type has a numeric value. * @stable ICU 4.8 */ static UBool hasNumericValue(UMessagePatternPartType type) { @@ -794,14 +794,14 @@ class U_COMMON_API MessagePattern : public UObject { /** * @param other another object to compare with. - * @return TRUE if this object is equivalent to the other one. + * @return true if this object is equivalent to the other one. * @stable ICU 4.8 */ UBool operator==(const Part &other) const; /** * @param other another object to compare with. - * @return FALSE if this object is equivalent to the other one. + * @return false if this object is equivalent to the other one. * @stable ICU 4.8 */ inline UBool operator!=(const Part &other) const { @@ -869,7 +869,7 @@ class U_COMMON_API MessagePattern : public UObject { * Parses a number from the specified message substring. * @param start start index into the message string * @param limit limit index into the message string, must be startFALSE, only canonical + * If this argument is false, only canonical * decomposition will be performed. * @param options the optional features to be enabled (0 for no options) * @param result The composed string (on output). @@ -256,7 +256,7 @@ class U_COMMON_API Normalizer : public UObject { * * @param source the string to be decomposed. * @param compat Perform compatibility decomposition. - * If this argument is FALSE, only canonical + * If this argument is false, only canonical * decomposition will be performed. * @param options the optional features to be enabled (0 for no options) * @param result The decomposed string (on output). @@ -315,7 +315,7 @@ class U_COMMON_API Normalizer : public UObject { * never a "maybe". * For NFD, NFKD, and FCD, both functions work exactly the same. * For NFC and NFKC where quickCheck may return "maybe", this function will - * perform further tests to arrive at a TRUE/FALSE result. + * perform further tests to arrive at a true/false result. * * @param src String that is to be tested if it is in a normalization format. * @param mode Which normalization form to test for. @@ -577,7 +577,7 @@ class U_COMMON_API Normalizer : public UObject { int32_t endIndex(void) const; /** - * Returns TRUE when both iterators refer to the same character in the same + * Returns true when both iterators refer to the same character in the same * input text. * * @param that a Normalizer object to compare this one to @@ -587,7 +587,7 @@ class U_COMMON_API Normalizer : public UObject { UBool operator==(const Normalizer& that) const; /** - * Returns FALSE when both iterators refer to the same character in the same + * Returns false when both iterators refer to the same character in the same * input text. * * @param that a Normalizer object to compare this one to @@ -655,8 +655,8 @@ class U_COMMON_API Normalizer : public UObject { * It is possible to specify multiple options that are all turned on or off. * * @param option the option(s) whose value is/are to be set. - * @param value the new setting for the option. Use TRUE to - * turn the option(s) on and FALSE to turn it/them off. + * @param value the new setting for the option. Use true to + * turn the option(s) on and false to turn it/them off. * * @see #getOption * @deprecated ICU 56 Use Normalizer2 instead. @@ -666,11 +666,11 @@ class U_COMMON_API Normalizer : public UObject { /** * Determine whether an option is turned on or off. - * If multiple options are specified, then the result is TRUE if any + * If multiple options are specified, then the result is true if any * of them are set. *

* @param option the option(s) that are to be checked - * @return TRUE if any of the option(s) are set + * @return true if any of the option(s) are set * @see #setOption * @deprecated ICU 56 Use Normalizer2 instead. */ diff --git a/deps/icu-small/source/common/unicode/parsepos.h b/deps/icu-small/source/common/unicode/parsepos.h index ae5754b8d75132..d6129fd4f1604f 100644 --- a/deps/icu-small/source/common/unicode/parsepos.h +++ b/deps/icu-small/source/common/unicode/parsepos.h @@ -97,14 +97,14 @@ class U_COMMON_API ParsePosition : public UObject { /** * Equality operator. - * @return TRUE if the two parse positions are equal, FALSE otherwise. + * @return true if the two parse positions are equal, false otherwise. * @stable ICU 2.0 */ inline UBool operator==(const ParsePosition& that) const; /** * Equality operator. - * @return TRUE if the two parse positions are not equal, FALSE otherwise. + * @return true if the two parse positions are not equal, false otherwise. * @stable ICU 2.0 */ inline UBool operator!=(const ParsePosition& that) const; @@ -196,9 +196,9 @@ inline UBool ParsePosition::operator==(const ParsePosition& copy) const { if(index != copy.index || errorIndex != copy.errorIndex) - return FALSE; + return false; else - return TRUE; + return true; } inline UBool diff --git a/deps/icu-small/source/common/unicode/putil.h b/deps/icu-small/source/common/unicode/putil.h index 14bb99ccc545b2..f8c510dacc75fc 100644 --- a/deps/icu-small/source/common/unicode/putil.h +++ b/deps/icu-small/source/common/unicode/putil.h @@ -66,7 +66,7 @@ * * @stable ICU 2.0 */ -U_STABLE const char* U_EXPORT2 u_getDataDirectory(void); +U_CAPI const char* U_EXPORT2 u_getDataDirectory(void); /** @@ -88,7 +88,7 @@ U_STABLE const char* U_EXPORT2 u_getDataDirectory(void); * @see u_init * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 u_setDataDirectory(const char *directory); +U_CAPI void U_EXPORT2 u_setDataDirectory(const char *directory); #ifndef U_HIDE_INTERNAL_API /** @@ -99,7 +99,7 @@ U_STABLE void U_EXPORT2 u_setDataDirectory(const char *directory); * @return the time zone data override directory. * @internal */ -U_INTERNAL const char * U_EXPORT2 u_getTimeZoneFilesDirectory(UErrorCode *status); +U_CAPI const char * U_EXPORT2 u_getTimeZoneFilesDirectory(UErrorCode *status); /** * Set the time zone files override directory. @@ -109,7 +109,7 @@ U_INTERNAL const char * U_EXPORT2 u_getTimeZoneFilesDirectory(UErrorCode *status * will access the time zone data. * @internal */ -U_INTERNAL void U_EXPORT2 u_setTimeZoneFilesDirectory(const char *path, UErrorCode *status); +U_CAPI void U_EXPORT2 u_setTimeZoneFilesDirectory(const char *path, UErrorCode *status); #endif /* U_HIDE_INTERNAL_API */ @@ -155,7 +155,7 @@ U_INTERNAL void U_EXPORT2 u_setTimeZoneFilesDirectory(const char *path, UErrorCo * @see U_CHARSET_FAMILY * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_charsToUChars(const char *cs, UChar *us, int32_t length); /** @@ -177,7 +177,7 @@ u_charsToUChars(const char *cs, UChar *us, int32_t length); * @see U_CHARSET_FAMILY * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_UCharsToChars(const UChar *us, char *cs, int32_t length); #endif diff --git a/deps/icu-small/source/common/unicode/rbbi.h b/deps/icu-small/source/common/unicode/rbbi.h index 7825f603a51c1b..65117f616cdf5b 100644 --- a/deps/icu-small/source/common/unicode/rbbi.h +++ b/deps/icu-small/source/common/unicode/rbbi.h @@ -32,6 +32,8 @@ #include "unicode/parseerr.h" #include "unicode/schriter.h" +struct UCPTrie; + U_NAMESPACE_BEGIN /** @internal */ @@ -140,6 +142,11 @@ class U_COMMON_API RuleBasedBreakIterator /*U_FINAL*/ : public BreakIterator { */ UBool fDone; + /** + * Array of look-ahead tentative results. + */ + int32_t *fLookAheadMatches; + //======================================================================= // constructors //======================================================================= @@ -246,20 +253,20 @@ class U_COMMON_API RuleBasedBreakIterator /*U_FINAL*/ : public BreakIterator { RuleBasedBreakIterator& operator=(const RuleBasedBreakIterator& that); /** - * Equality operator. Returns TRUE if both BreakIterators are of the + * Equality operator. Returns true if both BreakIterators are of the * same class, have the same behavior, and iterate over the same text. * @param that The BreakIterator to be compared for equality - * @return TRUE if both BreakIterators are of the + * @return true if both BreakIterators are of the * same class, have the same behavior, and iterate over the same text. * @stable ICU 2.0 */ virtual UBool operator==(const BreakIterator& that) const; /** - * Not-equal operator. If operator== returns TRUE, this returns FALSE, + * Not-equal operator. If operator== returns true, this returns false, * and vice versa. * @param that The BreakIterator to be compared for inequality - * @return TRUE if both BreakIterators are not same. + * @return true if both BreakIterators are not same. * @stable ICU 2.0 */ inline UBool operator!=(const BreakIterator& that) const; @@ -659,6 +666,28 @@ class U_COMMON_API RuleBasedBreakIterator /*U_FINAL*/ : public BreakIterator { */ int32_t handleNext(); + /* + * Templatized version of handleNext() and handleSafePrevious(). + * + * There will be exactly four instantiations, two each for 8 and 16 bit tables, + * two each for 8 and 16 bit trie. + * Having separate instantiations for the table types keeps conditional tests of + * the table type out of the inner loops, at the expense of replicated code. + * + * The template parameter for the Trie access function is a value, not a type. + * Doing it this way, the compiler will inline the Trie function in the + * expanded functions. (Both the 8 and 16 bit access functions have the same type + * signature) + */ + + typedef uint16_t (*PTrieFunc)(const UCPTrie *, UChar32); + + template + int32_t handleSafePrevious(int32_t fromPosition); + + template + int32_t handleNext(); + /** * This function returns the appropriate LanguageBreakEngine for a @@ -681,7 +710,6 @@ class U_COMMON_API RuleBasedBreakIterator /*U_FINAL*/ : public BreakIterator { * @internal */ void dumpTables(); - #endif /* U_HIDE_INTERNAL_API */ }; diff --git a/deps/icu-small/source/common/unicode/resbund.h b/deps/icu-small/source/common/unicode/resbund.h index 708a3423d2ae2b..63ffa506e77eec 100644 --- a/deps/icu-small/source/common/unicode/resbund.h +++ b/deps/icu-small/source/common/unicode/resbund.h @@ -286,7 +286,7 @@ class U_COMMON_API ResourceBundle : public UObject { /** * Checks whether the resource has another element to iterate over. * - * @return TRUE if there are more elements, FALSE if there is no more elements + * @return true if there are more elements, false if there is no more elements * @stable ICU 2.0 */ UBool diff --git a/deps/icu-small/source/common/unicode/simpleformatter.h b/deps/icu-small/source/common/unicode/simpleformatter.h index 9414bca3085ad4..6d9c04ace2359a 100644 --- a/deps/icu-small/source/common/unicode/simpleformatter.h +++ b/deps/icu-small/source/common/unicode/simpleformatter.h @@ -125,7 +125,7 @@ class U_COMMON_API SimpleFormatter U_FINAL : public UMemory { * @param errorCode ICU error code in/out parameter. * Must fulfill U_SUCCESS before the function call. * Set to U_ILLEGAL_ARGUMENT_ERROR for bad argument syntax. - * @return TRUE if U_SUCCESS(errorCode). + * @return true if U_SUCCESS(errorCode). * @stable ICU 57 */ UBool applyPattern(const UnicodeString &pattern, UErrorCode &errorCode) { @@ -144,7 +144,7 @@ class U_COMMON_API SimpleFormatter U_FINAL : public UMemory { * Must fulfill U_SUCCESS before the function call. * Set to U_ILLEGAL_ARGUMENT_ERROR for bad argument syntax and * too few or too many arguments. - * @return TRUE if U_SUCCESS(errorCode). + * @return true if U_SUCCESS(errorCode). * @stable ICU 57 */ UBool applyPatternMinMaxArguments(const UnicodeString &pattern, diff --git a/deps/icu-small/source/common/unicode/strenum.h b/deps/icu-small/source/common/unicode/strenum.h index e813cd84b3413a..5d1600156e32e9 100644 --- a/deps/icu-small/source/common/unicode/strenum.h +++ b/deps/icu-small/source/common/unicode/strenum.h @@ -196,7 +196,7 @@ class U_COMMON_API StringEnumeration : public UObject { * Compares this enumeration to other to check if both are equal * * @param that The other string enumeration to compare this object to - * @return TRUE if the enumerations are equal. FALSE if not. + * @return true if the enumerations are equal. false if not. * @stable ICU 3.6 */ virtual UBool operator==(const StringEnumeration& that)const; @@ -204,7 +204,7 @@ class U_COMMON_API StringEnumeration : public UObject { * Compares this enumeration to other to check if both are not equal * * @param that The other string enumeration to compare this object to - * @return TRUE if the enumerations are equal. FALSE if not. + * @return true if the enumerations are equal. false if not. * @stable ICU 3.6 */ virtual UBool operator!=(const StringEnumeration& that)const; diff --git a/deps/icu-small/source/common/unicode/stringpiece.h b/deps/icu-small/source/common/unicode/stringpiece.h index 19fbe2e22eb032..58053cfd5c3108 100644 --- a/deps/icu-small/source/common/unicode/stringpiece.h +++ b/deps/icu-small/source/common/unicode/stringpiece.h @@ -111,7 +111,6 @@ class U_COMMON_API StringPiece : public UMemory { #endif #endif // U_HIDE_DRAFT_API -#ifndef U_HIDE_DRAFT_API /** * Constructs from some other implementation of a string piece class, from any * C++ record type that has these two methods: @@ -132,7 +131,7 @@ class U_COMMON_API StringPiece : public UMemory { * as from std::u8string_view. * * @param str the other string piece - * @draft ICU 65 + * @stable ICU 65 */ template (str.data())), length_(static_cast(str.size())) {} -#endif // U_HIDE_DRAFT_API /** * Constructs from a const char * pointer and a specified length. @@ -209,7 +207,7 @@ class U_COMMON_API StringPiece : public UMemory { int32_t length() const { return length_; } /** * Returns whether the string is empty. - * @return TRUE if the string is empty + * @return true if the string is empty * @stable ICU 4.2 */ UBool empty() const { return length_ == 0; } @@ -331,7 +329,7 @@ class U_COMMON_API StringPiece : public UMemory { * Global operator == for StringPiece * @param x The first StringPiece to compare. * @param y The second StringPiece to compare. - * @return TRUE if the string data is equal + * @return true if the string data is equal * @stable ICU 4.8 */ U_EXPORT UBool U_EXPORT2 @@ -341,7 +339,7 @@ operator==(const StringPiece& x, const StringPiece& y); * Global operator != for StringPiece * @param x The first StringPiece to compare. * @param y The second StringPiece to compare. - * @return TRUE if the string data is not equal + * @return true if the string data is not equal * @stable ICU 4.8 */ inline UBool operator!=(const StringPiece& x, const StringPiece& y) { diff --git a/deps/icu-small/source/common/unicode/stringtriebuilder.h b/deps/icu-small/source/common/unicode/stringtriebuilder.h index 2860cbf5513b8e..efd2d49206ca2d 100644 --- a/deps/icu-small/source/common/unicode/stringtriebuilder.h +++ b/deps/icu-small/source/common/unicode/stringtriebuilder.h @@ -279,10 +279,10 @@ class U_COMMON_API StringTrieBuilder : public UObject { */ class ValueNode : public Node { public: - ValueNode(int32_t initialHash) : Node(initialHash), hasValue(FALSE), value(0) {} + ValueNode(int32_t initialHash) : Node(initialHash), hasValue(false), value(0) {} virtual UBool operator==(const Node &other) const; void setValue(int32_t v) { - hasValue=TRUE; + hasValue=true; value=v; hash=hash*37u+v; } diff --git a/deps/icu-small/source/common/unicode/ubidi.h b/deps/icu-small/source/common/unicode/ubidi.h index f4875c8801efd6..63d0e45cb7f3c5 100644 --- a/deps/icu-small/source/common/unicode/ubidi.h +++ b/deps/icu-small/source/common/unicode/ubidi.h @@ -21,7 +21,10 @@ #include "unicode/utypes.h" #include "unicode/uchar.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API /** *\file @@ -496,7 +499,7 @@ typedef struct UBiDi UBiDi; * @return An empty UBiDi object. * @stable ICU 2.0 */ -U_STABLE UBiDi * U_EXPORT2 +U_CAPI UBiDi * U_EXPORT2 ubidi_open(void); /** @@ -533,7 +536,7 @@ ubidi_open(void); * @return An empty UBiDi object with preallocated memory. * @stable ICU 2.0 */ -U_STABLE UBiDi * U_EXPORT2 +U_CAPI UBiDi * U_EXPORT2 ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode); /** @@ -556,7 +559,7 @@ ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode); * @see ubidi_setLine * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_close(UBiDi *pBiDi); #if U_SHOW_CPLUSPLUS_API @@ -594,7 +597,7 @@ U_NAMESPACE_END * this "inverse Bidi" and that the current implementation provides only an * approximation of "inverse Bidi".

* - *

With isInverse set to TRUE, + *

With isInverse set to true, * this function changes the behavior of some of the subsequent functions * in a way that they can be used for the inverse Bidi algorithm. * Specifically, runs of text with numeric characters will be treated in a @@ -607,12 +610,12 @@ U_NAMESPACE_END * the runs of the logically ordered output.

* *

Calling this function with argument isInverse set to - * TRUE is equivalent to calling + * true is equivalent to calling * ubidi_setReorderingMode with argument * reorderingMode * set to #UBIDI_REORDER_INVERSE_NUMBERS_AS_L.
* Calling this function with argument isInverse set to - * FALSE is equivalent to calling + * false is equivalent to calling * ubidi_setReorderingMode with argument * reorderingMode * set to #UBIDI_REORDER_DEFAULT. @@ -626,18 +629,18 @@ U_NAMESPACE_END * @see ubidi_setReorderingMode * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_setInverse(UBiDi *pBiDi, UBool isInverse); /** * Is this Bidi object set to perform the inverse Bidi algorithm? *

Note: calling this function after setting the reordering mode with - * ubidi_setReorderingMode will return TRUE if the + * ubidi_setReorderingMode will return true if the * reordering mode was set to #UBIDI_REORDER_INVERSE_NUMBERS_AS_L, - * FALSE for all other values.

+ * false for all other values.

* * @param pBiDi is a UBiDi object. - * @return TRUE if the Bidi object is set to perform the inverse Bidi algorithm + * @return true if the Bidi object is set to perform the inverse Bidi algorithm * by handling numbers as L. * * @see ubidi_setInverse @@ -645,7 +648,7 @@ ubidi_setInverse(UBiDi *pBiDi, UBool isInverse); * @stable ICU 2.0 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ubidi_isInverse(UBiDi *pBiDi); /** @@ -668,7 +671,7 @@ ubidi_isInverse(UBiDi *pBiDi); * @see ubidi_setPara * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR); /** @@ -676,13 +679,13 @@ ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR); * successive paragraphs progress from left to right? * * @param pBiDi is a UBiDi object. - * @return TRUE if the Bidi object is set to allocate level 0 to block + * @return true if the Bidi object is set to allocate level 0 to block * separators. * * @see ubidi_orderParagraphsLTR * @stable ICU 3.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ubidi_isOrderParagraphsLTR(UBiDi *pBiDi); /** @@ -714,7 +717,7 @@ typedef enum UBiDiReorderingMode { * @stable ICU 3.6 */ UBIDI_REORDER_RUNS_ONLY, /** Visual to Logical algorithm which handles numbers like L - * (same algorithm as selected by ubidi_setInverse(TRUE). + * (same algorithm as selected by ubidi_setInverse(true). * @see ubidi_setInverse * @stable ICU 3.6 */ UBIDI_REORDER_INVERSE_NUMBERS_AS_L, @@ -833,7 +836,7 @@ typedef enum UBiDiReorderingMode { * reordered sequence (the option #UBIDI_INSERT_LRM_FOR_NUMERIC can * be used with function ubidi_writeReordered to this end. This * mode is equivalent to calling ubidi_setInverse() with - * argument isInverse set to TRUE. + * argument isInverse set to true. * *
  • When the reordering mode is set to * #UBIDI_REORDER_INVERSE_LIKE_DIRECT, the "direct" Logical to Visual @@ -886,7 +889,7 @@ typedef enum UBiDiReorderingMode { * @see ubidi_writeReordered * @stable ICU 3.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode); /** @@ -897,7 +900,7 @@ ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode); * @see ubidi_setReorderingMode * @stable ICU 3.6 */ -U_STABLE UBiDiReorderingMode U_EXPORT2 +U_CAPI UBiDiReorderingMode U_EXPORT2 ubidi_getReorderingMode(UBiDi *pBiDi); /** @@ -935,7 +938,7 @@ typedef enum UBiDiReorderingOption { * *

    If this option is set in conjunction with reordering mode * #UBIDI_REORDER_INVERSE_NUMBERS_AS_L or with calling - * ubidi_setInverse(TRUE), it implies + * ubidi_setInverse(true), it implies * option #UBIDI_INSERT_LRM_FOR_NUMERIC * in calls to function ubidi_writeReordered().

    * @@ -1016,7 +1019,7 @@ typedef enum UBiDiReorderingOption { * *

    When the UBIDI_OPTION_STREAMING option is used, * it is recommended to call ubidi_orderParagraphsLTR() with - * argument orderParagraphsLTR set to TRUE before + * argument orderParagraphsLTR set to true before * calling ubidi_setPara so that later paragraphs may be * concatenated to previous paragraphs on the right.

    * @@ -1042,7 +1045,7 @@ typedef enum UBiDiReorderingOption { * @see ubidi_getReorderingOptions * @stable ICU 3.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions); /** @@ -1053,7 +1056,7 @@ ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions); * @see ubidi_setReorderingOptions * @stable ICU 3.6 */ -U_STABLE uint32_t U_EXPORT2 +U_CAPI uint32_t U_EXPORT2 ubidi_getReorderingOptions(UBiDi *pBiDi); /** @@ -1140,7 +1143,7 @@ ubidi_getReorderingOptions(UBiDi *pBiDi); * @see ubidi_setPara * @stable ICU 4.8 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_setContext(UBiDi *pBiDi, const UChar *prologue, int32_t proLength, const UChar *epilogue, int32_t epiLength, @@ -1228,7 +1231,7 @@ ubidi_setContext(UBiDi *pBiDi, * @param pErrorCode must be a valid pointer to an error code value. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length, UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels, UErrorCode *pErrorCode); @@ -1279,7 +1282,7 @@ ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length, * @see ubidi_getProcessedLength * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_setLine(const UBiDi *pParaBiDi, int32_t start, int32_t limit, UBiDi *pLineBiDi, @@ -1300,7 +1303,7 @@ ubidi_setLine(const UBiDi *pParaBiDi, * @see UBiDiDirection * @stable ICU 2.0 */ -U_STABLE UBiDiDirection U_EXPORT2 +U_CAPI UBiDiDirection U_EXPORT2 ubidi_getDirection(const UBiDi *pBiDi); /** @@ -1330,7 +1333,7 @@ ubidi_getDirection(const UBiDi *pBiDi); * @see UBiDiDirection * @stable ICU 4.6 */ -U_STABLE UBiDiDirection U_EXPORT2 +U_CAPI UBiDiDirection U_EXPORT2 ubidi_getBaseDirection(const UChar *text, int32_t length ); /** @@ -1344,7 +1347,7 @@ ubidi_getBaseDirection(const UChar *text, int32_t length ); * @see ubidi_setLine * @stable ICU 2.0 */ -U_STABLE const UChar * U_EXPORT2 +U_CAPI const UChar * U_EXPORT2 ubidi_getText(const UBiDi *pBiDi); /** @@ -1355,7 +1358,7 @@ ubidi_getText(const UBiDi *pBiDi); * @return The length of the text that the UBiDi object was created for. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_getLength(const UBiDi *pBiDi); /** @@ -1373,7 +1376,7 @@ ubidi_getLength(const UBiDi *pBiDi); * @see ubidi_getParagraphByIndex * @stable ICU 2.0 */ -U_STABLE UBiDiLevel U_EXPORT2 +U_CAPI UBiDiLevel U_EXPORT2 ubidi_getParaLevel(const UBiDi *pBiDi); /** @@ -1384,7 +1387,7 @@ ubidi_getParaLevel(const UBiDi *pBiDi); * @return The number of paragraphs. * @stable ICU 3.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_countParagraphs(UBiDi *pBiDi); /** @@ -1421,7 +1424,7 @@ ubidi_countParagraphs(UBiDi *pBiDi); * @see ubidi_getProcessedLength * @stable ICU 3.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart, int32_t *pParaLimit, UBiDiLevel *pParaLevel, UErrorCode *pErrorCode); @@ -1453,7 +1456,7 @@ ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart, * * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex, int32_t *pParaStart, int32_t *pParaLimit, UBiDiLevel *pParaLevel, UErrorCode *pErrorCode); @@ -1473,7 +1476,7 @@ ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex, * @see ubidi_getProcessedLength * @stable ICU 2.0 */ -U_STABLE UBiDiLevel U_EXPORT2 +U_CAPI UBiDiLevel U_EXPORT2 ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex); /** @@ -1494,7 +1497,7 @@ ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex); * @see ubidi_getProcessedLength * @stable ICU 2.0 */ -U_STABLE const UBiDiLevel * U_EXPORT2 +U_CAPI const UBiDiLevel * U_EXPORT2 ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode); /** @@ -1521,7 +1524,7 @@ ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode); * @see ubidi_getProcessedLength * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition, int32_t *pLogicalLimit, UBiDiLevel *pLevel); @@ -1540,7 +1543,7 @@ ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition, * @return The number of runs. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode); /** @@ -1599,7 +1602,7 @@ ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode); * to avoid these issues. * @stable ICU 2.0 */ -U_STABLE UBiDiDirection U_EXPORT2 +U_CAPI UBiDiDirection U_EXPORT2 ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex, int32_t *pLogicalStart, int32_t *pLength); @@ -1640,7 +1643,7 @@ ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex, * @see ubidi_getProcessedLength * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode); /** @@ -1675,7 +1678,7 @@ ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode) * @see ubidi_getResultLength * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode); /** @@ -1718,7 +1721,7 @@ ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode) * @see ubidi_getResultLength * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode); /** @@ -1754,7 +1757,7 @@ ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode); * @see ubidi_getResultLength * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode); /** @@ -1777,7 +1780,7 @@ ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode); * The index map will result in indexMap[logicalIndex]==visualIndex. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap); /** @@ -1800,7 +1803,7 @@ ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap * The index map will result in indexMap[visualIndex]==logicalIndex. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap); /** @@ -1835,7 +1838,7 @@ ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap) * @see UBIDI_MAP_NOWHERE * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length); /** option flags for ubidi_writeReordered() */ @@ -1940,7 +1943,7 @@ ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length); * @see UBIDI_OPTION_STREAMING * @stable ICU 3.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_getProcessedLength(const UBiDi *pBiDi); /** @@ -1970,7 +1973,7 @@ ubidi_getProcessedLength(const UBiDi *pBiDi); * @see UBIDI_OPTION_REMOVE_CONTROLS * @stable ICU 3.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_getResultLength(const UBiDi *pBiDi); U_CDECL_BEGIN @@ -2028,7 +2031,7 @@ U_CDECL_END * @see UBiDiClassCallback * @stable ICU 3.6 */ -U_STABLE UCharDirection U_EXPORT2 +U_CAPI UCharDirection U_EXPORT2 ubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c); /** @@ -2058,7 +2061,7 @@ ubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c); * @see ubidi_getClassCallback * @stable ICU 3.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn, const void *newContext, UBiDiClassCallback **oldFn, const void **oldContext, UErrorCode *pErrorCode); @@ -2075,7 +2078,7 @@ ubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn, * @see ubidi_setClassCallback * @stable ICU 3.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context); /** @@ -2143,7 +2146,7 @@ ubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **conte * @see ubidi_getProcessedLength * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_writeReordered(UBiDi *pBiDi, UChar *dest, int32_t destSize, uint16_t options, @@ -2195,7 +2198,7 @@ ubidi_writeReordered(UBiDi *pBiDi, * @return The length of the output string. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubidi_writeReverse(const UChar *src, int32_t srcLength, UChar *dest, int32_t destSize, uint16_t options, diff --git a/deps/icu-small/source/common/unicode/ubiditransform.h b/deps/icu-small/source/common/unicode/ubiditransform.h index 5c08ed5df0fd90..2dd7564010de17 100644 --- a/deps/icu-small/source/common/unicode/ubiditransform.h +++ b/deps/icu-small/source/common/unicode/ubiditransform.h @@ -21,7 +21,10 @@ #include "unicode/utypes.h" #include "unicode/ubidi.h" #include "unicode/uchar.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API /** * \file @@ -147,10 +150,10 @@ typedef struct UBiDiTransform UBiDiTransform; * calling ubidi_setPara with * paraLevel == UBIDI_DEFAULT_RTL,
  • *
  • : this is equivalent to - * calling ubidi_setInverse(UBiDi*, TRUE) and then + * calling ubidi_setInverse(UBiDi*, true) and then * ubidi_setPara with paraLevel == UBIDI_LTR,
  • *
  • : this is equivalent to - * calling ubidi_setInverse(UBiDi*, TRUE) and then + * calling ubidi_setInverse(UBiDi*, true) and then * ubidi_setPara with paraLevel == UBIDI_RTL.
  • * * All combinations that involve the Visual RTL scheme are unsupported by @@ -245,7 +248,7 @@ typedef struct UBiDiTransform UBiDiTransform; * @see u_shapeArabic * @stable ICU 58 */ -U_STABLE uint32_t U_EXPORT2 +U_CAPI uint32_t U_EXPORT2 ubiditransform_transform(UBiDiTransform *pBiDiTransform, const UChar *src, int32_t srcLength, UChar *dest, int32_t destSize, @@ -291,14 +294,14 @@ ubiditransform_transform(UBiDiTransform *pBiDiTransform, * @return An empty UBiDiTransform object. * @stable ICU 58 */ -U_STABLE UBiDiTransform* U_EXPORT2 +U_CAPI UBiDiTransform* U_EXPORT2 ubiditransform_open(UErrorCode *pErrorCode); /** * Deallocates the given UBiDiTransform object. * @stable ICU 58 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubiditransform_close(UBiDiTransform *pBidiTransform); #if U_SHOW_CPLUSPLUS_API diff --git a/deps/icu-small/source/common/unicode/ubrk.h b/deps/icu-small/source/common/unicode/ubrk.h index 73c1553b243957..37189a85984b68 100644 --- a/deps/icu-small/source/common/unicode/ubrk.h +++ b/deps/icu-small/source/common/unicode/ubrk.h @@ -13,7 +13,10 @@ #include "unicode/utypes.h" #include "unicode/uloc.h" #include "unicode/utext.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API /** * A text-break iterator. @@ -238,7 +241,7 @@ typedef enum USentenceBreakTag { * @see ubrk_openRules * @stable ICU 2.0 */ -U_STABLE UBreakIterator* U_EXPORT2 +U_CAPI UBreakIterator* U_EXPORT2 ubrk_open(UBreakIteratorType type, const char *locale, const UChar *text, @@ -260,7 +263,7 @@ ubrk_open(UBreakIteratorType type, * @see ubrk_open * @stable ICU 2.2 */ -U_STABLE UBreakIterator* U_EXPORT2 +U_CAPI UBreakIterator* U_EXPORT2 ubrk_openRules(const UChar *rules, int32_t rulesLength, const UChar *text, @@ -288,7 +291,7 @@ ubrk_openRules(const UChar *rules, * @see ubrk_getBinaryRules * @stable ICU 59 */ -U_STABLE UBreakIterator* U_EXPORT2 +U_CAPI UBreakIterator* U_EXPORT2 ubrk_openBinaryRules(const uint8_t *binaryRules, int32_t rulesLength, const UChar * text, int32_t textLength, UErrorCode * status); @@ -311,7 +314,7 @@ ubrk_openBinaryRules(const uint8_t *binaryRules, int32_t rulesLength, * @return pointer to the new clone * @stable ICU 2.0 */ -U_STABLE UBreakIterator * U_EXPORT2 +U_CAPI UBreakIterator * U_EXPORT2 ubrk_safeClone( const UBreakIterator *bi, void *stackBuffer, @@ -334,7 +337,7 @@ ubrk_safeClone( * @param bi The break iterator to close. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubrk_close(UBreakIterator *bi); #if U_SHOW_CPLUSPLUS_API @@ -368,7 +371,7 @@ U_NAMESPACE_END * @param status The error code * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubrk_setText(UBreakIterator* bi, const UChar* text, int32_t textLength, @@ -392,7 +395,7 @@ ubrk_setText(UBreakIterator* bi, * @param status The error code * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubrk_setUText(UBreakIterator* bi, UText* text, UErrorCode* status); @@ -407,7 +410,7 @@ ubrk_setUText(UBreakIterator* bi, * \ref ubrk_first, or \ref ubrk_last. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_current(const UBreakIterator *bi); /** @@ -419,7 +422,7 @@ ubrk_current(const UBreakIterator *bi); * @see ubrk_previous * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_next(UBreakIterator *bi); /** @@ -431,7 +434,7 @@ ubrk_next(UBreakIterator *bi); * @see ubrk_next * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_previous(UBreakIterator *bi); /** @@ -441,7 +444,7 @@ ubrk_previous(UBreakIterator *bi); * @see ubrk_last * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_first(UBreakIterator *bi); /** @@ -453,7 +456,7 @@ ubrk_first(UBreakIterator *bi); * @see ubrk_first * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_last(UBreakIterator *bi); /** @@ -465,7 +468,7 @@ ubrk_last(UBreakIterator *bi); * @see ubrk_following * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_preceding(UBreakIterator *bi, int32_t offset); @@ -478,7 +481,7 @@ ubrk_preceding(UBreakIterator *bi, * @see ubrk_preceding * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_following(UBreakIterator *bi, int32_t offset); @@ -491,7 +494,7 @@ ubrk_following(UBreakIterator *bi, * @see ubrk_countAvailable * @stable ICU 2.0 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 ubrk_getAvailable(int32_t index); /** @@ -502,7 +505,7 @@ ubrk_getAvailable(int32_t index); * @see ubrk_getAvailable * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_countAvailable(void); @@ -515,7 +518,7 @@ ubrk_countAvailable(void); * @return True if "offset" is a boundary position. * @stable ICU 2.0 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ubrk_isBoundary(UBreakIterator *bi, int32_t offset); /** @@ -527,7 +530,7 @@ ubrk_isBoundary(UBreakIterator *bi, int32_t offset); * For word break iterators, the possible values are defined in enum UWordBreak. * @stable ICU 2.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_getRuleStatus(UBreakIterator *bi); /** @@ -547,7 +550,7 @@ ubrk_getRuleStatus(UBreakIterator *bi); * the most recent boundary returned by the break iterator. * @stable ICU 3.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_getRuleStatusVec(UBreakIterator *bi, int32_t *fillInVec, int32_t capacity, UErrorCode *status); /** @@ -559,7 +562,7 @@ ubrk_getRuleStatusVec(UBreakIterator *bi, int32_t *fillInVec, int32_t capacity, * @return locale string * @stable ICU 2.8 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 ubrk_getLocaleByType(const UBreakIterator *bi, ULocDataLocaleType type, UErrorCode* status); /** @@ -587,7 +590,7 @@ ubrk_getLocaleByType(const UBreakIterator *bi, ULocDataLocaleType type, UErrorCo * * @stable ICU 49 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ubrk_refreshUText(UBreakIterator *bi, UText *text, UErrorCode *status); @@ -618,7 +621,7 @@ ubrk_refreshUText(UBreakIterator *bi, * @see ubrk_openBinaryRules * @stable ICU 59 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ubrk_getBinaryRules(UBreakIterator *bi, uint8_t * binaryRules, int32_t rulesCapacity, UErrorCode * status); diff --git a/deps/icu-small/source/common/unicode/ucasemap.h b/deps/icu-small/source/common/unicode/ucasemap.h index 6b253e3d638475..d1c1b483ab337e 100644 --- a/deps/icu-small/source/common/unicode/ucasemap.h +++ b/deps/icu-small/source/common/unicode/ucasemap.h @@ -22,10 +22,13 @@ #define __UCASEMAP_H__ #include "unicode/utypes.h" -#include "unicode/localpointer.h" #include "unicode/stringoptions.h" #include "unicode/ustring.h" +#if U_SHOW_CPLUSPLUS_API +#include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API + /** * \file * \brief C API: Unicode case mapping functions using a UCaseMap service object. @@ -69,7 +72,7 @@ typedef struct UCaseMap UCaseMap; /**< C typedef for struct UCaseMap. @stable IC * @see U_TITLECASE_NO_BREAK_ADJUSTMENT * @stable ICU 3.4 */ -U_STABLE UCaseMap * U_EXPORT2 +U_CAPI UCaseMap * U_EXPORT2 ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode); /** @@ -77,7 +80,7 @@ ucasemap_open(const char *locale, uint32_t options, UErrorCode *pErrorCode); * @param csm Object to be closed. * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucasemap_close(UCaseMap *csm); #if U_SHOW_CPLUSPLUS_API @@ -105,7 +108,7 @@ U_NAMESPACE_END * @return locale ID * @stable ICU 3.4 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ucasemap_getLocale(const UCaseMap *csm); /** @@ -114,7 +117,7 @@ ucasemap_getLocale(const UCaseMap *csm); * @return options bit set * @stable ICU 3.4 */ -U_STABLE uint32_t U_EXPORT2 +U_CAPI uint32_t U_EXPORT2 ucasemap_getOptions(const UCaseMap *csm); /** @@ -128,7 +131,7 @@ ucasemap_getOptions(const UCaseMap *csm); * @see ucasemap_open * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucasemap_setLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode); /** @@ -142,7 +145,7 @@ ucasemap_setLocale(UCaseMap *csm, const char *locale, UErrorCode *pErrorCode); * @see ucasemap_open * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode); #if !UCONFIG_NO_BREAK_ITERATION @@ -154,7 +157,7 @@ ucasemap_setOptions(UCaseMap *csm, uint32_t options, UErrorCode *pErrorCode); * @return titlecasing break iterator * @stable ICU 3.8 */ -U_STABLE const UBreakIterator * U_EXPORT2 +U_CAPI const UBreakIterator * U_EXPORT2 ucasemap_getBreakIterator(const UCaseMap *csm); /** @@ -177,7 +180,7 @@ ucasemap_getBreakIterator(const UCaseMap *csm); * @see ucasemap_utf8ToTitle * @stable ICU 3.8 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode *pErrorCode); /** @@ -226,7 +229,7 @@ ucasemap_setBreakIterator(UCaseMap *csm, UBreakIterator *iterToAdopt, UErrorCode * @see u_strToTitle * @stable ICU 3.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucasemap_toTitle(UCaseMap *csm, UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, @@ -257,7 +260,7 @@ ucasemap_toTitle(UCaseMap *csm, * @see u_strToLower * @stable ICU 3.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucasemap_utf8ToLower(const UCaseMap *csm, char *dest, int32_t destCapacity, const char *src, int32_t srcLength, @@ -286,7 +289,7 @@ ucasemap_utf8ToLower(const UCaseMap *csm, * @see u_strToUpper * @stable ICU 3.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucasemap_utf8ToUpper(const UCaseMap *csm, char *dest, int32_t destCapacity, const char *src, int32_t srcLength, @@ -338,7 +341,7 @@ ucasemap_utf8ToUpper(const UCaseMap *csm, * @see U_TITLECASE_NO_BREAK_ADJUSTMENT * @stable ICU 3.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucasemap_utf8ToTitle(UCaseMap *csm, char *dest, int32_t destCapacity, const char *src, int32_t srcLength, @@ -376,7 +379,7 @@ ucasemap_utf8ToTitle(UCaseMap *csm, * @see U_FOLD_CASE_EXCLUDE_SPECIAL_I * @stable ICU 3.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucasemap_utf8FoldCase(const UCaseMap *csm, char *dest, int32_t destCapacity, const char *src, int32_t srcLength, diff --git a/deps/icu-small/source/common/unicode/ucat.h b/deps/icu-small/source/common/unicode/ucat.h index f9c18b47d6c9b8..a177639a76bfcb 100644 --- a/deps/icu-small/source/common/unicode/ucat.h +++ b/deps/icu-small/source/common/unicode/ucat.h @@ -103,7 +103,7 @@ typedef UResourceBundle* u_nl_catd; * * @stable ICU 2.6 */ -U_STABLE u_nl_catd U_EXPORT2 +U_CAPI u_nl_catd U_EXPORT2 u_catopen(const char* name, const char* locale, UErrorCode* ec); /** @@ -114,7 +114,7 @@ u_catopen(const char* name, const char* locale, UErrorCode* ec); * * @stable ICU 2.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_catclose(u_nl_catd catd); /** @@ -149,7 +149,7 @@ u_catclose(u_nl_catd catd); * * @stable ICU 2.6 */ -U_STABLE const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 u_catgets(u_nl_catd catd, int32_t set_num, int32_t msg_num, const UChar* s, int32_t* len, UErrorCode* ec); diff --git a/deps/icu-small/source/common/unicode/uchar.h b/deps/icu-small/source/common/unicode/uchar.h index 3b55b2326dfc1f..1e0f82e706c482 100644 --- a/deps/icu-small/source/common/unicode/uchar.h +++ b/deps/icu-small/source/common/unicode/uchar.h @@ -80,7 +80,7 @@ U_CDECL_BEGIN * and the ICU User Guide chapter on Properties (http://icu-project.org/userguide/properties.html). * * Many properties are accessible via generic functions that take a UProperty selector. - * - u_hasBinaryProperty() returns a binary value (TRUE/FALSE) per property and code point. + * - u_hasBinaryProperty() returns a binary value (true/false) per property and code point. * - u_getIntPropertyValue() returns an integer value per property and code point. * For each supported enumerated or catalog property, there is * an enum type for all of the property's values, and @@ -2586,8 +2586,8 @@ typedef enum UVerticalOrientation { * @param c Code point to test. * @param which UProperty selector constant, identifies which binary property to check. * Must be UCHAR_BINARY_START<=which(remainingMatchLength_ + 2) << kState64RemainingShift) | @@ -123,14 +122,13 @@ class U_COMMON_API UCharsTrie : public UMemory { * @see getState64 * @see resetToState * @see reset - * @draft ICU 65 + * @stable ICU 65 */ UCharsTrie &resetToState64(uint64_t state) { remainingMatchLength_ = static_cast(state >> kState64RemainingShift) - 2; pos_ = uchars_ + (state & kState64PosMask); return *this; } -#endif /* U_HIDE_DRAFT_API */ /** * UCharsTrie state object, for saving a trie's current state @@ -268,16 +266,16 @@ class U_COMMON_API UCharsTrie : public UMemory { /** * Determines whether all strings reachable from the current state * map to the same value. - * @param uniqueValue Receives the unique value, if this function returns TRUE. + * @param uniqueValue Receives the unique value, if this function returns true. * (output-only) - * @return TRUE if all strings reachable from the current state + * @return true if all strings reachable from the current state * map to the same value. * @stable ICU 4.8 */ inline UBool hasUniqueValue(int32_t &uniqueValue) const { const char16_t *pos=pos_; // Skip the rest of a pending linear-match node. - return pos!=NULL && findUniqueValue(pos+remainingMatchLength_+1, FALSE, uniqueValue); + return pos!=NULL && findUniqueValue(pos+remainingMatchLength_+1, false, uniqueValue); } /** @@ -335,7 +333,7 @@ class U_COMMON_API UCharsTrie : public UMemory { Iterator &reset(); /** - * @return TRUE if there are more elements. + * @return true if there are more elements. * @stable ICU 4.8 */ UBool hasNext() const; @@ -351,7 +349,7 @@ class U_COMMON_API UCharsTrie : public UMemory { * pass the U_SUCCESS() test, or else the function returns * immediately. Check for U_FAILURE() on output or use with * function chaining. (See User Guide for details.) - * @return TRUE if there is another element. + * @return true if there is another element. * @stable ICU 4.8 */ UBool next(UErrorCode &errorCode); @@ -371,7 +369,7 @@ class U_COMMON_API UCharsTrie : public UMemory { UBool truncateAndStop() { pos_=NULL; value_=-1; // no real value for str - return TRUE; + return true; } const char16_t *branchNext(const char16_t *pos, int32_t length, UErrorCode &errorCode); diff --git a/deps/icu-small/source/common/unicode/ucharstriebuilder.h b/deps/icu-small/source/common/unicode/ucharstriebuilder.h index 540dcc047fd563..15657702f9d024 100644 --- a/deps/icu-small/source/common/unicode/ucharstriebuilder.h +++ b/deps/icu-small/source/common/unicode/ucharstriebuilder.h @@ -101,9 +101,10 @@ class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder { * Multiple calls to buildUnicodeString() set the UnicodeStrings to the * builder's same char16_t array, without rebuilding. * If buildUnicodeString() is called after build(), the trie will be - * re-serialized into a new array. - * If build() is called after buildUnicodeString(), the trie object will become - * the owner of the previously returned array. + * re-serialized into a new array (because build() passes on ownership). + * If build() is called after buildUnicodeString(), the trie object returned + * by build() will become the owner of the underlying data for the + * previously returned UnicodeString. * After clear() has been called, a new array will be used as well. * @param buildOption Build option, see UStringTrieBuildOption. * @param result A UnicodeString which will be set to the char16_t-serialized @@ -147,7 +148,7 @@ class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder { virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const; virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, char16_t unit) const; - virtual UBool matchNodesCanHaveValues() const { return TRUE; } + virtual UBool matchNodesCanHaveValues() const { return true; } virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; } virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; } diff --git a/deps/icu-small/source/common/unicode/uchriter.h b/deps/icu-small/source/common/unicode/uchriter.h index bee842cc259f07..84309b2416d136 100644 --- a/deps/icu-small/source/common/unicode/uchriter.h +++ b/deps/icu-small/source/common/unicode/uchriter.h @@ -274,11 +274,11 @@ class U_COMMON_API UCharCharacterIterator : public CharacterIterator { virtual UChar32 next32PostInc(void); /** - * Returns FALSE if there are no more code units or code points + * Returns false if there are no more code units or code points * at or after the current position in the iteration range. * This is used with nextPostInc() or next32PostInc() in forward * iteration. - * @return FALSE if there are no more code units or code points + * @return false if there are no more code units or code points * at or after the current position in the iteration range. * @stable ICU 2.0 */ @@ -303,11 +303,11 @@ class U_COMMON_API UCharCharacterIterator : public CharacterIterator { virtual UChar32 previous32(void); /** - * Returns FALSE if there are no more code units or code points + * Returns false if there are no more code units or code points * before the current position in the iteration range. * This is used with previous() or previous32() in backward * iteration. - * @return FALSE if there are no more code units or code points + * @return false if there are no more code units or code points * before the current position in the iteration range. * @stable ICU 2.0 */ diff --git a/deps/icu-small/source/common/unicode/uclean.h b/deps/icu-small/source/common/unicode/uclean.h index ab0cd6da6ba780..f03593964a4edd 100644 --- a/deps/icu-small/source/common/unicode/uclean.h +++ b/deps/icu-small/source/common/unicode/uclean.h @@ -49,7 +49,7 @@ * * @stable ICU 2.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_init(UErrorCode *status); #ifndef U_HIDE_SYSTEM_API @@ -98,7 +98,7 @@ u_init(UErrorCode *status); * @stable ICU 2.0 * @system */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_cleanup(void); U_CDECL_BEGIN @@ -148,7 +148,7 @@ typedef void U_CALLCONV UMemFreeFn (const void *context, void *mem); * @stable ICU 2.8 * @system */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_setMemoryFunctions(const void *context, UMemAllocFn * U_CALLCONV_FPTR a, UMemReallocFn * U_CALLCONV_FPTR r, UMemFreeFn * U_CALLCONV_FPTR f, UErrorCode *status); diff --git a/deps/icu-small/source/common/unicode/ucnv.h b/deps/icu-small/source/common/unicode/ucnv.h index ec7c5f350b4973..58f271cfb5adf2 100644 --- a/deps/icu-small/source/common/unicode/ucnv.h +++ b/deps/icu-small/source/common/unicode/ucnv.h @@ -51,7 +51,10 @@ #include "unicode/ucnv_err.h" #include "unicode/uenum.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API #if !defined(USET_DEFINED) && !defined(U_IN_DOXYGEN) @@ -308,7 +311,7 @@ U_CDECL_END * lexically follows name2. * @stable ICU 2.0 */ -U_STABLE int U_EXPORT2 +U_CAPI int U_EXPORT2 ucnv_compareNames(const char *name1, const char *name2); @@ -362,7 +365,7 @@ ucnv_compareNames(const char *name1, const char *name2); * @see ucnv_compareNames * @stable ICU 2.0 */ -U_STABLE UConverter* U_EXPORT2 +U_CAPI UConverter* U_EXPORT2 ucnv_open(const char *converterName, UErrorCode *err); @@ -392,7 +395,7 @@ ucnv_open(const char *converterName, UErrorCode *err); * @see ucnv_compareNames * @stable ICU 2.0 */ -U_STABLE UConverter* U_EXPORT2 +U_CAPI UConverter* U_EXPORT2 ucnv_openU(const UChar *name, UErrorCode *err); @@ -460,7 +463,7 @@ ucnv_openU(const UChar *name, * @see UConverterPlatform * @stable ICU 2.0 */ -U_STABLE UConverter* U_EXPORT2 +U_CAPI UConverter* U_EXPORT2 ucnv_openCCSID(int32_t codepage, UConverterPlatform platform, UErrorCode * err); @@ -476,7 +479,7 @@ ucnv_openCCSID(int32_t codepage, *

    The name will NOT be looked up in the alias mechanism, nor will the converter be * stored in the converter cache or the alias table. The only way to open further converters * is call this function multiple times, or use the ucnv_safeClone() function to clone a - * 'master' converter.

    + * 'primary' converter.

    * *

    A future version of ICU may add alias table lookups and/or caching * to this function.

    @@ -495,7 +498,7 @@ ucnv_openCCSID(int32_t codepage, * @see ucnv_close * @stable ICU 2.2 */ -U_STABLE UConverter* U_EXPORT2 +U_CAPI UConverter* U_EXPORT2 ucnv_openPackage(const char *packageName, const char *converterName, UErrorCode *err); /** @@ -537,7 +540,7 @@ ucnv_openPackage(const char *packageName, const char *converterName, UErrorCode * @return pointer to the new clone * @stable ICU 2.0 */ -U_STABLE UConverter * U_EXPORT2 +U_CAPI UConverter * U_EXPORT2 ucnv_safeClone(const UConverter *cnv, void *stackBuffer, int32_t *pBufferSize, @@ -566,7 +569,7 @@ ucnv_safeClone(const UConverter *cnv, * @see ucnv_openCCSID * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_close(UConverter * converter); #if U_SHOW_CPLUSPLUS_API @@ -605,7 +608,7 @@ U_NAMESPACE_END * @see ucnv_setSubstChars * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_getSubstChars(const UConverter *converter, char *subChars, int8_t *len, @@ -630,7 +633,7 @@ ucnv_getSubstChars(const UConverter *converter, * @see ucnv_getSubstChars * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_setSubstChars(UConverter *converter, const char *subChars, int8_t len, @@ -663,7 +666,7 @@ ucnv_setSubstChars(UConverter *converter, * @see ucnv_getSubstChars * @stable ICU 3.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_setSubstString(UConverter *cnv, const UChar *s, int32_t length, @@ -682,7 +685,7 @@ ucnv_setSubstString(UConverter *cnv, * U_INDEX_OUTOFBOUNDS_ERROR will be returned. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_getInvalidChars(const UConverter *converter, char *errBytes, int8_t *len, @@ -701,7 +704,7 @@ ucnv_getInvalidChars(const UConverter *converter, * U_INDEX_OUTOFBOUNDS_ERROR will be returned. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_getInvalidUChars(const UConverter *converter, UChar *errUChars, int8_t *len, @@ -714,7 +717,7 @@ ucnv_getInvalidUChars(const UConverter *converter, * @param converter the Unicode converter * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_reset(UConverter *converter); /** @@ -725,7 +728,7 @@ ucnv_reset(UConverter *converter); * @param converter the Unicode converter * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_resetToUnicode(UConverter *converter); /** @@ -736,7 +739,7 @@ ucnv_resetToUnicode(UConverter *converter); * @param converter the Unicode converter * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_resetFromUnicode(UConverter *converter); /** @@ -789,7 +792,7 @@ ucnv_resetFromUnicode(UConverter *converter); * @see ucnv_getMinCharSize * @stable ICU 2.0 */ -U_STABLE int8_t U_EXPORT2 +U_CAPI int8_t U_EXPORT2 ucnv_getMaxCharSize(const UConverter *converter); /** @@ -822,7 +825,7 @@ ucnv_getMaxCharSize(const UConverter *converter); * @see ucnv_getMaxCharSize * @stable ICU 2.0 */ -U_STABLE int8_t U_EXPORT2 +U_CAPI int8_t U_EXPORT2 ucnv_getMinCharSize(const UConverter *converter); /** @@ -839,7 +842,7 @@ ucnv_getMinCharSize(const UConverter *converter); * @see ucnv_getName * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucnv_getDisplayName(const UConverter *converter, const char *displayLocale, UChar *displayName, @@ -856,7 +859,7 @@ ucnv_getDisplayName(const UConverter *converter, * @see ucnv_getDisplayName * @stable ICU 2.0 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ucnv_getName(const UConverter *converter, UErrorCode *err); /** @@ -882,7 +885,7 @@ ucnv_getName(const UConverter *converter, UErrorCode *err); * @see ucnv_getPlatform * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucnv_getCCSID(const UConverter *converter, UErrorCode *err); @@ -896,7 +899,7 @@ ucnv_getCCSID(const UConverter *converter, * @return The codepage platform * @stable ICU 2.0 */ -U_STABLE UConverterPlatform U_EXPORT2 +U_CAPI UConverterPlatform U_EXPORT2 ucnv_getPlatform(const UConverter *converter, UErrorCode *err); @@ -908,14 +911,14 @@ ucnv_getPlatform(const UConverter *converter, * @return the type of the converter * @stable ICU 2.0 */ -U_STABLE UConverterType U_EXPORT2 +U_CAPI UConverterType U_EXPORT2 ucnv_getType(const UConverter * converter); /** * Gets the "starter" (lead) bytes for converters of type MBCS. * Will fill in an U_ILLEGAL_ARGUMENT_ERROR if converter passed in * is not MBCS. Fills in an array of type UBool, with the value of the byte - * as offset to the array. For example, if (starters[0x20] == TRUE) at return, + * as offset to the array. For example, if (starters[0x20] == true) at return, * it means that the byte 0x20 is a starter byte in this converter. * Context pointers are always owned by the caller. * @@ -926,7 +929,7 @@ ucnv_getType(const UConverter * converter); * @see ucnv_getType * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_getStarters(const UConverter* converter, UBool starters[256], UErrorCode* err); @@ -997,7 +1000,7 @@ typedef enum UConverterUnicodeSet { * @see uset_close * @stable ICU 2.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_getUnicodeSet(const UConverter *cnv, USet *setFillIn, UConverterUnicodeSet whichSet, @@ -1014,7 +1017,7 @@ ucnv_getUnicodeSet(const UConverter *cnv, * @see ucnv_setToUCallBack * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_getToUCallBack (const UConverter * converter, UConverterToUCallback *action, const void **context); @@ -1030,7 +1033,7 @@ ucnv_getToUCallBack (const UConverter * converter, * @see ucnv_setFromUCallBack * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_getFromUCallBack (const UConverter * converter, UConverterFromUCallback *action, const void **context); @@ -1050,7 +1053,7 @@ ucnv_getFromUCallBack (const UConverter * converter, * @see ucnv_getToUCallBack * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_setToUCallBack (UConverter * converter, UConverterToUCallback newAction, const void* newContext, @@ -1073,7 +1076,7 @@ ucnv_setToUCallBack (UConverter * converter, * @see ucnv_getFromUCallBack * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_setFromUCallBack (UConverter * converter, UConverterFromUCallback newAction, const void *newContext, @@ -1100,7 +1103,7 @@ ucnv_setFromUCallBack (UConverter * converter, * consumed. At that point, the caller should reset the source and * sourceLimit pointers to point to the next chunk. * - * At the end of the stream (flush==TRUE), the input is completely consumed + * At the end of the stream (flush==true), the input is completely consumed * when *source==sourceLimit and no error code is set. * The converter object is then automatically reset by this function. * (This means that a converter need not be reset explicitly between data @@ -1125,9 +1128,9 @@ ucnv_setFromUCallBack (UConverter * converter, * e.g: offsets[3] is equal to 6, it means that the target[3] was a result of transcoding source[6] * For output data carried across calls, and other data without a specific source character * (such as from escape sequences or callbacks) -1 will be placed for offsets. - * @param flush set to TRUE if the current source buffer is the last available - * chunk of the source, FALSE otherwise. Note that if a failing status is returned, - * this function may have to be called multiple times with flush set to TRUE until + * @param flush set to true if the current source buffer is the last available + * chunk of the source, false otherwise. Note that if a failing status is returned, + * this function may have to be called multiple times with flush set to true until * the source buffer is consumed. * @param err the error status. U_ILLEGAL_ARGUMENT_ERROR will be set if the * converter is NULL. @@ -1139,7 +1142,7 @@ ucnv_setFromUCallBack (UConverter * converter, * @see ucnv_setToUCallBack * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_fromUnicode (UConverter * converter, char **target, const char *targetLimit, @@ -1169,7 +1172,7 @@ ucnv_fromUnicode (UConverter * converter, * consumed. At that point, the caller should reset the source and * sourceLimit pointers to point to the next chunk. * - * At the end of the stream (flush==TRUE), the input is completely consumed + * At the end of the stream (flush==true), the input is completely consumed * when *source==sourceLimit and no error code is set * The converter object is then automatically reset by this function. * (This means that a converter need not be reset explicitly between data @@ -1193,9 +1196,9 @@ ucnv_fromUnicode (UConverter * converter, * e.g: offsets[3] is equal to 6, it means that the target[3] was a result of transcoding source[6] * For output data carried across calls, and other data without a specific source character * (such as from escape sequences or callbacks) -1 will be placed for offsets. - * @param flush set to TRUE if the current source buffer is the last available - * chunk of the source, FALSE otherwise. Note that if a failing status is returned, - * this function may have to be called multiple times with flush set to TRUE until + * @param flush set to true if the current source buffer is the last available + * chunk of the source, false otherwise. Note that if a failing status is returned, + * this function may have to be called multiple times with flush set to true until * the source buffer is consumed. * @param err the error status. U_ILLEGAL_ARGUMENT_ERROR will be set if the * converter is NULL. @@ -1208,7 +1211,7 @@ ucnv_fromUnicode (UConverter * converter, * @see ucnv_getNextUChar * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_toUnicode(UConverter *converter, UChar **target, const UChar *targetLimit, @@ -1245,7 +1248,7 @@ ucnv_toUnicode(UConverter *converter, * @see UCNV_GET_MAX_BYTES_FOR_STRING * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucnv_fromUChars(UConverter *cnv, char *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, @@ -1277,7 +1280,7 @@ ucnv_fromUChars(UConverter *cnv, * @see ucnv_convert * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucnv_toUChars(UConverter *cnv, UChar *dest, int32_t destCapacity, const char *src, int32_t srcLength, @@ -1295,7 +1298,7 @@ ucnv_toUChars(UConverter *cnv, * - Convenient. * * Limitations compared to ucnv_toUnicode(): - * - Always assumes flush=TRUE. + * - Always assumes flush=true. * This makes ucnv_getNextUChar() unsuitable for "streaming" conversion, * that is, for where the input is supplied in multiple buffers, * because ucnv_getNextUChar() will assume the end of the input at the end @@ -1306,7 +1309,7 @@ ucnv_toUChars(UConverter *cnv, * ucnv_getNextUChar() uses the current state of the converter * (unlike ucnv_toUChars() which always resets first). * However, if ucnv_getNextUChar() is called after ucnv_toUnicode() - * stopped in the middle of a character sequence (with flush=FALSE), + * stopped in the middle of a character sequence (with flush=false), * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode() * internally until the next character boundary. * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to @@ -1353,7 +1356,7 @@ ucnv_toUChars(UConverter *cnv, * @see ucnv_convert * @stable ICU 2.0 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 ucnv_getNextUChar(UConverter * converter, const char **source, const char * sourceLimit, @@ -1385,7 +1388,7 @@ ucnv_getNextUChar(UConverter * converter, * * ucnv_convertEx() also provides further convenience: * - an option to reset the converters at the beginning - * (if reset==TRUE, see parameters; + * (if reset==true, see parameters; * also sets *pivotTarget=*pivotSource=pivotStart) * - allow NUL-terminated input * (only a single NUL byte, will not work for charsets with multi-byte NULs) @@ -1442,7 +1445,7 @@ ucnv_getNextUChar(UConverter * converter, * &target, u8+capacity, * &s, s+length, * NULL, NULL, NULL, NULL, - * TRUE, TRUE, + * true, true, * pErrorCode); * * myReleaseCachedUTF8Converter(utf8Cnv); @@ -1474,7 +1477,7 @@ ucnv_getNextUChar(UConverter * converter, * It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit * and pivotStartNULL is returned. Owned by the library. * @stable ICU 2.0 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode); /** @@ -1853,7 +1856,7 @@ ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorC * @see ucnv_getStandardName * @stable ICU 2.4 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode); /** @@ -1870,7 +1873,7 @@ ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErro * @see ucnv_setDefaultName * @stable ICU 2.0 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ucnv_getDefaultName(void); #ifndef U_HIDE_SYSTEM_API @@ -1890,7 +1893,7 @@ ucnv_getDefaultName(void); * @system * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_setDefaultName(const char *name); #endif /* U_HIDE_SYSTEM_API */ @@ -1911,18 +1914,18 @@ ucnv_setDefaultName(const char *name); * @see ucnv_isAmbiguous * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_fixFileSeparator(const UConverter *cnv, UChar *source, int32_t sourceLen); /** * Determines if the converter contains ambiguous mappings of the same * character or not. * @param cnv the converter to be tested - * @return TRUE if the converter contains ambiguous mapping of the same - * character, FALSE otherwise. + * @return true if the converter contains ambiguous mapping of the same + * character, false otherwise. * @stable ICU 2.0 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ucnv_isAmbiguous(const UConverter *cnv); /** @@ -1935,12 +1938,12 @@ ucnv_isAmbiguous(const UConverter *cnv); * http://www.icu-project.org/userguide/conversion-data.html#ucmformat * * @param cnv The converter to set the fallback mapping usage on. - * @param usesFallback TRUE if the user wants the converter to take advantage of the fallback - * mapping, FALSE otherwise. + * @param usesFallback true if the user wants the converter to take advantage of the fallback + * mapping, false otherwise. * @stable ICU 2.0 * @see ucnv_usesFallback */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_setFallback(UConverter *cnv, UBool usesFallback); /** @@ -1948,11 +1951,11 @@ ucnv_setFallback(UConverter *cnv, UBool usesFallback); * This flag has restrictions, see ucnv_setFallback(). * * @param cnv The converter to be tested - * @return TRUE if the converter uses fallback, FALSE otherwise. + * @return true if the converter uses fallback, false otherwise. * @stable ICU 2.0 * @see ucnv_setFallback */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ucnv_usesFallback(const UConverter *cnv); /** @@ -1984,7 +1987,7 @@ ucnv_usesFallback(const UConverter *cnv); * @return The name of the encoding detected. NULL if encoding is not detected. * @stable ICU 2.4 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 ucnv_detectUnicodeSignature(const char* source, int32_t sourceLength, int32_t *signatureLength, @@ -2001,7 +2004,7 @@ ucnv_detectUnicodeSignature(const char* source, * @return The number of UChars in the state. -1 if an error is encountered. * @stable ICU 3.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status); /** @@ -2015,7 +2018,7 @@ ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status); * @return The number of chars in the state. -1 if an error is encountered. * @stable ICU 3.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status); /** @@ -2027,13 +2030,13 @@ ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status); * but a UTF-32 converter encodes each code point with 4 bytes. * Note: This method is not intended to be used to determine whether the charset has a * fixed ratio of bytes to Unicode codes units for any particular Unicode encoding form. - * FALSE is returned with the UErrorCode if error occurs or cnv is NULL. + * false is returned with the UErrorCode if error occurs or cnv is NULL. * @param cnv The converter to be tested * @param status ICU error code in/out paramter - * @return TRUE if the converter is fixed-width + * @return true if the converter is fixed-width * @stable ICU 4.8 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status); #endif diff --git a/deps/icu-small/source/common/unicode/ucnv_cb.h b/deps/icu-small/source/common/unicode/ucnv_cb.h index 632cc0b35f26c5..18240990dbaed9 100644 --- a/deps/icu-small/source/common/unicode/ucnv_cb.h +++ b/deps/icu-small/source/common/unicode/ucnv_cb.h @@ -84,7 +84,7 @@ * @see ucnv_cbFromUWriteSub * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args, const char* source, int32_t length, @@ -104,7 +104,7 @@ ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args, * @see ucnv_cbFromUWriteBytes * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode * err); @@ -121,7 +121,7 @@ ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args, * @see ucnv_cbToUWriteSub * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, +U_CAPI void U_EXPORT2 ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, const UChar** source, const UChar* sourceLimit, int32_t offsetIndex, @@ -140,7 +140,7 @@ U_STABLE void U_EXPORT2 ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, * @see ucnv_cbToUWriteSub * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args, +U_CAPI void U_EXPORT2 ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args, const UChar* source, int32_t length, int32_t offsetIndex, @@ -156,7 +156,7 @@ U_STABLE void U_EXPORT2 ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args, * @see ucnv_cbToUWriteUChars * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args, +U_CAPI void U_EXPORT2 ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args, int32_t offsetIndex, UErrorCode * err); #endif diff --git a/deps/icu-small/source/common/unicode/ucnv_err.h b/deps/icu-small/source/common/unicode/ucnv_err.h index 08c96c14407c22..bff90f0ba1e1d4 100644 --- a/deps/icu-small/source/common/unicode/ucnv_err.h +++ b/deps/icu-small/source/common/unicode/ucnv_err.h @@ -193,7 +193,7 @@ typedef enum { */ typedef struct { uint16_t size; /**< The size of this struct. @stable ICU 2.0 */ - UBool flush; /**< The internal state of converter will be reset and data flushed if set to TRUE. @stable ICU 2.0 */ + UBool flush; /**< The internal state of converter will be reset and data flushed if set to true. @stable ICU 2.0 */ UConverter *converter; /**< Pointer to the converter that is opened and to which this struct is passed as an argument. @stable ICU 2.0 */ const UChar *source; /**< Pointer to the source source buffer. @stable ICU 2.0 */ const UChar *sourceLimit; /**< Pointer to the limit (end + 1) of source buffer. @stable ICU 2.0 */ @@ -209,7 +209,7 @@ typedef struct { */ typedef struct { uint16_t size; /**< The size of this struct @stable ICU 2.0 */ - UBool flush; /**< The internal state of converter will be reset and data flushed if set to TRUE. @stable ICU 2.0 */ + UBool flush; /**< The internal state of converter will be reset and data flushed if set to true. @stable ICU 2.0 */ UConverter *converter; /**< Pointer to the converter that is opened and to which this struct is passed as an argument. @stable ICU 2.0 */ const char *source; /**< Pointer to the source source buffer. @stable ICU 2.0 */ const char *sourceLimit; /**< Pointer to the limit (end + 1) of source buffer. @stable ICU 2.0 */ @@ -233,7 +233,7 @@ typedef struct { * @param err This should always be set to a failure status prior to calling. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 UCNV_FROM_U_CALLBACK_STOP ( +U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_STOP ( const void *context, UConverterFromUnicodeArgs *fromUArgs, const UChar* codeUnits, @@ -257,7 +257,7 @@ U_STABLE void U_EXPORT2 UCNV_FROM_U_CALLBACK_STOP ( * @param err This should always be set to a failure status prior to calling. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 UCNV_TO_U_CALLBACK_STOP ( +U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_STOP ( const void *context, UConverterToUnicodeArgs *toUArgs, const char* codeUnits, @@ -284,7 +284,7 @@ U_STABLE void U_EXPORT2 UCNV_TO_U_CALLBACK_STOP ( * otherwise this value will be set to a failure status. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 UCNV_FROM_U_CALLBACK_SKIP ( +U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_SKIP ( const void *context, UConverterFromUnicodeArgs *fromUArgs, const UChar* codeUnits, @@ -314,7 +314,7 @@ U_STABLE void U_EXPORT2 UCNV_FROM_U_CALLBACK_SKIP ( * @see ucnv_setSubstChars * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 UCNV_FROM_U_CALLBACK_SUBSTITUTE ( +U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_SUBSTITUTE ( const void *context, UConverterFromUnicodeArgs *fromUArgs, const UChar* codeUnits, @@ -370,7 +370,7 @@ U_STABLE void U_EXPORT2 UCNV_FROM_U_CALLBACK_SUBSTITUTE ( * otherwise this value will be set to a failure status. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 UCNV_FROM_U_CALLBACK_ESCAPE ( +U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_ESCAPE ( const void *context, UConverterFromUnicodeArgs *fromUArgs, const UChar* codeUnits, @@ -398,7 +398,7 @@ U_STABLE void U_EXPORT2 UCNV_FROM_U_CALLBACK_ESCAPE ( * otherwise this value will be set to a failure status. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 UCNV_TO_U_CALLBACK_SKIP ( +U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_SKIP ( const void *context, UConverterToUnicodeArgs *toUArgs, const char* codeUnits, @@ -424,7 +424,7 @@ U_STABLE void U_EXPORT2 UCNV_TO_U_CALLBACK_SKIP ( * otherwise this value will be set to a failure status. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 UCNV_TO_U_CALLBACK_SUBSTITUTE ( +U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_SUBSTITUTE ( const void *context, UConverterToUnicodeArgs *toUArgs, const char* codeUnits, @@ -450,7 +450,7 @@ U_STABLE void U_EXPORT2 UCNV_TO_U_CALLBACK_SUBSTITUTE ( * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 UCNV_TO_U_CALLBACK_ESCAPE ( +U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_ESCAPE ( const void *context, UConverterToUnicodeArgs *toUArgs, const char* codeUnits, diff --git a/deps/icu-small/source/common/unicode/ucnvsel.h b/deps/icu-small/source/common/unicode/ucnvsel.h index 5fee53f179ace7..b84bc86bed2659 100644 --- a/deps/icu-small/source/common/unicode/ucnvsel.h +++ b/deps/icu-small/source/common/unicode/ucnvsel.h @@ -29,7 +29,10 @@ #include "unicode/utf16.h" #include "unicode/uenum.h" #include "unicode/ucnv.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API /** * \file @@ -72,7 +75,7 @@ typedef struct UConverterSelector UConverterSelector; * * @stable ICU 4.2 */ -U_STABLE UConverterSelector* U_EXPORT2 +U_CAPI UConverterSelector* U_EXPORT2 ucnvsel_open(const char* const* converterList, int32_t converterListSize, const USet* excludedCodePoints, const UConverterUnicodeSet whichSet, UErrorCode* status); @@ -90,7 +93,7 @@ ucnvsel_open(const char* const* converterList, int32_t converterListSize, * * @stable ICU 4.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ucnvsel_close(UConverterSelector *sel); #if U_SHOW_CPLUSPLUS_API @@ -127,7 +130,7 @@ U_NAMESPACE_END * * @stable ICU 4.2 */ -U_STABLE UConverterSelector* U_EXPORT2 +U_CAPI UConverterSelector* U_EXPORT2 ucnvsel_openFromSerialized(const void* buffer, int32_t length, UErrorCode* status); /** @@ -144,7 +147,7 @@ ucnvsel_openFromSerialized(const void* buffer, int32_t length, UErrorCode* statu * * @stable ICU 4.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucnvsel_serialize(const UConverterSelector* sel, void* buffer, int32_t bufferCapacity, UErrorCode* status); @@ -162,7 +165,7 @@ ucnvsel_serialize(const UConverterSelector* sel, * * @stable ICU 4.2 */ -U_STABLE UEnumeration * U_EXPORT2 +U_CAPI UEnumeration * U_EXPORT2 ucnvsel_selectForString(const UConverterSelector* sel, const UChar *s, int32_t length, UErrorCode *status); @@ -180,7 +183,7 @@ ucnvsel_selectForString(const UConverterSelector* sel, * * @stable ICU 4.2 */ -U_STABLE UEnumeration * U_EXPORT2 +U_CAPI UEnumeration * U_EXPORT2 ucnvsel_selectForUTF8(const UConverterSelector* sel, const char *s, int32_t length, UErrorCode *status); diff --git a/deps/icu-small/source/common/unicode/ucptrie.h b/deps/icu-small/source/common/unicode/ucptrie.h index be06a227928286..b95491b183e9af 100644 --- a/deps/icu-small/source/common/unicode/ucptrie.h +++ b/deps/icu-small/source/common/unicode/ucptrie.h @@ -8,11 +8,13 @@ #define __UCPTRIE_H__ #include "unicode/utypes.h" - -#include "unicode/localpointer.h" #include "unicode/ucpmap.h" #include "unicode/utf8.h" +#if U_SHOW_CPLUSPLUS_API +#include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API + U_CDECL_BEGIN /** @@ -580,11 +582,11 @@ enum { // Do not conditionalize with #ifndef U_HIDE_INTERNAL_API, needed for public API /** @internal */ -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucptrie_internalSmallIndex(const UCPTrie *trie, UChar32 c); /** @internal */ -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucptrie_internalSmallU8Index(const UCPTrie *trie, int32_t lt1, uint8_t t2, uint8_t t3); /** @@ -592,7 +594,7 @@ ucptrie_internalSmallU8Index(const UCPTrie *trie, int32_t lt1, uint8_t t2, uint8 * Do not call directly. * @internal */ -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucptrie_internalU8PrevIndex(const UCPTrie *trie, UChar32 c, const uint8_t *start, const uint8_t *src); diff --git a/deps/icu-small/source/common/unicode/ucurr.h b/deps/icu-small/source/common/unicode/ucurr.h index 7149e7adf13067..4e115cd01e0fb6 100644 --- a/deps/icu-small/source/common/unicode/ucurr.h +++ b/deps/icu-small/source/common/unicode/ucurr.h @@ -78,7 +78,7 @@ typedef enum UCurrencyUsage UCurrencyUsage; * invalid. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucurr_forLocale(const char* locale, UChar* buff, int32_t buffCapacity, @@ -113,7 +113,29 @@ typedef enum UCurrNameStyle { * * @stable ICU 61 */ - UCURR_NARROW_SYMBOL_NAME + UCURR_NARROW_SYMBOL_NAME, + +#ifndef U_HIDE_DRAFT_API + /** + * Selector for getName() indicating the formal currency symbol. + * The formal currency symbol is similar to the regular currency + * symbol, but it always takes the form used in formal settings + * such as banking; for example, "NT$" instead of "$" for TWD in zh-TW. + * + * @draft ICU 68 + */ + UCURR_FORMAL_SYMBOL_NAME, + + /** + * Selector for getName() indicating the variant currency symbol. + * The variant symbol for a currency is an alternative symbol + * that is not necessarily as widely used as the regular symbol. + * + * @draft ICU 68 + */ + UCURR_VARIANT_SYMBOL_NAME +#endif // U_HIDE_DRAFT_API + } UCurrNameStyle; #if !UCONFIG_NO_SERVICE @@ -133,7 +155,7 @@ typedef const void* UCurrRegistryKey; * if there was an error. * @stable ICU 2.6 */ -U_STABLE UCurrRegistryKey U_EXPORT2 +U_CAPI UCurrRegistryKey U_EXPORT2 ucurr_register(const UChar* isoCode, const char* locale, UErrorCode* status); @@ -145,10 +167,10 @@ ucurr_register(const UChar* isoCode, * restored. * @param key the registry key returned by a previous call to ucurr_register * @param status the in/out status code, no special meanings are assigned - * @return TRUE if the currency for this key was successfully unregistered + * @return true if the currency for this key was successfully unregistered * @stable ICU 2.6 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ucurr_unregister(UCurrRegistryKey key, UErrorCode* status); #endif /* UCONFIG_NO_SERVICE */ @@ -159,7 +181,7 @@ ucurr_unregister(UCurrRegistryKey key, UErrorCode* status); * @param currency null-terminated 3-letter ISO 4217 code * @param locale locale in which to display currency * @param nameStyle selector for which kind of name to return - * @param isChoiceFormat always set to FALSE, or can be NULL; + * @param isChoiceFormat always set to false, or can be NULL; * display names are static strings; * since ICU 4.4, ChoiceFormat patterns are no longer supported * @param len fill-in parameter to receive length of result @@ -169,7 +191,7 @@ ucurr_unregister(UCurrRegistryKey key, UErrorCode* status); * returned. * @stable ICU 2.6 */ -U_STABLE const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ucurr_getName(const UChar* currency, const char* locale, UCurrNameStyle nameStyle, @@ -183,7 +205,7 @@ ucurr_getName(const UChar* currency, * currency object in the en_US locale is "US dollar" or "US dollars". * @param currency null-terminated 3-letter ISO 4217 code * @param locale locale in which to display currency - * @param isChoiceFormat always set to FALSE, or can be NULL; + * @param isChoiceFormat always set to false, or can be NULL; * display names are static strings; * since ICU 4.4, ChoiceFormat patterns are no longer supported * @param pluralCount plural count @@ -194,7 +216,7 @@ ucurr_getName(const UChar* currency, * returned. * @stable ICU 4.2 */ -U_STABLE const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ucurr_getPluralName(const UChar* currency, const char* locale, UBool* isChoiceFormat, @@ -219,7 +241,7 @@ ucurr_getPluralName(const UChar* currency, * displayed, or 0 if there is an error * @stable ICU 3.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucurr_getDefaultFractionDigits(const UChar* currency, UErrorCode* ec); @@ -240,7 +262,7 @@ ucurr_getDefaultFractionDigits(const UChar* currency, * displayed, or 0 if there is an error * @stable ICU 54 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucurr_getDefaultFractionDigitsForUsage(const UChar* currency, const UCurrencyUsage usage, UErrorCode* ec); @@ -255,7 +277,7 @@ ucurr_getDefaultFractionDigitsForUsage(const UChar* currency, * or 0.0 if there is an error * @stable ICU 3.0 */ -U_STABLE double U_EXPORT2 +U_CAPI double U_EXPORT2 ucurr_getRoundingIncrement(const UChar* currency, UErrorCode* ec); @@ -269,7 +291,7 @@ ucurr_getRoundingIncrement(const UChar* currency, * or 0.0 if there is an error * @stable ICU 54 */ -U_STABLE double U_EXPORT2 +U_CAPI double U_EXPORT2 ucurr_getRoundingIncrementForUsage(const UChar* currency, const UCurrencyUsage usage, UErrorCode* ec); @@ -326,7 +348,7 @@ typedef enum UCurrCurrencyType { * @param pErrorCode Error code * @stable ICU 3.2 */ -U_STABLE UEnumeration * U_EXPORT2 +U_CAPI UEnumeration * U_EXPORT2 ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode); /** @@ -351,11 +373,11 @@ ucurr_openISOCurrencies(uint32_t currType, UErrorCode *pErrorCode); * @param errorCode * ICU error code * - * @return TRUE if the given ISO 4217 3-letter code is supported on the specified date range. + * @return true if the given ISO 4217 3-letter code is supported on the specified date range. * * @stable ICU 4.8 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ucurr_isAvailable(const UChar* isoCode, UDate from, UDate to, @@ -375,7 +397,7 @@ ucurr_isAvailable(const UChar* isoCode, * values are invalid. * @stable ICU 4.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucurr_countCurrencies(const char* locale, UDate date, UErrorCode* ec); @@ -399,7 +421,7 @@ ucurr_countCurrencies(const char* locale, * invalid. * @stable ICU 4.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucurr_forLocaleAndDate(const char* locale, UDate date, int32_t index, @@ -423,7 +445,7 @@ ucurr_forLocaleAndDate(const char* locale, * @return a string enumeration over keyword values for the given key and the locale. * @stable ICU 4.2 */ -U_STABLE UEnumeration* U_EXPORT2 +U_CAPI UEnumeration* U_EXPORT2 ucurr_getKeywordValuesForLocale(const char* key, const char* locale, UBool commonlyUsed, @@ -438,7 +460,7 @@ ucurr_getKeywordValuesForLocale(const char* key, * @return The ISO 4217 numeric code of the currency * @stable ICU 49 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucurr_getNumericCode(const UChar* currency); #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/common/unicode/udata.h b/deps/icu-small/source/common/unicode/udata.h index 8236877b443d3d..88c0dded118d00 100644 --- a/deps/icu-small/source/common/unicode/udata.h +++ b/deps/icu-small/source/common/unicode/udata.h @@ -20,7 +20,10 @@ #define __UDATA_H__ #include "unicode/utypes.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API U_CDECL_BEGIN @@ -166,8 +169,8 @@ typedef struct UDataMemory UDataMemory; * @param pInfo A pointer to the UDataInfo structure * of data that has been loaded and will be returned * by udata_openChoice() if this function - * returns TRUE. - * @return TRUE if the current data memory is acceptable + * returns true. + * @return true if the current data memory is acceptable * @stable ICU 2.0 */ typedef UBool U_CALLCONV @@ -197,7 +200,7 @@ UDataMemoryIsAcceptable(void *context, * @see udata_openChoice * @stable ICU 2.0 */ -U_STABLE UDataMemory * U_EXPORT2 +U_CAPI UDataMemory * U_EXPORT2 udata_open(const char *path, const char *type, const char *name, UErrorCode *pErrorCode); @@ -239,7 +242,7 @@ udata_open(const char *path, const char *type, const char *name, * This may be NULL or empty. * @param name A string that specifies the name of the data. * @param isAcceptable This function is called to verify that loaded data - * is useful for the client code. If it returns FALSE + * is useful for the client code. If it returns false * for all data items, then udata_openChoice() * will return with an error. * @param context Arbitrary parameter to be passed into isAcceptable. @@ -249,7 +252,7 @@ udata_open(const char *path, const char *type, const char *name, * to get a pointer to the actual data. * @stable ICU 2.0 */ -U_STABLE UDataMemory * U_EXPORT2 +U_CAPI UDataMemory * U_EXPORT2 udata_openChoice(const char *path, const char *type, const char *name, UDataMemoryIsAcceptable *isAcceptable, void *context, UErrorCode *pErrorCode); @@ -261,7 +264,7 @@ udata_openChoice(const char *path, const char *type, const char *name, * @param pData The pointer to data memory object * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 udata_close(UDataMemory *pData); /** @@ -273,7 +276,7 @@ udata_close(UDataMemory *pData); * @param pData The pointer to data memory object * @stable ICU 2.0 */ -U_STABLE const void * U_EXPORT2 +U_CAPI const void * U_EXPORT2 udata_getMemory(UDataMemory *pData); /** @@ -294,7 +297,7 @@ udata_getMemory(UDataMemory *pData); * adjusted and only part of the structure will be filled. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 udata_getInfo(UDataMemory *pData, UDataInfo *pInfo); /** @@ -303,7 +306,7 @@ udata_getInfo(UDataMemory *pData, UDataInfo *pInfo); * area in memory. * * ICU data must be at least 8-aligned, and should be 16-aligned. - * See http://userguide.icu-project.org/icudata + * See https://unicode-org.github.io/icu/userguide/icudata * * The format of this data is that of the icu common data file, as is * generated by the pkgdata tool with mode=common or mode=dll. @@ -340,7 +343,7 @@ udata_getInfo(UDataMemory *pData, UDataInfo *pInfo); * @param err outgoing error status U_USING_DEFAULT_WARNING, U_UNSUPPORTED_ERROR * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 udata_setCommonData(const void *data, UErrorCode *err); @@ -350,7 +353,7 @@ udata_setCommonData(const void *data, UErrorCode *err); * pointer. * * ICU data must be at least 8-aligned, and should be 16-aligned. - * See http://userguide.icu-project.org/icudata + * See https://unicode-org.github.io/icu/userguide/icudata * * The format of this data is that of the icu common data file, like 'icudt26l.dat' * or the corresponding shared library (DLL) file. @@ -371,7 +374,7 @@ udata_setCommonData(const void *data, UErrorCode *err); * @see udata_setCommonData * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 udata_setAppData(const char *packageName, const void *data, UErrorCode *err); /** @@ -410,7 +413,7 @@ typedef enum UDataFileAccess { * @see UDataFileAccess * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 udata_setFileAccess(UDataFileAccess access, UErrorCode *status); U_CDECL_END diff --git a/deps/icu-small/source/common/unicode/udisplaycontext.h b/deps/icu-small/source/common/unicode/udisplaycontext.h index 398481c6812247..6e1421798054f6 100644 --- a/deps/icu-small/source/common/unicode/udisplaycontext.h +++ b/deps/icu-small/source/common/unicode/udisplaycontext.h @@ -156,7 +156,8 @@ enum UDisplayContext { UDISPCTX_SUBSTITUTE = (UDISPCTX_TYPE_SUBSTITUTE_HANDLING<<8) + 0, /** * A possible setting for SUBSTITUTE_HANDLING: - * Returns a null value when no data is available. + * Returns a null value with error code set to U_ILLEGAL_ARGUMENT_ERROR when no + * data is available. * @stable ICU 58 */ UDISPCTX_NO_SUBSTITUTE = (UDISPCTX_TYPE_SUBSTITUTE_HANDLING<<8) + 1 diff --git a/deps/icu-small/source/common/unicode/uenum.h b/deps/icu-small/source/common/unicode/uenum.h index eb8ecdf88b6ec5..f1c506934bec87 100644 --- a/deps/icu-small/source/common/unicode/uenum.h +++ b/deps/icu-small/source/common/unicode/uenum.h @@ -20,13 +20,14 @@ #define __UENUM_H #include "unicode/utypes.h" -#include "unicode/localpointer.h" #if U_SHOW_CPLUSPLUS_API +#include "unicode/localpointer.h" + U_NAMESPACE_BEGIN class StringEnumeration; U_NAMESPACE_END -#endif +#endif // U_SHOW_CPLUSPLUS_API /** * \file @@ -49,7 +50,7 @@ typedef struct UEnumeration UEnumeration; * @param en UEnumeration structure pointer * @stable ICU 2.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uenum_close(UEnumeration* en); #if U_SHOW_CPLUSPLUS_API @@ -85,7 +86,7 @@ U_NAMESPACE_END * @return number of elements in the iterator * @stable ICU 2.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uenum_count(UEnumeration* en, UErrorCode* status); /** @@ -109,7 +110,7 @@ uenum_count(UEnumeration* en, UErrorCode* status); * traversed, returns NULL. * @stable ICU 2.2 */ -U_STABLE const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 uenum_unext(UEnumeration* en, int32_t* resultLength, UErrorCode* status); @@ -142,7 +143,7 @@ uenum_unext(UEnumeration* en, * traversed, returns NULL. * @stable ICU 2.2 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uenum_next(UEnumeration* en, int32_t* resultLength, UErrorCode* status); @@ -156,7 +157,7 @@ uenum_next(UEnumeration* en, * the iterator is out of sync with its service. * @stable ICU 2.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uenum_reset(UEnumeration* en, UErrorCode* status); #if U_SHOW_CPLUSPLUS_API @@ -170,7 +171,7 @@ uenum_reset(UEnumeration* en, UErrorCode* status); * @return a UEnumeration wrapping the adopted StringEnumeration. * @stable ICU 4.2 */ -U_STABLE UEnumeration* U_EXPORT2 +U_CAPI UEnumeration* U_EXPORT2 uenum_openFromStringEnumeration(icu::StringEnumeration* adopted, UErrorCode* ec); #endif @@ -186,7 +187,7 @@ uenum_openFromStringEnumeration(icu::StringEnumeration* adopted, UErrorCode* ec) * @see uenum_close * @stable ICU 50 */ -U_STABLE UEnumeration* U_EXPORT2 +U_CAPI UEnumeration* U_EXPORT2 uenum_openUCharStringsEnumeration(const UChar* const strings[], int32_t count, UErrorCode* ec); @@ -201,7 +202,7 @@ uenum_openUCharStringsEnumeration(const UChar* const strings[], int32_t count, * @see uenum_close * @stable ICU 50 */ -U_STABLE UEnumeration* U_EXPORT2 +U_CAPI UEnumeration* U_EXPORT2 uenum_openCharStringsEnumeration(const char* const strings[], int32_t count, UErrorCode* ec); diff --git a/deps/icu-small/source/common/unicode/uidna.h b/deps/icu-small/source/common/unicode/uidna.h index cb79ba8545008e..1f75562555c3c2 100644 --- a/deps/icu-small/source/common/unicode/uidna.h +++ b/deps/icu-small/source/common/unicode/uidna.h @@ -23,9 +23,13 @@ #if !UCONFIG_NO_IDNA -#include "unicode/localpointer.h" +#include #include "unicode/parseerr.h" +#if U_SHOW_CPLUSPLUS_API +#include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API + /** * \file * \brief C API: Internationalizing Domain Names in Applications (IDNA) @@ -138,7 +142,7 @@ typedef struct UIDNA UIDNA; /**< C typedef for struct UIDNA. @stable ICU 4.6 */ * @return the UTS #46 UIDNA instance, if successful * @stable ICU 4.6 */ -U_STABLE UIDNA * U_EXPORT2 +U_CAPI UIDNA * U_EXPORT2 uidna_openUTS46(uint32_t options, UErrorCode *pErrorCode); /** @@ -146,7 +150,7 @@ uidna_openUTS46(uint32_t options, UErrorCode *pErrorCode); * @param idna UIDNA instance to be closed * @stable ICU 4.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uidna_close(UIDNA *idna); #if U_SHOW_CPLUSPLUS_API @@ -182,7 +186,7 @@ typedef struct UIDNAInfo { /** sizeof(UIDNAInfo) @stable ICU 4.6 */ int16_t size; /** - * Set to TRUE if transitional and nontransitional processing produce different results. + * Set to true if transitional and nontransitional processing produce different results. * For details see C++ IDNAInfo::isTransitionalDifferent(). * @stable ICU 4.6 */ @@ -204,7 +208,7 @@ typedef struct UIDNAInfo { */ #define UIDNA_INFO_INITIALIZER { \ (int16_t)sizeof(UIDNAInfo), \ - FALSE, FALSE, \ + false, false, \ 0, 0, 0 } /** @@ -230,7 +234,7 @@ typedef struct UIDNAInfo { * @return destination string length * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uidna_labelToASCII(const UIDNA *idna, const UChar *label, int32_t length, UChar *dest, int32_t capacity, @@ -257,7 +261,7 @@ uidna_labelToASCII(const UIDNA *idna, * @return destination string length * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uidna_labelToUnicode(const UIDNA *idna, const UChar *label, int32_t length, UChar *dest, int32_t capacity, @@ -286,7 +290,7 @@ uidna_labelToUnicode(const UIDNA *idna, * @return destination string length * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uidna_nameToASCII(const UIDNA *idna, const UChar *name, int32_t length, UChar *dest, int32_t capacity, @@ -313,7 +317,7 @@ uidna_nameToASCII(const UIDNA *idna, * @return destination string length * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uidna_nameToUnicode(const UIDNA *idna, const UChar *name, int32_t length, UChar *dest, int32_t capacity, @@ -338,7 +342,7 @@ uidna_nameToUnicode(const UIDNA *idna, * @return destination string length * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uidna_labelToASCII_UTF8(const UIDNA *idna, const char *label, int32_t length, char *dest, int32_t capacity, @@ -361,7 +365,7 @@ uidna_labelToASCII_UTF8(const UIDNA *idna, * @return destination string length * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uidna_labelToUnicodeUTF8(const UIDNA *idna, const char *label, int32_t length, char *dest, int32_t capacity, @@ -384,7 +388,7 @@ uidna_labelToUnicodeUTF8(const UIDNA *idna, * @return destination string length * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uidna_nameToASCII_UTF8(const UIDNA *idna, const char *name, int32_t length, char *dest, int32_t capacity, @@ -407,7 +411,7 @@ uidna_nameToASCII_UTF8(const UIDNA *idna, * @return destination string length * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uidna_nameToUnicodeUTF8(const UIDNA *idna, const char *name, int32_t length, char *dest, int32_t capacity, diff --git a/deps/icu-small/source/common/unicode/uiter.h b/deps/icu-small/source/common/unicode/uiter.h index 3b8537204cecfa..7dbe1266668f24 100644 --- a/deps/icu-small/source/common/unicode/uiter.h +++ b/deps/icu-small/source/common/unicode/uiter.h @@ -492,7 +492,7 @@ struct UCharIterator { * @see UnicodeString::char32At() * @stable ICU 2.1 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 uiter_current32(UCharIterator *iter); /** @@ -509,7 +509,7 @@ uiter_current32(UCharIterator *iter); * @see U16_NEXT * @stable ICU 2.1 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 uiter_next32(UCharIterator *iter); /** @@ -526,7 +526,7 @@ uiter_next32(UCharIterator *iter); * @see U16_PREV * @stable ICU 2.1 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 uiter_previous32(UCharIterator *iter); /** @@ -547,7 +547,7 @@ uiter_previous32(UCharIterator *iter); * @see UITER_NO_STATE * @stable ICU 2.6 */ -U_STABLE uint32_t U_EXPORT2 +U_CAPI uint32_t U_EXPORT2 uiter_getState(const UCharIterator *iter); /** @@ -565,7 +565,7 @@ uiter_getState(const UCharIterator *iter); * @see UCharIteratorSetState * @stable ICU 2.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uiter_setState(UCharIterator *iter, uint32_t state, UErrorCode *pErrorCode); /** @@ -590,7 +590,7 @@ uiter_setState(UCharIterator *iter, uint32_t state, UErrorCode *pErrorCode); * @see UCharIterator * @stable ICU 2.1 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uiter_setString(UCharIterator *iter, const UChar *s, int32_t length); /** @@ -613,7 +613,7 @@ uiter_setString(UCharIterator *iter, const UChar *s, int32_t length); * @see uiter_setString * @stable ICU 2.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uiter_setUTF16BE(UCharIterator *iter, const char *s, int32_t length); /** @@ -649,7 +649,7 @@ uiter_setUTF16BE(UCharIterator *iter, const char *s, int32_t length); * @see UCharIterator * @stable ICU 2.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uiter_setUTF8(UCharIterator *iter, const char *s, int32_t length); #if U_SHOW_CPLUSPLUS_API @@ -674,7 +674,7 @@ uiter_setUTF8(UCharIterator *iter, const char *s, int32_t length); * @see UCharIterator * @stable ICU 2.1 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uiter_setCharacterIterator(UCharIterator *iter, icu::CharacterIterator *charIter); /** @@ -699,7 +699,7 @@ uiter_setCharacterIterator(UCharIterator *iter, icu::CharacterIterator *charIter * @see UCharIterator * @stable ICU 2.1 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uiter_setReplaceable(UCharIterator *iter, const icu::Replaceable *rep); #endif diff --git a/deps/icu-small/source/common/unicode/uldnames.h b/deps/icu-small/source/common/unicode/uldnames.h index 3a3c0a06573c36..10f0e91e5526e4 100644 --- a/deps/icu-small/source/common/unicode/uldnames.h +++ b/deps/icu-small/source/common/unicode/uldnames.h @@ -16,10 +16,13 @@ */ #include "unicode/utypes.h" -#include "unicode/localpointer.h" #include "unicode/uscript.h" #include "unicode/udisplaycontext.h" +#if U_SHOW_CPLUSPLUS_API +#include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API + /** * Enum used in LocaleDisplayNames::createInstance. * @stable ICU 4.4 @@ -65,7 +68,7 @@ typedef struct ULocaleDisplayNames ULocaleDisplayNames; * @param pErrorCode the status code * @stable ICU 4.4 */ -U_STABLE ULocaleDisplayNames * U_EXPORT2 +U_CAPI ULocaleDisplayNames * U_EXPORT2 uldn_open(const char * locale, UDialectHandling dialectHandling, UErrorCode *pErrorCode); @@ -75,7 +78,7 @@ uldn_open(const char * locale, * @param ldn the ULocaleDisplayNames instance to be closed * @stable ICU 4.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uldn_close(ULocaleDisplayNames *ldn); #if U_SHOW_CPLUSPLUS_API @@ -106,7 +109,7 @@ U_NAMESPACE_END * @return the display locale * @stable ICU 4.4 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 uldn_getLocale(const ULocaleDisplayNames *ldn); /** @@ -115,7 +118,7 @@ uldn_getLocale(const ULocaleDisplayNames *ldn); * @return the dialect handling enum * @stable ICU 4.4 */ -U_STABLE UDialectHandling U_EXPORT2 +U_CAPI UDialectHandling U_EXPORT2 uldn_getDialectHandling(const ULocaleDisplayNames *ldn); /* names for entire locales */ @@ -131,7 +134,7 @@ uldn_getDialectHandling(const ULocaleDisplayNames *ldn); * greater than maxResultSize, the returned name will be truncated. * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uldn_localeDisplayName(const ULocaleDisplayNames *ldn, const char *locale, UChar *result, @@ -151,7 +154,7 @@ uldn_localeDisplayName(const ULocaleDisplayNames *ldn, * greater than maxResultSize, the returned name will be truncated. * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uldn_languageDisplayName(const ULocaleDisplayNames *ldn, const char *lang, UChar *result, @@ -169,7 +172,7 @@ uldn_languageDisplayName(const ULocaleDisplayNames *ldn, * greater than maxResultSize, the returned name will be truncated. * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uldn_scriptDisplayName(const ULocaleDisplayNames *ldn, const char *script, UChar *result, @@ -187,7 +190,7 @@ uldn_scriptDisplayName(const ULocaleDisplayNames *ldn, * greater than maxResultSize, the returned name will be truncated. * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uldn_scriptCodeDisplayName(const ULocaleDisplayNames *ldn, UScriptCode scriptCode, UChar *result, @@ -205,7 +208,7 @@ uldn_scriptCodeDisplayName(const ULocaleDisplayNames *ldn, * greater than maxResultSize, the returned name will be truncated. * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uldn_regionDisplayName(const ULocaleDisplayNames *ldn, const char *region, UChar *result, @@ -223,7 +226,7 @@ uldn_regionDisplayName(const ULocaleDisplayNames *ldn, * greater than maxResultSize, the returned name will be truncated. * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uldn_variantDisplayName(const ULocaleDisplayNames *ldn, const char *variant, UChar *result, @@ -241,7 +244,7 @@ uldn_variantDisplayName(const ULocaleDisplayNames *ldn, * greater than maxResultSize, the returned name will be truncated. * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uldn_keyDisplayName(const ULocaleDisplayNames *ldn, const char *key, UChar *result, @@ -260,7 +263,7 @@ uldn_keyDisplayName(const ULocaleDisplayNames *ldn, * greater than maxResultSize, the returned name will be truncated. * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uldn_keyValueDisplayName(const ULocaleDisplayNames *ldn, const char *key, const char *value, @@ -282,7 +285,7 @@ uldn_keyValueDisplayName(const ULocaleDisplayNames *ldn, * @return a ULocaleDisplayNames instance * @stable ICU 51 */ -U_STABLE ULocaleDisplayNames * U_EXPORT2 +U_CAPI ULocaleDisplayNames * U_EXPORT2 uldn_openForContext(const char * locale, UDisplayContext *contexts, int32_t length, UErrorCode *pErrorCode); @@ -296,7 +299,7 @@ uldn_openForContext(const char * locale, UDisplayContext *contexts, * @return the UDisplayContextValue for the specified type. * @stable ICU 51 */ -U_STABLE UDisplayContext U_EXPORT2 +U_CAPI UDisplayContext U_EXPORT2 uldn_getContext(const ULocaleDisplayNames *ldn, UDisplayContextType type, UErrorCode *pErrorCode); diff --git a/deps/icu-small/source/common/unicode/uloc.h b/deps/icu-small/source/common/unicode/uloc.h index a10ab526cec141..56fb4c9b3769e0 100644 --- a/deps/icu-small/source/common/unicode/uloc.h +++ b/deps/icu-small/source/common/unicode/uloc.h @@ -371,7 +371,7 @@ typedef enum { * @system * @stable ICU 2.0 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uloc_getDefault(void); /** @@ -391,7 +391,7 @@ uloc_getDefault(void); * @system * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uloc_setDefault(const char* localeID, UErrorCode* status); #endif /* U_HIDE_SYSTEM_API */ @@ -408,7 +408,7 @@ uloc_setDefault(const char* localeID, * than languageCapacity, the returned language code will be truncated. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getLanguage(const char* localeID, char* language, int32_t languageCapacity, @@ -426,7 +426,7 @@ uloc_getLanguage(const char* localeID, * than scriptCapacity, the returned language code will be truncated. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getScript(const char* localeID, char* script, int32_t scriptCapacity, @@ -444,7 +444,7 @@ uloc_getScript(const char* localeID, * than countryCapacity, the returned country code will be truncated. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getCountry(const char* localeID, char* country, int32_t countryCapacity, @@ -462,7 +462,7 @@ uloc_getCountry(const char* localeID, * than variantCapacity, the returned variant code will be truncated. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getVariant(const char* localeID, char* variant, int32_t variantCapacity, @@ -485,7 +485,7 @@ uloc_getVariant(const char* localeID, * than nameCapacity, the returned full name will be truncated. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getName(const char* localeID, char* name, int32_t nameCapacity, @@ -508,7 +508,7 @@ uloc_getName(const char* localeID, * than nameCapacity, the returned full name will be truncated. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_canonicalize(const char* localeID, char* name, int32_t nameCapacity, @@ -521,7 +521,7 @@ uloc_canonicalize(const char* localeID, * @return language the ISO language code for localeID * @stable ICU 2.0 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uloc_getISO3Language(const char* localeID); @@ -532,7 +532,7 @@ uloc_getISO3Language(const char* localeID); * @return country the ISO country code for localeID * @stable ICU 2.0 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uloc_getISO3Country(const char* localeID); /** @@ -546,26 +546,31 @@ uloc_getISO3Country(const char* localeID); * @return country the Win32 LCID for localeID * @stable ICU 2.0 */ -U_STABLE uint32_t U_EXPORT2 +U_CAPI uint32_t U_EXPORT2 uloc_getLCID(const char* localeID); /** * Gets the language name suitable for display for the specified locale. * * @param locale the locale to get the ISO language code with - * @param displayLocale Specifies the locale to be used to display the name. In other words, - * if the locale's language code is "en", passing Locale::getFrench() for - * inLocale would result in "Anglais", while passing Locale::getGerman() - * for inLocale would result in "Englisch". + * @param displayLocale Specifies the locale to be used to display the name. In + * other words, if the locale's language code is "en", passing + * Locale::getFrench() for inLocale would result in "Anglais", + * while passing Locale::getGerman() for inLocale would result + * in "Englisch". * @param language the displayable language code for localeID * @param languageCapacity the size of the language buffer to store the - * displayable language code with - * @param status error information if retrieving the displayable language code failed - * @return the actual buffer size needed for the displayable language code. If it's greater - * than languageCapacity, the returned language code will be truncated. + * displayable language code with. + * @param status error information if retrieving the displayable language code + * failed. U_USING_DEFAULT_WARNING indicates that no data was + * found from the locale resources and a case canonicalized + * language code is placed into language as fallback. + * @return the actual buffer size needed for the displayable language code. If + * it's greater than languageCapacity, the returned language + * code will be truncated. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getDisplayLanguage(const char* locale, const char* displayLocale, UChar* language, @@ -575,20 +580,26 @@ uloc_getDisplayLanguage(const char* locale, /** * Gets the script name suitable for display for the specified locale. * - * @param locale the locale to get the displayable script code with. NULL may be used to specify the default. - * @param displayLocale Specifies the locale to be used to display the name. In other words, - * if the locale's language code is "en", passing Locale::getFrench() for - * inLocale would result in "", while passing Locale::getGerman() - * for inLocale would result in "". NULL may be used to specify the default. - * @param script the displayable script for the localeID - * @param scriptCapacity the size of the script buffer to store the - * displayable script code with - * @param status error information if retrieving the displayable script code failed - * @return the actual buffer size needed for the displayable script code. If it's greater - * than scriptCapacity, the returned displayable script code will be truncated. + * @param locale the locale to get the displayable script code with. NULL may be + * used to specify the default. + * @param displayLocale Specifies the locale to be used to display the name. In + * other words, if the locale's language code is "en", passing + * Locale::getFrench() for inLocale would result in "", while + * passing Locale::getGerman() for inLocale would result in "". + * NULL may be used to specify the default. + * @param script the displayable script for the localeID. + * @param scriptCapacity the size of the script buffer to store the displayable + * script code with. + * @param status error information if retrieving the displayable script code + * failed. U_USING_DEFAULT_WARNING indicates that no data was + * found from the locale resources and a case canonicalized + * script code is placed into script as fallback. + * @return the actual buffer size needed for the displayable script code. If + * it's greater than scriptCapacity, the returned displayable + * script code will be truncated. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getDisplayScript(const char* locale, const char* displayLocale, UChar* script, @@ -597,23 +608,30 @@ uloc_getDisplayScript(const char* locale, /** * Gets the country name suitable for display for the specified locale. - * Warning: this is for the region part of a valid locale ID; it cannot just be the region code (like "FR"). - * To get the display name for a region alone, or for other options, use ULocaleDisplayNames instead. - * - * @param locale the locale to get the displayable country code with. NULL may be used to specify the default. - * @param displayLocale Specifies the locale to be used to display the name. In other words, - * if the locale's language code is "en", passing Locale::getFrench() for - * inLocale would result in "Anglais", while passing Locale::getGerman() - * for inLocale would result in "Englisch". NULL may be used to specify the default. - * @param country the displayable country code for localeID + * Warning: this is for the region part of a valid locale ID; it cannot just be + * the region code (like "FR"). To get the display name for a region alone, or + * for other options, use ULocaleDisplayNames instead. + * + * @param locale the locale to get the displayable country code with. NULL may + * be used to specify the default. + * @param displayLocale Specifies the locale to be used to display the name. In + * other words, if the locale's language code is "en", passing + * Locale::getFrench() for inLocale would result in "Anglais", + * while passing Locale::getGerman() for inLocale would result + * in "Englisch". NULL may be used to specify the default. + * @param country the displayable country code for localeID. * @param countryCapacity the size of the country buffer to store the - * displayable country code with - * @param status error information if retrieving the displayable country code failed - * @return the actual buffer size needed for the displayable country code. If it's greater - * than countryCapacity, the returned displayable country code will be truncated. + * displayable country code with. + * @param status error information if retrieving the displayable country code + * failed. U_USING_DEFAULT_WARNING indicates that no data was + * found from the locale resources and a case canonicalized + * country code is placed into country as fallback. + * @return the actual buffer size needed for the displayable country code. If + * it's greater than countryCapacity, the returned displayable + * country code will be truncated. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getDisplayCountry(const char* locale, const char* displayLocale, UChar* country, @@ -624,20 +642,26 @@ uloc_getDisplayCountry(const char* locale, /** * Gets the variant name suitable for display for the specified locale. * - * @param locale the locale to get the displayable variant code with. NULL may be used to specify the default. - * @param displayLocale Specifies the locale to be used to display the name. In other words, - * if the locale's language code is "en", passing Locale::getFrench() for - * inLocale would result in "Anglais", while passing Locale::getGerman() - * for inLocale would result in "Englisch". NULL may be used to specify the default. - * @param variant the displayable variant code for localeID + * @param locale the locale to get the displayable variant code with. NULL may + * be used to specify the default. + * @param displayLocale Specifies the locale to be used to display the name. In + * other words, if the locale's language code is "en", passing + * Locale::getFrench() for inLocale would result in "Anglais", + * while passing Locale::getGerman() for inLocale would result + * in "Englisch". NULL may be used to specify the default. + * @param variant the displayable variant code for localeID. * @param variantCapacity the size of the variant buffer to store the - * displayable variant code with - * @param status error information if retrieving the displayable variant code failed - * @return the actual buffer size needed for the displayable variant code. If it's greater - * than variantCapacity, the returned displayable variant code will be truncated. + * displayable variant code with. + * @param status error information if retrieving the displayable variant code + * failed. U_USING_DEFAULT_WARNING indicates that no data was + * found from the locale resources and a case canonicalized + * variant code is placed into variant as fallback. + * @return the actual buffer size needed for the displayable variant code. If + * it's greater than variantCapacity, the returned displayable + * variant code will be truncated. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getDisplayVariant(const char* locale, const char* displayLocale, UChar* variant, @@ -645,8 +669,8 @@ uloc_getDisplayVariant(const char* locale, UErrorCode* status); /** - * Gets the keyword name suitable for display for the specified locale. - * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display + * Gets the keyword name suitable for display for the specified locale. E.g: + * for the locale string de_DE\@collation=PHONEBOOK, this API gets the display * string for the keyword collation. * Usage: * @@ -680,11 +704,13 @@ uloc_getDisplayVariant(const char* locale, * result without writing any of the result string (pre-flighting). * @param status error information if retrieving the displayable string failed. * Should not be NULL and should not indicate failure on entry. + * U_USING_DEFAULT_WARNING indicates that no data was found from the locale + * resources and the keyword is placed into dest as fallback. * @return the actual buffer size needed for the displayable variant code. * @see #uloc_openKeywords * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getDisplayKeyword(const char* keyword, const char* displayLocale, UChar* dest, @@ -707,10 +733,12 @@ uloc_getDisplayKeyword(const char* keyword, * result without writing any of the result string (pre-flighting). * @param status error information if retrieving the displayable string failed. * Should not be NULL and must not indicate failure on entry. + * U_USING_DEFAULT_WARNING indicates that no data was found from the locale + * resources and the value of the keyword is placed into dest as fallback. * @return the actual buffer size needed for the displayable variant code. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getDisplayKeywordValue( const char* locale, const char* keyword, const char* displayLocale, @@ -733,7 +761,7 @@ uloc_getDisplayKeywordValue( const char* locale, * than maxResultSize, the returned displayable name will be truncated. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getDisplayName(const char* localeID, const char* inLocaleID, UChar* result, @@ -757,7 +785,7 @@ uloc_getDisplayName(const char* localeID, * @return a specified locale name of all available locales * @stable ICU 2.0 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uloc_getAvailable(int32_t n); /** @@ -766,21 +794,19 @@ uloc_getAvailable(int32_t n); * @return the size of the locale list * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 uloc_countAvailable(void); - -#ifndef U_HIDE_DRAFT_API +U_CAPI int32_t U_EXPORT2 uloc_countAvailable(void); /** * Types for uloc_getAvailableByType and uloc_countAvailableByType. * - * @draft ICU 65 + * @stable ICU 65 */ typedef enum ULocAvailableType { /** * Locales that return data when passed to ICU APIs, * but not including legacy or alias locales. * - * @draft ICU 65 + * @stable ICU 65 */ ULOC_AVAILABLE_DEFAULT, @@ -798,7 +824,7 @@ typedef enum ULocAvailableType { * ULOC_AVAILABLE_DEFAULT. To get both sets at the same time, use * ULOC_AVAILABLE_WITH_LEGACY_ALIASES. * - * @draft ICU 65 + * @stable ICU 65 */ ULOC_AVAILABLE_ONLY_LEGACY_ALIASES, @@ -806,7 +832,7 @@ typedef enum ULocAvailableType { * The union of the locales in ULOC_AVAILABLE_DEFAULT and * ULOC_AVAILABLE_ONLY_LEGACY_ALIAS. * - * @draft ICU 65 + * @stable ICU 65 */ ULOC_AVAILABLE_WITH_LEGACY_ALIASES, @@ -827,13 +853,11 @@ typedef enum ULocAvailableType { * @param type Type choice from ULocAvailableType. * @param status Set if an error occurred. * @return a UEnumeration owned by the caller, or nullptr on failure. - * @draft ICU 65 + * @stable ICU 65 */ -U_DRAFT UEnumeration* U_EXPORT2 +U_CAPI UEnumeration* U_EXPORT2 uloc_openAvailableByType(ULocAvailableType type, UErrorCode* status); -#endif // U_HIDE_DRAFT_API - /** * * Gets a list of all available 2-letter language codes defined in ISO 639, @@ -845,7 +869,7 @@ uloc_openAvailableByType(ULocAvailableType type, UErrorCode* status); * @return a list of all available language codes * @stable ICU 2.0 */ -U_STABLE const char* const* U_EXPORT2 +U_CAPI const char* const* U_EXPORT2 uloc_getISOLanguages(void); /** @@ -857,7 +881,7 @@ uloc_getISOLanguages(void); * @return a list of all available country codes * @stable ICU 2.0 */ -U_STABLE const char* const* U_EXPORT2 +U_CAPI const char* const* U_EXPORT2 uloc_getISOCountries(void); /** @@ -873,7 +897,7 @@ uloc_getISOCountries(void); * @return The length of the parent locale ID. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getParent(const char* localeID, char* parent, int32_t parentCapacity, @@ -904,7 +928,7 @@ uloc_getParent(const char* localeID, * than nameCapacity, the returned full name will be truncated. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getBaseName(const char* localeID, char* name, int32_t nameCapacity, @@ -919,7 +943,7 @@ uloc_getBaseName(const char* localeID, * @return enumeration of keywords or NULL if there are no keywords. * @stable ICU 2.8 */ -U_STABLE UEnumeration* U_EXPORT2 +U_CAPI UEnumeration* U_EXPORT2 uloc_openKeywords(const char* localeID, UErrorCode* status); @@ -936,7 +960,7 @@ uloc_openKeywords(const char* localeID, * @return the length of keyword value * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getKeywordValue(const char* localeID, const char* keywordName, char* buffer, int32_t bufferCapacity, @@ -973,7 +997,7 @@ uloc_getKeywordValue(const char* localeID, * @see uloc_getKeywordValue * @stable ICU 3.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_setKeywordValue(const char* keywordName, const char* keywordValue, char* buffer, int32_t bufferCapacity, @@ -982,18 +1006,18 @@ uloc_setKeywordValue(const char* keywordName, /** * Returns whether the locale's script is written right-to-left. * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags(). - * If no likely script is known, then FALSE is returned. + * If no likely script is known, then false is returned. * * A script is right-to-left according to the CLDR script metadata * which corresponds to whether the script's letters have Bidi_Class=R or AL. * - * Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl". + * Returns true for "ar" and "en-Hebr", false for "zh" and "fa-Cyrl". * * @param locale input locale ID - * @return TRUE if the locale's script is written right-to-left + * @return true if the locale's script is written right-to-left * @stable ICU 54 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uloc_isRightToLeft(const char *locale); /** @@ -1017,7 +1041,7 @@ typedef enum { * @return an enum indicating the layout orientation for characters. * @stable ICU 4.0 */ -U_STABLE ULayoutType U_EXPORT2 +U_CAPI ULayoutType U_EXPORT2 uloc_getCharacterOrientation(const char* localeId, UErrorCode *status); @@ -1029,7 +1053,7 @@ uloc_getCharacterOrientation(const char* localeId, * @return an enum indicating the layout orientation for lines. * @stable ICU 4.0 */ -U_STABLE ULayoutType U_EXPORT2 +U_CAPI ULayoutType U_EXPORT2 uloc_getLineOrientation(const char* localeId, UErrorCode *status); @@ -1076,7 +1100,7 @@ typedef enum { * @return length needed for the locale. * @stable ICU 3.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_acceptLanguageFromHTTP(char *result, int32_t resultAvailable, UAcceptResult *outResult, const char *httpAcceptLanguage, @@ -1101,7 +1125,7 @@ uloc_acceptLanguageFromHTTP(char *result, int32_t resultAvailable, * @return length needed for the locale. * @stable ICU 3.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_acceptLanguage(char *result, int32_t resultAvailable, UAcceptResult *outResult, const char **acceptList, int32_t acceptListCount, @@ -1121,7 +1145,7 @@ uloc_acceptLanguage(char *result, int32_t resultAvailable, * @return actual the actual size of the locale ID, not including NUL-termination * @stable ICU 3.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_getLocaleForLCID(uint32_t hostID, char *locale, int32_t localeCapacity, UErrorCode *status); @@ -1159,7 +1183,7 @@ uloc_getLocaleForLCID(uint32_t hostID, char *locale, int32_t localeCapacity, * On error, the return value is -1. * @stable ICU 4.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_addLikelySubtags(const char* localeID, char* maximizedLocaleID, int32_t maximizedLocaleIDCapacity, @@ -1199,7 +1223,7 @@ uloc_addLikelySubtags(const char* localeID, * On error, the return value is -1. * @stable ICU 4.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_minimizeSubtags(const char* localeID, char* minimizedLocaleID, int32_t minimizedLocaleIDCapacity, @@ -1210,13 +1234,17 @@ uloc_minimizeSubtags(const char* localeID, * If the specified language tag contains any ill-formed subtags, * the first such subtag and all following subtags are ignored. *

    - * This implements the 'Language-Tag' production of BCP47, and so - * supports grandfathered (regular and irregular) as well as private - * use language tags. Private use tags are represented as 'x-whatever', - * and grandfathered tags are converted to their canonical replacements - * where they exist. Note that a few grandfathered tags have no modern - * replacement, these will be converted using the fallback described in + * This implements the 'Language-Tag' production of BCP 47, and so + * supports legacy language tags (marked as “Type: grandfathered” in BCP 47) + * (regular and irregular) as well as private use language tags. + * + * Private use tags are represented as 'x-whatever', + * and legacy tags are converted to their canonical replacements where they exist. + * + * Note that a few legacy tags have no modern replacement; + * these will be converted using the fallback described in * the first paragraph, so some information might be lost. + * * @param langtag the input BCP47 language tag. * @param localeID the output buffer receiving a locale ID for the * specified BCP47 language tag. @@ -1228,7 +1256,7 @@ uloc_minimizeSubtags(const char* localeID, * @return the length of the locale ID. * @stable ICU 4.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_forLanguageTag(const char* langtag, char* localeID, int32_t localeIDCapacity, @@ -1238,10 +1266,10 @@ uloc_forLanguageTag(const char* langtag, /** * Returns a well-formed language tag for this locale ID. *

    - * Note: When strict is FALSE, any locale + * Note: When strict is false, any locale * fields which do not satisfy the BCP47 syntax requirement will * be omitted from the result. When strict is - * TRUE, this function sets U_ILLEGAL_ARGUMENT_ERROR to the + * true, this function sets U_ILLEGAL_ARGUMENT_ERROR to the * err if any locale fields do not satisfy the * BCP47 syntax requirement. * @param localeID the input locale ID @@ -1256,7 +1284,7 @@ uloc_forLanguageTag(const char* langtag, * @return The length of the BCP47 language tag. * @stable ICU 4.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uloc_toLanguageTag(const char* localeID, char* langtag, int32_t langtagCapacity, @@ -1284,7 +1312,7 @@ uloc_toLanguageTag(const char* localeID, * @see uloc_toLegacyKey * @stable ICU 54 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uloc_toUnicodeLocaleKey(const char* keyword); /** @@ -1315,7 +1343,7 @@ uloc_toUnicodeLocaleKey(const char* keyword); * @see uloc_toLegacyType * @stable ICU 54 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uloc_toUnicodeLocaleType(const char* keyword, const char* value); /** @@ -1330,7 +1358,7 @@ uloc_toUnicodeLocaleType(const char* keyword, const char* value); * @see toUnicodeLocaleKey * @stable ICU 54 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uloc_toLegacyKey(const char* keyword); /** @@ -1359,7 +1387,7 @@ uloc_toLegacyKey(const char* keyword); * @see toUnicodeLocaleType * @stable ICU 54 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uloc_toLegacyType(const char* keyword, const char* value); #endif /*_ULOC*/ diff --git a/deps/icu-small/source/common/unicode/umachine.h b/deps/icu-small/source/common/unicode/umachine.h index ff5deb8d01786a..219d1ee1911d02 100644 --- a/deps/icu-small/source/common/unicode/umachine.h +++ b/deps/icu-small/source/common/unicode/umachine.h @@ -49,12 +49,13 @@ * ANSI C headers: * stddef.h defines wchar_t */ +#include #include /*==========================================================================*/ -/* For C wrappers, we use the symbol U_STABLE. */ +/* For C wrappers, we use the symbol U_CAPI. */ /* This works properly if the includer is C or C++. */ -/* Functions are declared U_STABLE return-type U_EXPORT2 function-name()... */ +/* Functions are declared U_CAPI return-type U_EXPORT2 function-name()... */ /*==========================================================================*/ /** @@ -107,15 +108,15 @@ /** This is used to declare a function as a public ICU C API @stable ICU 2.0*/ #define U_CAPI U_CFUNC U_EXPORT -/** This is used to declare a function as a stable public ICU C API*/ +/** Obsolete/same as U_CAPI; was used to declare a function as a stable public ICU C API*/ #define U_STABLE U_CAPI -/** This is used to declare a function as a draft public ICU C API */ +/** Obsolete/same as U_CAPI; was used to declare a function as a draft public ICU C API */ #define U_DRAFT U_CAPI /** This is used to declare a function as a deprecated public ICU C API */ #define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED -/** This is used to declare a function as an obsolete public ICU C API */ +/** Obsolete/same as U_CAPI; was used to declare a function as an obsolete public ICU C API */ #define U_OBSOLETE U_CAPI -/** This is used to declare a function as an internal ICU C API */ +/** Obsolete/same as U_CAPI; was used to declare a function as an internal ICU C API */ #define U_INTERNAL U_CAPI /** @@ -170,11 +171,11 @@ /** * \def UPRV_BLOCK_MACRO_END - * Defined as "while (FALSE)" by default. + * Defined as "while (false)" by default. * @internal */ #ifndef UPRV_BLOCK_MACRO_END -#define UPRV_BLOCK_MACRO_END while (FALSE) +#define UPRV_BLOCK_MACRO_END while (false) #endif /*==========================================================================*/ @@ -257,18 +258,59 @@ /* Boolean data type */ /*==========================================================================*/ -/** The ICU boolean type @stable ICU 2.0 */ +/** + * The ICU boolean type, a signed-byte integer. + * ICU-specific for historical reasons: The C and C++ standards used to not define type bool. + * Also provides a fixed type definition, as opposed to + * type bool whose details (e.g., sizeof) may vary by compiler and between C and C++. + * + * @stable ICU 2.0 + */ typedef int8_t UBool; +/** + * \def U_DEFINE_FALSE_AND_TRUE + * Normally turns off defining macros FALSE=0 & TRUE=1 in public ICU headers. + * These obsolete macros sometimes break compilation of other code that + * defines enum constants or similar with these names. + * C++ has long defined bool/false/true. + * C99 also added definitions for these, although as macros; see stdbool.h. + * + * You may transitionally define U_DEFINE_FALSE_AND_TRUE=1 if you need time to migrate code. + * + * @internal ICU 68 + */ +#ifdef U_DEFINE_FALSE_AND_TRUE + // Use the predefined value. +#elif defined(U_COMBINED_IMPLEMENTATION) || \ + defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || \ + defined(U_IO_IMPLEMENTATION) || defined(U_LAYOUTEX_IMPLEMENTATION) || \ + defined(U_TOOLUTIL_IMPLEMENTATION) + // Inside ICU: Keep FALSE & TRUE available. +# define U_DEFINE_FALSE_AND_TRUE 1 +#else + // Outside ICU: Avoid collision with non-macro definitions of FALSE & TRUE. +# define U_DEFINE_FALSE_AND_TRUE 0 +#endif + +#if U_DEFINE_FALSE_AND_TRUE || defined(U_IN_DOXYGEN) #ifndef TRUE -/** The TRUE value of a UBool @stable ICU 2.0 */ +/** + * The TRUE value of a UBool. + * + * @deprecated ICU 68 Use standard "true" instead. + */ # define TRUE 1 #endif #ifndef FALSE -/** The FALSE value of a UBool @stable ICU 2.0 */ +/** + * The FALSE value of a UBool. + * + * @deprecated ICU 68 Use standard "false" instead. + */ # define FALSE 0 #endif - +#endif // U_DEFINE_FALSE_AND_TRUE /*==========================================================================*/ /* Unicode data types */ diff --git a/deps/icu-small/source/common/unicode/umutablecptrie.h b/deps/icu-small/source/common/unicode/umutablecptrie.h index f2af36477d5300..5325d58147ab1f 100644 --- a/deps/icu-small/source/common/unicode/umutablecptrie.h +++ b/deps/icu-small/source/common/unicode/umutablecptrie.h @@ -9,11 +9,14 @@ #include "unicode/utypes.h" -#include "unicode/localpointer.h" #include "unicode/ucpmap.h" #include "unicode/ucptrie.h" #include "unicode/utf8.h" +#if U_SHOW_CPLUSPLUS_API +#include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API + U_CDECL_BEGIN /** diff --git a/deps/icu-small/source/common/unicode/unimatch.h b/deps/icu-small/source/common/unicode/unimatch.h index 2d3c5210c38e25..10efd3d007a5ca 100644 --- a/deps/icu-small/source/common/unicode/unimatch.h +++ b/deps/icu-small/source/common/unicode/unimatch.h @@ -115,11 +115,11 @@ class U_COMMON_API UnicodeMatcher /* not : public UObject because this is an int * considered for matching will be text.charAt(limit-1) in the * forward direction or text.charAt(limit+1) in the backward * direction. - * @param incremental if TRUE, then assume further characters may + * @param incremental if true, then assume further characters may * be inserted at limit and check for partial matching. Otherwise * assume the text as given is complete. * @return a match degree value indicating a full match, a partial - * match, or a mismatch. If incremental is FALSE then + * match, or a mismatch. If incremental is false then * U_PARTIAL_MATCH should never be returned. * @stable ICU 2.4 */ @@ -134,17 +134,17 @@ class U_COMMON_API UnicodeMatcher /* not : public UObject because this is an int * will produce another matcher that is equal to this one. * @param result the string to receive the pattern. Previous * contents will be deleted. - * @param escapeUnprintable if TRUE then convert unprintable + * @param escapeUnprintable if true then convert unprintable * character to their hex escape representations, \\uxxxx or * \\Uxxxxxxxx. Unprintable characters are those other than * U+000A, U+0020..U+007E. * @stable ICU 2.4 */ virtual UnicodeString& toPattern(UnicodeString& result, - UBool escapeUnprintable = FALSE) const = 0; + UBool escapeUnprintable = false) const = 0; /** - * Returns TRUE if this matcher will match a character c, where c + * Returns true if this matcher will match a character c, where c * & 0xFF == v, at offset, in the forward direction (with limit > * offset). This is used by RuleBasedTransliterator for * indexing. diff --git a/deps/icu-small/source/common/unicode/uniset.h b/deps/icu-small/source/common/unicode/uniset.h index 18cc9376442a2f..4179507af18e6f 100644 --- a/deps/icu-small/source/common/unicode/uniset.h +++ b/deps/icu-small/source/common/unicode/uniset.h @@ -325,7 +325,7 @@ class U_COMMON_API UnicodeSet U_FINAL : public UnicodeFilter { * A bogus set has no value. It is different from an empty set. * It can be used to indicate that no set value is available. * - * @return TRUE if the set is bogus/invalid, FALSE otherwise + * @return true if the set is bogus/invalid, false otherwise * @see setToBogus() * @stable ICU 4.0 */ @@ -333,7 +333,7 @@ class U_COMMON_API UnicodeSet U_FINAL : public UnicodeFilter { /** * Make this UnicodeSet object invalid. - * The string will test TRUE with isBogus(). + * The string will test true with isBogus(). * * A bogus set has no value. It is different from an empty set. * It can be used to indicate that no set value is available. @@ -563,7 +563,7 @@ class U_COMMON_API UnicodeSet U_FINAL : public UnicodeFilter { /** * Determines whether the set has been frozen (made immutable) or not. * See the ICU4J Freezable interface for details. - * @return TRUE/FALSE for whether the set has been frozen + * @return true/false for whether the set has been frozen * @see freeze * @see cloneAsThawed * @stable ICU 3.8 @@ -700,14 +700,14 @@ class U_COMMON_API UnicodeSet U_FINAL : public UnicodeFilter { * A frozen set will not be modified. * @param result the string to receive the rules. Previous * contents will be deleted. - * @param escapeUnprintable if TRUE then convert unprintable + * @param escapeUnprintable if true then convert unprintable * character to their hex escape representations, \\uxxxx or * \\Uxxxxxxxx. Unprintable characters are those other than * U+000A, U+0020..U+007E. * @stable ICU 2.0 */ virtual UnicodeString& toPattern(UnicodeString& result, - UBool escapeUnprintable = FALSE) const; + UBool escapeUnprintable = false) const; /** * Modifies this set to contain those code points which have the given value @@ -1636,7 +1636,7 @@ class U_COMMON_API UnicodeSet U_FINAL : public UnicodeFilter { static const UnicodeSet* getInclusions(int32_t src, UErrorCode &status); /** - * A filter that returns TRUE if the given code point should be + * A filter that returns true if the given code point should be * included in the UnicodeSet being constructed. */ typedef UBool (*Filter)(UChar32 codePoint, void* context); diff --git a/deps/icu-small/source/common/unicode/unistr.h b/deps/icu-small/source/common/unicode/unistr.h index da79053765acf6..456389f265fea0 100644 --- a/deps/icu-small/source/common/unicode/unistr.h +++ b/deps/icu-small/source/common/unicode/unistr.h @@ -45,7 +45,7 @@ struct UConverter; // unicode/ucnv.h /** * \ingroup ustring_ustrlen */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strlen(const UChar *s); #endif @@ -113,9 +113,9 @@ class UnicodeStringAppendable; // unicode/appendable.h * @stable ICU 2.0 */ #if !U_CHAR16_IS_TYPEDEF -# define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length) +# define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length) #else -# define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length) +# define UNICODE_STRING(cs, _length) icu::UnicodeString(true, (const char16_t*)u ## cs, _length) #endif /** @@ -227,7 +227,7 @@ class UnicodeStringAppendable; // unicode/appendable.h * The UnicodeString class is not suitable for subclassing. * * For an overview of Unicode strings in C and C++ see the - * [User Guide Strings chapter](http://userguide.icu-project.org/strings#TOC-Strings-in-C-C-). + * [User Guide Strings chapter](https://unicode-org.github.io/icu/userguide/strings#strings-in-cc). * * In ICU, a Unicode string consists of 16-bit Unicode *code units*. * A Unicode character may be stored with either one code unit @@ -285,7 +285,7 @@ class UnicodeStringAppendable; // unicode/appendable.h * significant performance improvements. * Also, the internal buffer is accessible via special functions. * For details see the - * [User Guide Strings chapter](http://userguide.icu-project.org/strings#TOC-Maximizing-Performance-with-the-UnicodeString-Storage-Model). + * [User Guide Strings chapter](https://unicode-org.github.io/icu/userguide/strings#maximizing-performance-with-the-unicodestring-storage-model). * * @see utf.h * @see CharacterIterator @@ -320,8 +320,8 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Equality operator. Performs only bitwise comparison. * @param text The UnicodeString to compare to this one. - * @return TRUE if `text` contains the same characters as this one, - * FALSE otherwise. + * @return true if `text` contains the same characters as this one, + * false otherwise. * @stable ICU 2.0 */ inline UBool operator== (const UnicodeString& text) const; @@ -329,8 +329,8 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Inequality operator. Performs only bitwise comparison. * @param text The UnicodeString to compare to this one. - * @return FALSE if `text` contains the same characters as this one, - * TRUE otherwise. + * @return false if `text` contains the same characters as this one, + * true otherwise. * @stable ICU 2.0 */ inline UBool operator!= (const UnicodeString& text) const; @@ -338,8 +338,8 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Greater than operator. Performs only bitwise comparison. * @param text The UnicodeString to compare to this one. - * @return TRUE if the characters in this are bitwise - * greater than the characters in `text`, FALSE otherwise + * @return true if the characters in this are bitwise + * greater than the characters in `text`, false otherwise * @stable ICU 2.0 */ inline UBool operator> (const UnicodeString& text) const; @@ -347,8 +347,8 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Less than operator. Performs only bitwise comparison. * @param text The UnicodeString to compare to this one. - * @return TRUE if the characters in this are bitwise - * less than the characters in `text`, FALSE otherwise + * @return true if the characters in this are bitwise + * less than the characters in `text`, false otherwise * @stable ICU 2.0 */ inline UBool operator< (const UnicodeString& text) const; @@ -356,8 +356,8 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Greater than or equal operator. Performs only bitwise comparison. * @param text The UnicodeString to compare to this one. - * @return TRUE if the characters in this are bitwise - * greater than or equal to the characters in `text`, FALSE otherwise + * @return true if the characters in this are bitwise + * greater than or equal to the characters in `text`, false otherwise * @stable ICU 2.0 */ inline UBool operator>= (const UnicodeString& text) const; @@ -365,8 +365,8 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Less than or equal operator. Performs only bitwise comparison. * @param text The UnicodeString to compare to this one. - * @return TRUE if the characters in this are bitwise - * less than or equal to the characters in `text`, FALSE otherwise + * @return true if the characters in this are bitwise + * less than or equal to the characters in `text`, false otherwise * @stable ICU 2.0 */ inline UBool operator<= (const UnicodeString& text) const; @@ -855,8 +855,8 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Determine if this starts with the characters in `text` * @param text The text to match. - * @return TRUE if this starts with the characters in `text`, - * FALSE otherwise + * @return true if this starts with the characters in `text`, + * false otherwise * @stable ICU 2.0 */ inline UBool startsWith(const UnicodeString& text) const; @@ -867,8 +867,8 @@ class U_COMMON_API UnicodeString : public Replaceable * @param srcText The text to match. * @param srcStart the offset into `srcText` to start matching * @param srcLength the number of characters in `srcText` to match - * @return TRUE if this starts with the characters in `text`, - * FALSE otherwise + * @return true if this starts with the characters in `text`, + * false otherwise * @stable ICU 2.0 */ inline UBool startsWith(const UnicodeString& srcText, @@ -879,8 +879,8 @@ class U_COMMON_API UnicodeString : public Replaceable * Determine if this starts with the characters in `srcChars` * @param srcChars The characters to match. * @param srcLength the number of characters in `srcChars` - * @return TRUE if this starts with the characters in `srcChars`, - * FALSE otherwise + * @return true if this starts with the characters in `srcChars`, + * false otherwise * @stable ICU 2.0 */ inline UBool startsWith(ConstChar16Ptr srcChars, @@ -892,7 +892,7 @@ class U_COMMON_API UnicodeString : public Replaceable * @param srcChars The characters to match. * @param srcStart the offset into `srcText` to start matching * @param srcLength the number of characters in `srcChars` to match - * @return TRUE if this ends with the characters in `srcChars`, FALSE otherwise + * @return true if this ends with the characters in `srcChars`, false otherwise * @stable ICU 2.0 */ inline UBool startsWith(const char16_t *srcChars, @@ -902,8 +902,8 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Determine if this ends with the characters in `text` * @param text The text to match. - * @return TRUE if this ends with the characters in `text`, - * FALSE otherwise + * @return true if this ends with the characters in `text`, + * false otherwise * @stable ICU 2.0 */ inline UBool endsWith(const UnicodeString& text) const; @@ -914,8 +914,8 @@ class U_COMMON_API UnicodeString : public Replaceable * @param srcText The text to match. * @param srcStart the offset into `srcText` to start matching * @param srcLength the number of characters in `srcText` to match - * @return TRUE if this ends with the characters in `text`, - * FALSE otherwise + * @return true if this ends with the characters in `text`, + * false otherwise * @stable ICU 2.0 */ inline UBool endsWith(const UnicodeString& srcText, @@ -926,8 +926,8 @@ class U_COMMON_API UnicodeString : public Replaceable * Determine if this ends with the characters in `srcChars` * @param srcChars The characters to match. * @param srcLength the number of characters in `srcChars` - * @return TRUE if this ends with the characters in `srcChars`, - * FALSE otherwise + * @return true if this ends with the characters in `srcChars`, + * false otherwise * @stable ICU 2.0 */ inline UBool endsWith(ConstChar16Ptr srcChars, @@ -939,8 +939,8 @@ class U_COMMON_API UnicodeString : public Replaceable * @param srcChars The characters to match. * @param srcStart the offset into `srcText` to start matching * @param srcLength the number of characters in `srcChars` to match - * @return TRUE if this ends with the characters in `srcChars`, - * FALSE otherwise + * @return true if this ends with the characters in `srcChars`, + * false otherwise * @stable ICU 2.0 */ inline UBool endsWith(const char16_t *srcChars, @@ -1804,7 +1804,7 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Determine if this string is empty. - * @return TRUE if this string contains 0 characters, FALSE otherwise. + * @return true if this string contains 0 characters, false otherwise. * @stable ICU 2.0 */ inline UBool isEmpty(void) const; @@ -1832,12 +1832,12 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Determine if this object contains a valid string. * A bogus string has no value. It is different from an empty string, - * although in both cases isEmpty() returns TRUE and length() returns 0. + * although in both cases isEmpty() returns true and length() returns 0. * setToBogus() and isBogus() can be used to indicate that no string value is available. * For a bogus string, getBuffer() and getTerminatedBuffer() return NULL, and * length() returns 0. * - * @return TRUE if the string is bogus/invalid, FALSE otherwise + * @return true if the string is bogus/invalid, false otherwise * @see setToBogus() * @stable ICU 2.0 */ @@ -2067,7 +2067,7 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Make this UnicodeString object invalid. - * The string will test TRUE with isBogus(). + * The string will test true with isBogus(). * * A bogus string has no value. It is different from an empty string. * It can be used to indicate that no string value is available. @@ -2459,7 +2459,7 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Replaceable API - * @return TRUE if it has MetaData + * @return true if it has MetaData * @stable ICU 2.4 */ virtual UBool hasMetaData() const; @@ -2590,7 +2590,7 @@ class U_COMMON_API UnicodeString : public Replaceable * @param targetLength the desired length of the string * @param padChar the character to use for padding. Defaults to * space (U+0020) - * @return TRUE if the text was padded, FALSE otherwise. + * @return true if the text was padded, false otherwise. * @stable ICU 2.0 */ UBool padLeading(int32_t targetLength, @@ -2604,7 +2604,7 @@ class U_COMMON_API UnicodeString : public Replaceable * @param targetLength the desired length of the string * @param padChar the character to use for padding. Defaults to * space (U+0020) - * @return TRUE if the text was padded, FALSE otherwise. + * @return true if the text was padded, false otherwise. * @stable ICU 2.0 */ UBool padTrailing(int32_t targetLength, @@ -2613,7 +2613,7 @@ class U_COMMON_API UnicodeString : public Replaceable /** * Truncate this UnicodeString to the `targetLength`. * @param targetLength the desired length of this UnicodeString. - * @return TRUE if the text was truncated, FALSE otherwise + * @return true if the text was truncated, false otherwise * @stable ICU 2.0 */ inline UBool truncate(int32_t targetLength); @@ -3615,7 +3615,7 @@ class U_COMMON_API UnicodeString : public Replaceable void unBogus(); // implements assigment operator, copy constructor, and fastCopyFrom() - UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE); + UnicodeString ©From(const UnicodeString &src, UBool fastCopy=false); // Copies just the fields without memory management. void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT; @@ -3668,13 +3668,13 @@ class U_COMMON_API UnicodeString : public Replaceable * the buffer is refCounted (shared), and refCount>1, or * the buffer is too small. * - * Return FALSE if memory could not be allocated. + * Return false if memory could not be allocated. */ UBool cloneArrayIfNeeded(int32_t newCapacity = -1, int32_t growCapacity = -1, - UBool doCopyArray = TRUE, + UBool doCopyArray = true, int32_t **pBufferToDelete = 0, - UBool forceClone = FALSE); + UBool forceClone = false); /** * Common function for UnicodeString case mappings. @@ -4732,12 +4732,12 @@ UnicodeString::truncate(int32_t targetLength) if(isBogus() && targetLength == 0) { // truncate(0) of a bogus string makes the string empty and non-bogus unBogus(); - return FALSE; + return false; } else if((uint32_t)targetLength < (uint32_t)length()) { setLength(targetLength); - return TRUE; + return true; } else { - return FALSE; + return false; } } diff --git a/deps/icu-small/source/common/unicode/unorm.h b/deps/icu-small/source/common/unicode/unorm.h index 09dd366a968c1b..c3c57582d449d5 100644 --- a/deps/icu-small/source/common/unicode/unorm.h +++ b/deps/icu-small/source/common/unicode/unorm.h @@ -274,7 +274,7 @@ unorm_quickCheckWithOptions(const UChar *src, int32_t srcLength, * never a "maybe". * For NFD, NFKD, and FCD, both functions work exactly the same. * For NFC and NFKC where quickCheck may return "maybe", this function will - * perform further tests to arrive at a TRUE/FALSE result. + * perform further tests to arrive at a true/false result. * * @param src String that is to be tested if it is in a normalization format. * @param srcLength Length of source to test, or -1 if NUL-terminated. @@ -358,10 +358,10 @@ unorm_isNormalizedWithOptions(const UChar *src, int32_t srcLength, * It is useful for operations like a normalizing transliterator, where one would * not want to replace a piece of text if it is not modified. * - * If doNormalize==TRUE and pNeededToNormalize!=NULL then *pNeeded... is set TRUE + * If doNormalize==true and pNeededToNormalize!=NULL then *pNeeded... is set true * if the normalization was necessary. * - * If doNormalize==FALSE then *pNeededToNormalize will be set to FALSE. + * If doNormalize==false then *pNeededToNormalize will be set to false. * * If the buffer overflows, then *pNeededToNormalize will be undefined; * essentially, whenever U_FAILURE is true (like in buffer overflows), this result @@ -373,11 +373,11 @@ unorm_isNormalizedWithOptions(const UChar *src, int32_t srcLength, * @param mode The normalization mode. * @param options The normalization options, ORed together (0 for no options). * @param doNormalize Indicates if the source text up to the next boundary - * is to be normalized (TRUE) or just copied (FALSE). + * is to be normalized (true) or just copied (false). * @param pNeededToNormalize Output flag indicating if the normalization resulted in * different text from the input. * Not defined if an error occurs including buffer overflow. - * Always FALSE if !doNormalize. + * Always false if !doNormalize. * @param pErrorCode ICU error code in/out parameter. * Must fulfill U_SUCCESS before the function call. * @return Length of output (number of UChars) when successful or buffer overflow. @@ -406,11 +406,11 @@ unorm_next(UCharIterator *src, * @param mode The normalization mode. * @param options The normalization options, ORed together (0 for no options). * @param doNormalize Indicates if the source text up to the next boundary - * is to be normalized (TRUE) or just copied (FALSE). + * is to be normalized (true) or just copied (false). * @param pNeededToNormalize Output flag indicating if the normalization resulted in * different text from the input. * Not defined if an error occurs including buffer overflow. - * Always FALSE if !doNormalize. + * Always false if !doNormalize. * @param pErrorCode ICU error code in/out parameter. * Must fulfill U_SUCCESS before the function call. * @return Length of output (number of UChars) when successful or buffer overflow. diff --git a/deps/icu-small/source/common/unicode/unorm2.h b/deps/icu-small/source/common/unicode/unorm2.h index a9bd02f256361f..24417b7103c12e 100644 --- a/deps/icu-small/source/common/unicode/unorm2.h +++ b/deps/icu-small/source/common/unicode/unorm2.h @@ -31,10 +31,13 @@ */ #include "unicode/utypes.h" -#include "unicode/localpointer.h" #include "unicode/stringoptions.h" #include "unicode/uset.h" +#if U_SHOW_CPLUSPLUS_API +#include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API + /** * Constants for normalization modes. * For details about standard Unicode normalization forms @@ -132,7 +135,7 @@ typedef struct UNormalizer2 UNormalizer2; /**< C typedef for struct UNormalizer * @return the requested Normalizer2, if successful * @stable ICU 49 */ -U_STABLE const UNormalizer2 * U_EXPORT2 +U_CAPI const UNormalizer2 * U_EXPORT2 unorm2_getNFCInstance(UErrorCode *pErrorCode); /** @@ -146,7 +149,7 @@ unorm2_getNFCInstance(UErrorCode *pErrorCode); * @return the requested Normalizer2, if successful * @stable ICU 49 */ -U_STABLE const UNormalizer2 * U_EXPORT2 +U_CAPI const UNormalizer2 * U_EXPORT2 unorm2_getNFDInstance(UErrorCode *pErrorCode); /** @@ -160,7 +163,7 @@ unorm2_getNFDInstance(UErrorCode *pErrorCode); * @return the requested Normalizer2, if successful * @stable ICU 49 */ -U_STABLE const UNormalizer2 * U_EXPORT2 +U_CAPI const UNormalizer2 * U_EXPORT2 unorm2_getNFKCInstance(UErrorCode *pErrorCode); /** @@ -174,7 +177,7 @@ unorm2_getNFKCInstance(UErrorCode *pErrorCode); * @return the requested Normalizer2, if successful * @stable ICU 49 */ -U_STABLE const UNormalizer2 * U_EXPORT2 +U_CAPI const UNormalizer2 * U_EXPORT2 unorm2_getNFKDInstance(UErrorCode *pErrorCode); /** @@ -188,7 +191,7 @@ unorm2_getNFKDInstance(UErrorCode *pErrorCode); * @return the requested Normalizer2, if successful * @stable ICU 49 */ -U_STABLE const UNormalizer2 * U_EXPORT2 +U_CAPI const UNormalizer2 * U_EXPORT2 unorm2_getNFKCCasefoldInstance(UErrorCode *pErrorCode); /** @@ -212,7 +215,7 @@ unorm2_getNFKCCasefoldInstance(UErrorCode *pErrorCode); * @return the requested UNormalizer2, if successful * @stable ICU 4.4 */ -U_STABLE const UNormalizer2 * U_EXPORT2 +U_CAPI const UNormalizer2 * U_EXPORT2 unorm2_getInstance(const char *packageName, const char *name, UNormalization2Mode mode, @@ -233,7 +236,7 @@ unorm2_getInstance(const char *packageName, * @return the requested UNormalizer2, if successful * @stable ICU 4.4 */ -U_STABLE UNormalizer2 * U_EXPORT2 +U_CAPI UNormalizer2 * U_EXPORT2 unorm2_openFiltered(const UNormalizer2 *norm2, const USet *filterSet, UErrorCode *pErrorCode); /** @@ -242,7 +245,7 @@ unorm2_openFiltered(const UNormalizer2 *norm2, const USet *filterSet, UErrorCode * @param norm2 UNormalizer2 instance to be closed * @stable ICU 4.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 unorm2_close(UNormalizer2 *norm2); #if U_SHOW_CPLUSPLUS_API @@ -280,7 +283,7 @@ U_NAMESPACE_END * @return dest * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 unorm2_normalize(const UNormalizer2 *norm2, const UChar *src, int32_t length, UChar *dest, int32_t capacity, @@ -303,7 +306,7 @@ unorm2_normalize(const UNormalizer2 *norm2, * @return first * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 unorm2_normalizeSecondAndAppend(const UNormalizer2 *norm2, UChar *first, int32_t firstLength, int32_t firstCapacity, const UChar *second, int32_t secondLength, @@ -326,7 +329,7 @@ unorm2_normalizeSecondAndAppend(const UNormalizer2 *norm2, * @return first * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 unorm2_append(const UNormalizer2 *norm2, UChar *first, int32_t firstLength, int32_t firstCapacity, const UChar *second, int32_t secondLength, @@ -351,7 +354,7 @@ unorm2_append(const UNormalizer2 *norm2, * @return the non-negative length of c's decomposition, if there is one; otherwise a negative value * @stable ICU 4.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 unorm2_getDecomposition(const UNormalizer2 *norm2, UChar32 c, UChar *decomposition, int32_t capacity, UErrorCode *pErrorCode); @@ -385,7 +388,7 @@ unorm2_getDecomposition(const UNormalizer2 *norm2, * @return the non-negative length of c's raw decomposition, if there is one; otherwise a negative value * @stable ICU 49 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 unorm2_getRawDecomposition(const UNormalizer2 *norm2, UChar32 c, UChar *decomposition, int32_t capacity, UErrorCode *pErrorCode); @@ -405,7 +408,7 @@ unorm2_getRawDecomposition(const UNormalizer2 *norm2, * @return The non-negative composite code point if there is one; otherwise a negative value. * @stable ICU 49 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 unorm2_composePair(const UNormalizer2 *norm2, UChar32 a, UChar32 b); /** @@ -417,7 +420,7 @@ unorm2_composePair(const UNormalizer2 *norm2, UChar32 a, UChar32 b); * @return c's combining class * @stable ICU 49 */ -U_STABLE uint8_t U_EXPORT2 +U_CAPI uint8_t U_EXPORT2 unorm2_getCombiningClass(const UNormalizer2 *norm2, UChar32 c); /** @@ -433,10 +436,10 @@ unorm2_getCombiningClass(const UNormalizer2 *norm2, UChar32 c); * pass the U_SUCCESS() test, or else the function returns * immediately. Check for U_FAILURE() on output or use with * function chaining. (See User Guide for details.) - * @return TRUE if s is normalized + * @return true if s is normalized * @stable ICU 4.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 unorm2_isNormalized(const UNormalizer2 *norm2, const UChar *s, int32_t length, UErrorCode *pErrorCode); @@ -458,7 +461,7 @@ unorm2_isNormalized(const UNormalizer2 *norm2, * @return UNormalizationCheckResult * @stable ICU 4.4 */ -U_STABLE UNormalizationCheckResult U_EXPORT2 +U_CAPI UNormalizationCheckResult U_EXPORT2 unorm2_quickCheck(const UNormalizer2 *norm2, const UChar *s, int32_t length, UErrorCode *pErrorCode); @@ -487,7 +490,7 @@ unorm2_quickCheck(const UNormalizer2 *norm2, * @return "yes" span end index * @stable ICU 4.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 unorm2_spanQuickCheckYes(const UNormalizer2 *norm2, const UChar *s, int32_t length, UErrorCode *pErrorCode); @@ -498,10 +501,10 @@ unorm2_spanQuickCheckYes(const UNormalizer2 *norm2, * For details see the Normalizer2 base class documentation. * @param norm2 UNormalizer2 instance * @param c character to test - * @return TRUE if c has a normalization boundary before it + * @return true if c has a normalization boundary before it * @stable ICU 4.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 unorm2_hasBoundaryBefore(const UNormalizer2 *norm2, UChar32 c); /** @@ -510,10 +513,10 @@ unorm2_hasBoundaryBefore(const UNormalizer2 *norm2, UChar32 c); * For details see the Normalizer2 base class documentation. * @param norm2 UNormalizer2 instance * @param c character to test - * @return TRUE if c has a normalization boundary after it + * @return true if c has a normalization boundary after it * @stable ICU 4.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 unorm2_hasBoundaryAfter(const UNormalizer2 *norm2, UChar32 c); /** @@ -521,10 +524,10 @@ unorm2_hasBoundaryAfter(const UNormalizer2 *norm2, UChar32 c); * For details see the Normalizer2 base class documentation. * @param norm2 UNormalizer2 instance * @param c character to test - * @return TRUE if c is normalization-inert + * @return true if c is normalization-inert * @stable ICU 4.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 unorm2_isInert(const UNormalizer2 *norm2, UChar32 c); /** @@ -593,7 +596,7 @@ unorm2_isInert(const UNormalizer2 *norm2, UChar32 c); * * @stable ICU 2.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 unorm_compare(const UChar *s1, int32_t length1, const UChar *s2, int32_t length2, uint32_t options, diff --git a/deps/icu-small/source/common/unicode/urename.h b/deps/icu-small/source/common/unicode/urename.h index 30f4b7af39adc5..20232cd209c2d6 100644 --- a/deps/icu-small/source/common/unicode/urename.h +++ b/deps/icu-small/source/common/unicode/urename.h @@ -130,7 +130,6 @@ #define izrule_getStaticClassID U_ICU_ENTRY_POINT_RENAME(izrule_getStaticClassID) #define izrule_isEquivalentTo U_ICU_ENTRY_POINT_RENAME(izrule_isEquivalentTo) #define izrule_open U_ICU_ENTRY_POINT_RENAME(izrule_open) -#define locale_getKeywords U_ICU_ENTRY_POINT_RENAME(locale_getKeywords) #define locale_getKeywordsStart U_ICU_ENTRY_POINT_RENAME(locale_getKeywordsStart) #define locale_get_default U_ICU_ENTRY_POINT_RENAME(locale_get_default) #define locale_set_default U_ICU_ENTRY_POINT_RENAME(locale_set_default) @@ -918,9 +917,11 @@ #define udtitvfmt_format U_ICU_ENTRY_POINT_RENAME(udtitvfmt_format) #define udtitvfmt_formatCalendarToResult U_ICU_ENTRY_POINT_RENAME(udtitvfmt_formatCalendarToResult) #define udtitvfmt_formatToResult U_ICU_ENTRY_POINT_RENAME(udtitvfmt_formatToResult) +#define udtitvfmt_getContext U_ICU_ENTRY_POINT_RENAME(udtitvfmt_getContext) #define udtitvfmt_open U_ICU_ENTRY_POINT_RENAME(udtitvfmt_open) #define udtitvfmt_openResult U_ICU_ENTRY_POINT_RENAME(udtitvfmt_openResult) #define udtitvfmt_resultAsValue U_ICU_ENTRY_POINT_RENAME(udtitvfmt_resultAsValue) +#define udtitvfmt_setContext U_ICU_ENTRY_POINT_RENAME(udtitvfmt_setContext) #define uenum_close U_ICU_ENTRY_POINT_RENAME(uenum_close) #define uenum_count U_ICU_ENTRY_POINT_RENAME(uenum_count) #define uenum_next U_ICU_ENTRY_POINT_RENAME(uenum_next) @@ -1079,7 +1080,6 @@ #define uloc_getDisplayLanguage U_ICU_ENTRY_POINT_RENAME(uloc_getDisplayLanguage) #define uloc_getDisplayName U_ICU_ENTRY_POINT_RENAME(uloc_getDisplayName) #define uloc_getDisplayScript U_ICU_ENTRY_POINT_RENAME(uloc_getDisplayScript) -#define uloc_getDisplayScriptInContext U_ICU_ENTRY_POINT_RENAME(uloc_getDisplayScriptInContext) #define uloc_getDisplayVariant U_ICU_ENTRY_POINT_RENAME(uloc_getDisplayVariant) #define uloc_getISO3Country U_ICU_ENTRY_POINT_RENAME(uloc_getISO3Country) #define uloc_getISO3Language U_ICU_ENTRY_POINT_RENAME(uloc_getISO3Language) @@ -1123,10 +1123,14 @@ #define ulocimp_forLanguageTag U_ICU_ENTRY_POINT_RENAME(ulocimp_forLanguageTag) #define ulocimp_getBaseName U_ICU_ENTRY_POINT_RENAME(ulocimp_getBaseName) #define ulocimp_getCountry U_ICU_ENTRY_POINT_RENAME(ulocimp_getCountry) +#define ulocimp_getKeywordValue U_ICU_ENTRY_POINT_RENAME(ulocimp_getKeywordValue) +#define ulocimp_getKeywords U_ICU_ENTRY_POINT_RENAME(ulocimp_getKeywords) +#define ulocimp_getKnownCanonicalizedLocaleForTest U_ICU_ENTRY_POINT_RENAME(ulocimp_getKnownCanonicalizedLocaleForTest) #define ulocimp_getLanguage U_ICU_ENTRY_POINT_RENAME(ulocimp_getLanguage) #define ulocimp_getName U_ICU_ENTRY_POINT_RENAME(ulocimp_getName) #define ulocimp_getRegionForSupplementalData U_ICU_ENTRY_POINT_RENAME(ulocimp_getRegionForSupplementalData) #define ulocimp_getScript U_ICU_ENTRY_POINT_RENAME(ulocimp_getScript) +#define ulocimp_isCanonicalizedLocaleForTest U_ICU_ENTRY_POINT_RENAME(ulocimp_isCanonicalizedLocaleForTest) #define ulocimp_minimizeSubtags U_ICU_ENTRY_POINT_RENAME(ulocimp_minimizeSubtags) #define ulocimp_toBcpKey U_ICU_ENTRY_POINT_RENAME(ulocimp_toBcpKey) #define ulocimp_toBcpType U_ICU_ENTRY_POINT_RENAME(ulocimp_toBcpType) @@ -1245,7 +1249,18 @@ #define unumf_resultAsValue U_ICU_ENTRY_POINT_RENAME(unumf_resultAsValue) #define unumf_resultGetAllFieldPositions U_ICU_ENTRY_POINT_RENAME(unumf_resultGetAllFieldPositions) #define unumf_resultNextFieldPosition U_ICU_ENTRY_POINT_RENAME(unumf_resultNextFieldPosition) +#define unumf_resultToDecimalNumber U_ICU_ENTRY_POINT_RENAME(unumf_resultToDecimalNumber) #define unumf_resultToString U_ICU_ENTRY_POINT_RENAME(unumf_resultToString) +#define unumrf_close U_ICU_ENTRY_POINT_RENAME(unumrf_close) +#define unumrf_closeResult U_ICU_ENTRY_POINT_RENAME(unumrf_closeResult) +#define unumrf_formatDecimalRange U_ICU_ENTRY_POINT_RENAME(unumrf_formatDecimalRange) +#define unumrf_formatDoubleRange U_ICU_ENTRY_POINT_RENAME(unumrf_formatDoubleRange) +#define unumrf_openForSkeletonWithCollapseAndIdentityFallback U_ICU_ENTRY_POINT_RENAME(unumrf_openForSkeletonWithCollapseAndIdentityFallback) +#define unumrf_openResult U_ICU_ENTRY_POINT_RENAME(unumrf_openResult) +#define unumrf_resultAsValue U_ICU_ENTRY_POINT_RENAME(unumrf_resultAsValue) +#define unumrf_resultGetFirstDecimalNumber U_ICU_ENTRY_POINT_RENAME(unumrf_resultGetFirstDecimalNumber) +#define unumrf_resultGetIdentityResult U_ICU_ENTRY_POINT_RENAME(unumrf_resultGetIdentityResult) +#define unumrf_resultGetSecondDecimalNumber U_ICU_ENTRY_POINT_RENAME(unumrf_resultGetSecondDecimalNumber) #define unumsys_close U_ICU_ENTRY_POINT_RENAME(unumsys_close) #define unumsys_getDescription U_ICU_ENTRY_POINT_RENAME(unumsys_getDescription) #define unumsys_getName U_ICU_ENTRY_POINT_RENAME(unumsys_getName) @@ -1259,6 +1274,7 @@ #define uplrules_open U_ICU_ENTRY_POINT_RENAME(uplrules_open) #define uplrules_openForType U_ICU_ENTRY_POINT_RENAME(uplrules_openForType) #define uplrules_select U_ICU_ENTRY_POINT_RENAME(uplrules_select) +#define uplrules_selectForRange U_ICU_ENTRY_POINT_RENAME(uplrules_selectForRange) #define uplrules_selectFormatted U_ICU_ENTRY_POINT_RENAME(uplrules_selectFormatted) #define uplrules_selectWithFormat U_ICU_ENTRY_POINT_RENAME(uplrules_selectWithFormat) #define uplug_closeLibrary U_ICU_ENTRY_POINT_RENAME(uplug_closeLibrary) diff --git a/deps/icu-small/source/common/unicode/ures.h b/deps/icu-small/source/common/unicode/ures.h index 839779fada804d..fff84043e84785 100644 --- a/deps/icu-small/source/common/unicode/ures.h +++ b/deps/icu-small/source/common/unicode/ures.h @@ -27,7 +27,10 @@ #include "unicode/utypes.h" #include "unicode/uloc.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API /** * \file @@ -163,7 +166,7 @@ typedef enum { * @see ures_close * @stable ICU 2.0 */ -U_STABLE UResourceBundle* U_EXPORT2 +U_CAPI UResourceBundle* U_EXPORT2 ures_open(const char* packageName, const char* locale, UErrorCode* status); @@ -186,7 +189,7 @@ ures_open(const char* packageName, * @see ures_close * @stable ICU 2.0 */ -U_STABLE UResourceBundle* U_EXPORT2 +U_CAPI UResourceBundle* U_EXPORT2 ures_openDirect(const char* packageName, const char* locale, UErrorCode* status); @@ -209,7 +212,7 @@ ures_openDirect(const char* packageName, * @see ures_open * @stable ICU 2.0 */ -U_STABLE UResourceBundle* U_EXPORT2 +U_CAPI UResourceBundle* U_EXPORT2 ures_openU(const UChar* packageName, const char* locale, UErrorCode* status); @@ -245,7 +248,7 @@ ures_countArrayItems(const UResourceBundle* resourceBundle, * @see ures_open * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ures_close(UResourceBundle* resourceBundle); #if U_SHOW_CPLUSPLUS_API @@ -291,7 +294,7 @@ ures_getVersionNumber(const UResourceBundle* resourceBundle); * as specified in the resource bundle or its parent. * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ures_getVersion(const UResourceBundle* resB, UVersionInfo versionInfo); @@ -325,7 +328,7 @@ ures_getLocale(const UResourceBundle* resourceBundle, * @return A Locale name * @stable ICU 2.8 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 ures_getLocaleByType(const UResourceBundle* resourceBundle, ULocDataLocaleType type, UErrorCode* status); @@ -348,7 +351,7 @@ ures_getLocaleByType(const UResourceBundle* resourceBundle, * @param status The error code. * @internal */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 ures_openFillIn(UResourceBundle *r, const char* packageName, const char* localeID, @@ -372,7 +375,7 @@ ures_openFillIn(UResourceBundle *r, * @see ures_getUInt * @stable ICU 2.0 */ -U_STABLE const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ures_getString(const UResourceBundle* resourceBundle, int32_t* len, UErrorCode* status); @@ -383,10 +386,10 @@ ures_getString(const UResourceBundle* resourceBundle, * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() * or equivalent. * - * If forceCopy==TRUE, then the string is always written to the dest buffer + * If forceCopy==true, then the string is always written to the dest buffer * and dest is returned. * - * If forceCopy==FALSE, then the string is returned as a pointer if possible, + * If forceCopy==false, then the string is returned as a pointer if possible, * without needing a dest buffer (it can be NULL). If the string needs to be * copied or transformed, then it may be placed into dest at an arbitrary offset. * @@ -404,10 +407,10 @@ ures_getString(const UResourceBundle* resourceBundle, * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. * Can be NULL, meaning capacity=0 and the string length is not * returned to the caller. - * @param forceCopy If TRUE, then the output string will always be written to + * @param forceCopy If true, then the output string will always be written to * dest, with U_BUFFER_OVERFLOW_ERROR and * U_STRING_NOT_TERMINATED_WARNING set if appropriate. - * If FALSE, then the dest buffer may or may not contain a + * If false, then the dest buffer may or may not contain a * copy of the string. dest may or may not be modified. * If a copy needs to be written, then the UErrorCode parameter * indicates overflow etc. as usual. @@ -424,7 +427,7 @@ ures_getString(const UResourceBundle* resourceBundle, * @see u_strToUTF8 * @stable ICU 3.6 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ures_getUTF8String(const UResourceBundle *resB, char *dest, int32_t *length, UBool forceCopy, @@ -447,7 +450,7 @@ ures_getUTF8String(const UResourceBundle *resB, * @see ures_getUInt * @stable ICU 2.0 */ -U_STABLE const uint8_t* U_EXPORT2 +U_CAPI const uint8_t* U_EXPORT2 ures_getBinary(const UResourceBundle* resourceBundle, int32_t* len, UErrorCode* status); @@ -469,7 +472,7 @@ ures_getBinary(const UResourceBundle* resourceBundle, * @see ures_getUInt * @stable ICU 2.0 */ -U_STABLE const int32_t* U_EXPORT2 +U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resourceBundle, int32_t* len, UErrorCode* status); @@ -490,7 +493,7 @@ ures_getIntVector(const UResourceBundle* resourceBundle, * @see ures_getString * @stable ICU 2.0 */ -U_STABLE uint32_t U_EXPORT2 +U_CAPI uint32_t U_EXPORT2 ures_getUInt(const UResourceBundle* resourceBundle, UErrorCode *status); @@ -510,7 +513,7 @@ ures_getUInt(const UResourceBundle* resourceBundle, * @see ures_getString * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ures_getInt(const UResourceBundle* resourceBundle, UErrorCode *status); @@ -524,7 +527,7 @@ ures_getInt(const UResourceBundle* resourceBundle, * @return number of resources in a given resource. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ures_getSize(const UResourceBundle *resourceBundle); /** @@ -535,7 +538,7 @@ ures_getSize(const UResourceBundle *resourceBundle); * @see UResType * @stable ICU 2.0 */ -U_STABLE UResType U_EXPORT2 +U_CAPI UResType U_EXPORT2 ures_getType(const UResourceBundle *resourceBundle); /** @@ -546,7 +549,7 @@ ures_getType(const UResourceBundle *resourceBundle); * @return a key associated to this resource, or NULL if it doesn't have a key * @stable ICU 2.0 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ures_getKey(const UResourceBundle *resourceBundle); /* ITERATION API @@ -559,17 +562,17 @@ ures_getKey(const UResourceBundle *resourceBundle); * @param resourceBundle a resource * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ures_resetIterator(UResourceBundle *resourceBundle); /** * Checks whether the given resource has another element to iterate over. * * @param resourceBundle a resource - * @return TRUE if there are more elements, FALSE if there is no more elements + * @return true if there are more elements, false if there is no more elements * @stable ICU 2.0 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ures_hasNext(const UResourceBundle *resourceBundle); /** @@ -584,7 +587,7 @@ ures_hasNext(const UResourceBundle *resourceBundle); * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it * @stable ICU 2.0 */ -U_STABLE UResourceBundle* U_EXPORT2 +U_CAPI UResourceBundle* U_EXPORT2 ures_getNextResource(UResourceBundle *resourceBundle, UResourceBundle *fillIn, UErrorCode *status); @@ -601,7 +604,7 @@ ures_getNextResource(UResourceBundle *resourceBundle, * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. * @stable ICU 2.0 */ -U_STABLE const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ures_getNextString(UResourceBundle *resourceBundle, int32_t* len, const char ** key, @@ -619,7 +622,7 @@ ures_getNextString(UResourceBundle *resourceBundle, * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it * @stable ICU 2.0 */ -U_STABLE UResourceBundle* U_EXPORT2 +U_CAPI UResourceBundle* U_EXPORT2 ures_getByIndex(const UResourceBundle *resourceBundle, int32_t indexR, UResourceBundle *fillIn, @@ -636,7 +639,7 @@ ures_getByIndex(const UResourceBundle *resourceBundle, * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. * @stable ICU 2.0 */ -U_STABLE const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ures_getStringByIndex(const UResourceBundle *resourceBundle, int32_t indexS, int32_t* len, @@ -648,10 +651,10 @@ ures_getStringByIndex(const UResourceBundle *resourceBundle, * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() * or equivalent. * - * If forceCopy==TRUE, then the string is always written to the dest buffer + * If forceCopy==true, then the string is always written to the dest buffer * and dest is returned. * - * If forceCopy==FALSE, then the string is returned as a pointer if possible, + * If forceCopy==false, then the string is returned as a pointer if possible, * without needing a dest buffer (it can be NULL). If the string needs to be * copied or transformed, then it may be placed into dest at an arbitrary offset. * @@ -670,10 +673,10 @@ ures_getStringByIndex(const UResourceBundle *resourceBundle, * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. * Can be NULL, meaning capacity=0 and the string length is not * returned to the caller. - * @param forceCopy If TRUE, then the output string will always be written to + * @param forceCopy If true, then the output string will always be written to * dest, with U_BUFFER_OVERFLOW_ERROR and * U_STRING_NOT_TERMINATED_WARNING set if appropriate. - * If FALSE, then the dest buffer may or may not contain a + * If false, then the dest buffer may or may not contain a * copy of the string. dest may or may not be modified. * If a copy needs to be written, then the UErrorCode parameter * indicates overflow etc. as usual. @@ -690,7 +693,7 @@ ures_getStringByIndex(const UResourceBundle *resourceBundle, * @see u_strToUTF8 * @stable ICU 3.6 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ures_getUTF8StringByIndex(const UResourceBundle *resB, int32_t stringIndex, char *dest, int32_t *pLength, @@ -709,7 +712,7 @@ ures_getUTF8StringByIndex(const UResourceBundle *resB, * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it * @stable ICU 2.0 */ -U_STABLE UResourceBundle* U_EXPORT2 +U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resourceBundle, const char* key, UResourceBundle *fillIn, @@ -727,7 +730,7 @@ ures_getByKey(const UResourceBundle *resourceBundle, * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. * @stable ICU 2.0 */ -U_STABLE const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, const char* key, int32_t* len, @@ -741,10 +744,10 @@ ures_getStringByKey(const UResourceBundle *resB, * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() * or equivalent. * - * If forceCopy==TRUE, then the string is always written to the dest buffer + * If forceCopy==true, then the string is always written to the dest buffer * and dest is returned. * - * If forceCopy==FALSE, then the string is returned as a pointer if possible, + * If forceCopy==false, then the string is returned as a pointer if possible, * without needing a dest buffer (it can be NULL). If the string needs to be * copied or transformed, then it may be placed into dest at an arbitrary offset. * @@ -763,10 +766,10 @@ ures_getStringByKey(const UResourceBundle *resB, * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. * Can be NULL, meaning capacity=0 and the string length is not * returned to the caller. - * @param forceCopy If TRUE, then the output string will always be written to + * @param forceCopy If true, then the output string will always be written to * dest, with U_BUFFER_OVERFLOW_ERROR and * U_STRING_NOT_TERMINATED_WARNING set if appropriate. - * If FALSE, then the dest buffer may or may not contain a + * If false, then the dest buffer may or may not contain a * copy of the string. dest may or may not be modified. * If a copy needs to be written, then the UErrorCode parameter * indicates overflow etc. as usual. @@ -783,7 +786,7 @@ ures_getStringByKey(const UResourceBundle *resB, * @see u_strToUTF8 * @stable ICU 3.6 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ures_getUTF8StringByKey(const UResourceBundle *resB, const char *key, char *dest, int32_t *pLength, @@ -811,7 +814,7 @@ ures_getUnicodeString(const UResourceBundle *resB, UErrorCode* status) { int32_t len = 0; const UChar *r = ures_getString(resB, &len, status); if(U_SUCCESS(*status)) { - result.setTo(TRUE, r, len); + result.setTo(true, r, len); } else { result.setToBogus(); } @@ -836,7 +839,7 @@ ures_getNextUnicodeString(UResourceBundle *resB, const char ** key, UErrorCode* int32_t len = 0; const UChar* r = ures_getNextString(resB, &len, key, status); if(U_SUCCESS(*status)) { - result.setTo(TRUE, r, len); + result.setTo(true, r, len); } else { result.setToBogus(); } @@ -858,7 +861,7 @@ ures_getUnicodeStringByIndex(const UResourceBundle *resB, int32_t indexS, UError int32_t len = 0; const UChar* r = ures_getStringByIndex(resB, indexS, &len, status); if(U_SUCCESS(*status)) { - result.setTo(TRUE, r, len); + result.setTo(true, r, len); } else { result.setToBogus(); } @@ -881,7 +884,7 @@ ures_getUnicodeStringByKey(const UResourceBundle *resB, const char* key, UErrorC int32_t len = 0; const UChar* r = ures_getStringByKey(resB, key, &len, status); if(U_SUCCESS(*status)) { - result.setTo(TRUE, r, len); + result.setTo(true, r, len); } else { result.setToBogus(); } @@ -900,7 +903,7 @@ U_NAMESPACE_END * @param status error code * @stable ICU 3.2 */ -U_STABLE UEnumeration* U_EXPORT2 +U_CAPI UEnumeration* U_EXPORT2 ures_openAvailableLocales(const char *packageName, UErrorCode *status); diff --git a/deps/icu-small/source/common/unicode/uscript.h b/deps/icu-small/source/common/unicode/uscript.h index 53d57abed14cd0..8448afda761550 100644 --- a/deps/icu-small/source/common/unicode/uscript.h +++ b/deps/icu-small/source/common/unicode/uscript.h @@ -514,7 +514,7 @@ typedef enum UScriptCode { * @return The number of script codes filled in the buffer passed in * @stable ICU 2.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uscript_getCode(const char* nameOrAbbrOrLocale,UScriptCode* fillIn,int32_t capacity,UErrorCode *err); /** @@ -527,7 +527,7 @@ uscript_getCode(const char* nameOrAbbrOrLocale,UScriptCode* fillIn,int32_t capac * or NULL if scriptCode is invalid * @stable ICU 2.4 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uscript_getName(UScriptCode scriptCode); /** @@ -539,7 +539,7 @@ uscript_getName(UScriptCode scriptCode); * @return short script name (4-letter code), or NULL if scriptCode is invalid * @stable ICU 2.4 */ -U_STABLE const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uscript_getShortName(UScriptCode scriptCode); /** @@ -550,7 +550,7 @@ uscript_getShortName(UScriptCode scriptCode); * @return The UScriptCode, or 0 if codepoint is invalid * @stable ICU 2.4 */ -U_STABLE UScriptCode U_EXPORT2 +U_CAPI UScriptCode U_EXPORT2 uscript_getScript(UChar32 codepoint, UErrorCode *err); /** @@ -562,10 +562,10 @@ uscript_getScript(UChar32 codepoint, UErrorCode *err); * For more information, see UAX #24: http://www.unicode.org/reports/tr24/. * @param c code point * @param sc script code - * @return TRUE if sc is in Script_Extensions(c) + * @return true if sc is in Script_Extensions(c) * @stable ICU 49 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uscript_hasScript(UChar32 c, UScriptCode sc); /** @@ -597,7 +597,7 @@ uscript_hasScript(UChar32 c, UScriptCode sc); * written to scripts unless U_BUFFER_OVERFLOW_ERROR indicates insufficient capacity * @stable ICU 49 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uscript_getScriptExtensions(UChar32 c, UScriptCode *scripts, int32_t capacity, UErrorCode *errorCode); @@ -636,7 +636,7 @@ typedef enum UScriptUsage { * @return the string length, even if U_BUFFER_OVERFLOW_ERROR * @stable ICU 51 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uscript_getSampleString(UScriptCode script, UChar *dest, int32_t capacity, UErrorCode *pErrorCode); #if U_SHOW_CPLUSPLUS_API @@ -668,41 +668,41 @@ uscript_getSampleUnicodeString(UScriptCode script); * @see UScriptUsage * @stable ICU 51 */ -U_STABLE UScriptUsage U_EXPORT2 +U_CAPI UScriptUsage U_EXPORT2 uscript_getUsage(UScriptCode script); /** - * Returns TRUE if the script is written right-to-left. + * Returns true if the script is written right-to-left. * For example, Arab and Hebr. * * @param script script code - * @return TRUE if the script is right-to-left + * @return true if the script is right-to-left * @stable ICU 51 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uscript_isRightToLeft(UScriptCode script); /** - * Returns TRUE if the script allows line breaks between letters (excluding hyphenation). + * Returns true if the script allows line breaks between letters (excluding hyphenation). * Such a script typically requires dictionary-based line breaking. * For example, Hani and Thai. * * @param script script code - * @return TRUE if the script allows line breaks between letters + * @return true if the script allows line breaks between letters * @stable ICU 51 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uscript_breaksBetweenLetters(UScriptCode script); /** - * Returns TRUE if in modern (or most recent) usage of the script case distinctions are customary. + * Returns true if in modern (or most recent) usage of the script case distinctions are customary. * For example, Latn and Cyrl. * * @param script script code - * @return TRUE if the script is cased + * @return true if the script is cased * @stable ICU 51 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uscript_isCased(UScriptCode script); #endif diff --git a/deps/icu-small/source/common/unicode/uset.h b/deps/icu-small/source/common/unicode/uset.h index ef6bbb5c38f3fb..473cc6fbae4e0d 100644 --- a/deps/icu-small/source/common/unicode/uset.h +++ b/deps/icu-small/source/common/unicode/uset.h @@ -31,7 +31,10 @@ #include "unicode/utypes.h" #include "unicode/uchar.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API #ifndef USET_DEFINED @@ -158,7 +161,7 @@ typedef enum USetSpanCondition { * Continues a span() while there is no set element at the current position. * Increments by one code point at a time. * Stops before the first set element (character or string). - * (For code points only, this is like while contains(current)==FALSE). + * (For code points only, this is like while contains(current)==false). * * When span() returns, the substring between where it started and the position * it returned consists only of characters that are not in the set, @@ -169,7 +172,7 @@ typedef enum USetSpanCondition { USET_SPAN_NOT_CONTAINED = 0, /** * Spans the longest substring that is a concatenation of set elements (characters or strings). - * (For characters only, this is like while contains(current)==TRUE). + * (For characters only, this is like while contains(current)==true). * * When span() returns, the substring between where it started and the position * it returned consists only of set elements (characters or strings) that are in the set. @@ -185,7 +188,7 @@ typedef enum USetSpanCondition { /** * Continues a span() while there is a set element at the current position. * Increments by the longest matching element at each position. - * (For characters only, this is like while contains(current)==TRUE). + * (For characters only, this is like while contains(current)==true). * * When span() returns, the substring between where it started and the position * it returned consists only of set elements (characters or strings) that are in the set. @@ -260,7 +263,7 @@ typedef struct USerializedSet { * it when done. * @stable ICU 4.2 */ -U_STABLE USet* U_EXPORT2 +U_CAPI USet* U_EXPORT2 uset_openEmpty(void); /** @@ -273,7 +276,7 @@ uset_openEmpty(void); * it when done. * @stable ICU 2.4 */ -U_STABLE USet* U_EXPORT2 +U_CAPI USet* U_EXPORT2 uset_open(UChar32 start, UChar32 end); /** @@ -285,7 +288,7 @@ uset_open(UChar32 start, UChar32 end); * @param ec the error code * @stable ICU 2.4 */ -U_STABLE USet* U_EXPORT2 +U_CAPI USet* U_EXPORT2 uset_openPattern(const UChar* pattern, int32_t patternLength, UErrorCode* ec); @@ -300,7 +303,7 @@ uset_openPattern(const UChar* pattern, int32_t patternLength, * @param ec the error code * @stable ICU 2.4 */ -U_STABLE USet* U_EXPORT2 +U_CAPI USet* U_EXPORT2 uset_openPatternOptions(const UChar* pattern, int32_t patternLength, uint32_t options, UErrorCode* ec); @@ -311,7 +314,7 @@ uset_openPatternOptions(const UChar* pattern, int32_t patternLength, * @param set the object to dispose of * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_close(USet* set); #if U_SHOW_CPLUSPLUS_API @@ -342,19 +345,19 @@ U_NAMESPACE_END * @see uset_cloneAsThawed * @stable ICU 3.8 */ -U_STABLE USet * U_EXPORT2 +U_CAPI USet * U_EXPORT2 uset_clone(const USet *set); /** * Determines whether the set has been frozen (made immutable) or not. * See the ICU4J Freezable interface for details. * @param set the set - * @return TRUE/FALSE for whether the set has been frozen + * @return true/false for whether the set has been frozen * @see uset_freeze * @see uset_cloneAsThawed * @stable ICU 3.8 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_isFrozen(const USet *set); /** @@ -371,7 +374,7 @@ uset_isFrozen(const USet *set); * @see uset_cloneAsThawed * @stable ICU 3.8 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_freeze(USet *set); /** @@ -384,7 +387,7 @@ uset_freeze(USet *set); * @see uset_clone * @stable ICU 3.8 */ -U_STABLE USet * U_EXPORT2 +U_CAPI USet * U_EXPORT2 uset_cloneAsThawed(const USet *set); /** @@ -396,7 +399,7 @@ uset_cloneAsThawed(const USet *set); * @param end last character in the set, inclusive * @stable ICU 3.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_set(USet* set, UChar32 start, UChar32 end); @@ -421,7 +424,7 @@ uset_set(USet* set, * * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_applyPattern(USet *set, const UChar *pattern, int32_t patternLength, uint32_t options, @@ -449,7 +452,7 @@ uset_applyPattern(USet *set, * * @stable ICU 3.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_applyIntPropertyValue(USet* set, UProperty prop, int32_t value, UErrorCode* ec); @@ -488,7 +491,7 @@ uset_applyIntPropertyValue(USet* set, * * @stable ICU 3.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_applyPropertyAlias(USet* set, const UChar *prop, int32_t propLength, const UChar *value, int32_t valueLength, @@ -503,7 +506,7 @@ uset_applyPropertyAlias(USet* set, * @param pos the given position * @stable ICU 3.2 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_resemblesPattern(const UChar *pattern, int32_t patternLength, int32_t pos); @@ -514,7 +517,7 @@ uset_resemblesPattern(const UChar *pattern, int32_t patternLength, * @param set the set * @param result the string to receive the rules, may be NULL * @param resultCapacity the capacity of result, may be 0 if result is NULL - * @param escapeUnprintable if TRUE then convert unprintable + * @param escapeUnprintable if true then convert unprintable * character to their hex escape representations, \\uxxxx or * \\Uxxxxxxxx. Unprintable characters are those other than * U+000A, U+0020..U+007E. @@ -522,7 +525,7 @@ uset_resemblesPattern(const UChar *pattern, int32_t patternLength, * @return length of string, possibly larger than resultCapacity * @stable ICU 2.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_toPattern(const USet* set, UChar* result, int32_t resultCapacity, UBool escapeUnprintable, @@ -530,13 +533,13 @@ uset_toPattern(const USet* set, /** * Adds the given character to the given USet. After this call, - * uset_contains(set, c) will return TRUE. + * uset_contains(set, c) will return true. * A frozen set will not be modified. * @param set the object to which to add the character * @param c the character to add * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_add(USet* set, UChar32 c); /** @@ -551,31 +554,31 @@ uset_add(USet* set, UChar32 c); * @param additionalSet the source set whose elements are to be added to this set. * @stable ICU 2.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_addAll(USet* set, const USet *additionalSet); /** * Adds the given range of characters to the given USet. After this call, - * uset_contains(set, start, end) will return TRUE. + * uset_contains(set, start, end) will return true. * A frozen set will not be modified. * @param set the object to which to add the character * @param start the first character of the range to add, inclusive * @param end the last character of the range to add, inclusive * @stable ICU 2.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_addRange(USet* set, UChar32 start, UChar32 end); /** * Adds the given string to the given USet. After this call, - * uset_containsString(set, str, strLen) will return TRUE. + * uset_containsString(set, str, strLen) will return true. * A frozen set will not be modified. * @param set the object to which to add the character * @param str the string to add * @param strLen the length of the string or -1 if null terminated. * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_addString(USet* set, const UChar* str, int32_t strLen); /** @@ -587,42 +590,42 @@ uset_addString(USet* set, const UChar* str, int32_t strLen); * @param strLen the length of the string or -1 if null terminated. * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_addAllCodePoints(USet* set, const UChar *str, int32_t strLen); /** * Removes the given character from the given USet. After this call, - * uset_contains(set, c) will return FALSE. + * uset_contains(set, c) will return false. * A frozen set will not be modified. * @param set the object from which to remove the character * @param c the character to remove * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_remove(USet* set, UChar32 c); /** * Removes the given range of characters from the given USet. After this call, - * uset_contains(set, start, end) will return FALSE. + * uset_contains(set, start, end) will return false. * A frozen set will not be modified. * @param set the object to which to add the character * @param start the first character of the range to remove, inclusive * @param end the last character of the range to remove, inclusive * @stable ICU 2.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_removeRange(USet* set, UChar32 start, UChar32 end); /** * Removes the given string to the given USet. After this call, - * uset_containsString(set, str, strLen) will return FALSE. + * uset_containsString(set, str, strLen) will return false. * A frozen set will not be modified. * @param set the object to which to add the character * @param str the string to remove * @param strLen the length of the string or -1 if null terminated. * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_removeString(USet* set, const UChar* str, int32_t strLen); /** @@ -636,7 +639,7 @@ uset_removeString(USet* set, const UChar* str, int32_t strLen); * removed from this set * @stable ICU 3.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_removeAll(USet* set, const USet* removeSet); /** @@ -653,7 +656,7 @@ uset_removeAll(USet* set, const USet* removeSet); * to this set. * @stable ICU 3.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_retain(USet* set, UChar32 start, UChar32 end); /** @@ -668,7 +671,7 @@ uset_retain(USet* set, UChar32 start, UChar32 end); * @param retain set that defines which elements this set will retain * @stable ICU 3.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_retainAll(USet* set, const USet* retain); /** @@ -679,7 +682,7 @@ uset_retainAll(USet* set, const USet* retain); * @param set the object on which to perfrom the compact * @stable ICU 3.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_compact(USet* set); /** @@ -690,7 +693,7 @@ uset_compact(USet* set); * @param set the set * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_complement(USet* set); /** @@ -704,7 +707,7 @@ uset_complement(USet* set); * from this set. * @stable ICU 3.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_complementAll(USet* set, const USet* complement); /** @@ -714,7 +717,7 @@ uset_complementAll(USet* set, const USet* complement); * @param set the set * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_clear(USet* set); /** @@ -743,7 +746,7 @@ uset_clear(USet* set); * are ignored. * @stable ICU 4.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_closeOver(USet* set, int32_t attributes); /** @@ -752,51 +755,51 @@ uset_closeOver(USet* set, int32_t attributes); * @param set the set * @stable ICU 4.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_removeAllStrings(USet* set); /** - * Returns TRUE if the given USet contains no characters and no + * Returns true if the given USet contains no characters and no * strings. * @param set the set * @return true if set is empty * @stable ICU 2.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_isEmpty(const USet* set); /** - * Returns TRUE if the given USet contains the given character. + * Returns true if the given USet contains the given character. * This function works faster with a frozen set. * @param set the set * @param c The codepoint to check for within the set * @return true if set contains c * @stable ICU 2.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_contains(const USet* set, UChar32 c); /** - * Returns TRUE if the given USet contains all characters c + * Returns true if the given USet contains all characters c * where start <= c && c <= end. * @param set the set * @param start the first character of the range to test, inclusive * @param end the last character of the range to test, inclusive - * @return TRUE if set contains the range + * @return true if set contains the range * @stable ICU 2.2 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_containsRange(const USet* set, UChar32 start, UChar32 end); /** - * Returns TRUE if the given USet contains the given string. + * Returns true if the given USet contains the given string. * @param set the set * @param str the string * @param strLen the length of the string or -1 if null terminated. * @return true if set contains str * @stable ICU 2.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_containsString(const USet* set, const UChar* str, int32_t strLen); /** @@ -809,7 +812,7 @@ uset_containsString(const USet* set, const UChar* str, int32_t strLen); * @return an index from 0..size()-1, or -1 * @stable ICU 3.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_indexOf(const USet* set, UChar32 c); /** @@ -822,7 +825,7 @@ uset_indexOf(const USet* set, UChar32 c); * @return the character at the given index, or (UChar32)-1. * @stable ICU 3.2 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 uset_charAt(const USet* set, int32_t charIndex); /** @@ -833,7 +836,7 @@ uset_charAt(const USet* set, int32_t charIndex); * contained in set * @stable ICU 2.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_size(const USet* set); /** @@ -844,7 +847,7 @@ uset_size(const USet* set); * and/or strings contained in set * @stable ICU 2.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_getItemCount(const USet* set); /** @@ -865,7 +868,7 @@ uset_getItemCount(const USet* set); * itemIndex is out of range * @stable ICU 2.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_getItem(const USet* set, int32_t itemIndex, UChar32* start, UChar32* end, UChar* str, int32_t strCapacity, @@ -879,7 +882,7 @@ uset_getItem(const USet* set, int32_t itemIndex, * @return true if the test condition is met * @stable ICU 3.2 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_containsAll(const USet* set1, const USet* set2); /** @@ -892,7 +895,7 @@ uset_containsAll(const USet* set1, const USet* set2); * @return true if the test condition is met * @stable ICU 3.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_containsAllCodePoints(const USet* set, const UChar *str, int32_t strLen); /** @@ -903,7 +906,7 @@ uset_containsAllCodePoints(const USet* set, const UChar *str, int32_t strLen); * @return true if the test condition is met * @stable ICU 3.2 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_containsNone(const USet* set1, const USet* set2); /** @@ -914,7 +917,7 @@ uset_containsNone(const USet* set1, const USet* set2); * @return true if the test condition is met * @stable ICU 3.2 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_containsSome(const USet* set1, const USet* set2); /** @@ -936,7 +939,7 @@ uset_containsSome(const USet* set1, const USet* set2); * @stable ICU 3.8 * @see USetSpanCondition */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_span(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition); /** @@ -957,7 +960,7 @@ uset_span(const USet *set, const UChar *s, int32_t length, USetSpanCondition spa * @stable ICU 3.8 * @see USetSpanCondition */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_spanBack(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition); /** @@ -979,7 +982,7 @@ uset_spanBack(const USet *set, const UChar *s, int32_t length, USetSpanCondition * @stable ICU 3.8 * @see USetSpanCondition */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_spanUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition); /** @@ -1000,7 +1003,7 @@ uset_spanUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition * @stable ICU 3.8 * @see USetSpanCondition */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_spanBackUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition); /** @@ -1011,7 +1014,7 @@ uset_spanBackUTF8(const USet *set, const char *s, int32_t length, USetSpanCondit * @return true if the test condition is met * @stable ICU 3.2 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_equals(const USet* set1, const USet* set2); /********************************************************************* @@ -1067,7 +1070,7 @@ uset_equals(const USet* set1, const USet* set2); * than U_BUFFER_OVERFLOW_ERROR. * @stable ICU 2.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_serialize(const USet* set, uint16_t* dest, int32_t destCapacity, UErrorCode* pErrorCode); /** @@ -1078,7 +1081,7 @@ uset_serialize(const USet* set, uint16_t* dest, int32_t destCapacity, UErrorCode * @return true if the given array is valid, otherwise false * @stable ICU 2.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_getSerializedSet(USerializedSet* fillSet, const uint16_t* src, int32_t srcLength); /** @@ -1088,18 +1091,18 @@ uset_getSerializedSet(USerializedSet* fillSet, const uint16_t* src, int32_t srcL * @param c The codepoint to set * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 uset_setSerializedToOne(USerializedSet* fillSet, UChar32 c); /** - * Returns TRUE if the given USerializedSet contains the given + * Returns true if the given USerializedSet contains the given * character. * @param set the serialized set * @param c The codepoint to check for within the set * @return true if set contains c * @stable ICU 2.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_serializedContains(const USerializedSet* set, UChar32 c); /** @@ -1111,7 +1114,7 @@ uset_serializedContains(const USerializedSet* set, UChar32 c); * contained in set * @stable ICU 2.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 uset_getSerializedRangeCount(const USerializedSet* set); /** @@ -1127,7 +1130,7 @@ uset_getSerializedRangeCount(const USerializedSet* set); * @return true if rangeIndex is valid, otherwise false * @stable ICU 2.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 uset_getSerializedRange(const USerializedSet* set, int32_t rangeIndex, UChar32* pStart, UChar32* pEnd); diff --git a/deps/icu-small/source/common/unicode/usetiter.h b/deps/icu-small/source/common/unicode/usetiter.h index f3f470f95aa5f5..45d268a05c9b90 100644 --- a/deps/icu-small/source/common/unicode/usetiter.h +++ b/deps/icu-small/source/common/unicode/usetiter.h @@ -176,7 +176,7 @@ class U_COMMON_API UnicodeSetIterator : public UObject { * If there are no more elements in the set, return false. * *

    - * If isString() == TRUE, the value is a + * If isString() == true, the value is a * string, otherwise the value is a * single code point. Elements of either type can be retrieved * with the function getString(), while elements of @@ -197,7 +197,7 @@ class U_COMMON_API UnicodeSetIterator : public UObject { /** * Returns the next element in the set, either a code point range * or a string. If there are no more elements in the set, return - * false. If isString() == TRUE, the value is a + * false. If isString() == true, the value is a * string and can be accessed with getString(). Otherwise the value is a * range of one or more code points from getCodepoint() to * getCodepointeEnd() inclusive. @@ -205,7 +205,7 @@ class U_COMMON_API UnicodeSetIterator : public UObject { *

    The order of iteration is all code points ranges in sorted * order, followed by all strings sorted order. Ranges are * disjoint and non-contiguous. The value returned from getString() - * is undefined unless isString() == TRUE. Do not mix calls to + * is undefined unless isString() == true. Do not mix calls to * next() and nextRange() without calling * reset() between them. The results of doing so are * undefined. diff --git a/deps/icu-small/source/common/unicode/ushape.h b/deps/icu-small/source/common/unicode/ushape.h index 3064e0857281c5..9a85b73e4cba80 100644 --- a/deps/icu-small/source/common/unicode/ushape.h +++ b/deps/icu-small/source/common/unicode/ushape.h @@ -98,7 +98,7 @@ * the return value indicates the necessary destination buffer size. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_shapeArabic(const UChar *source, int32_t sourceLength, UChar *dest, int32_t destSize, uint32_t options, diff --git a/deps/icu-small/source/common/unicode/usprep.h b/deps/icu-small/source/common/unicode/usprep.h index 7cdc6cdd18ea6b..be06189e2e9e6d 100644 --- a/deps/icu-small/source/common/unicode/usprep.h +++ b/deps/icu-small/source/common/unicode/usprep.h @@ -25,7 +25,10 @@ */ #include "unicode/utypes.h" + +#if U_SHOW_CPLUSPLUS_API #include "unicode/localpointer.h" +#endif // U_SHOW_CPLUSPLUS_API /** * @@ -181,7 +184,7 @@ typedef enum UStringPrepProfileType { * @see usprep_close() * @stable ICU 2.8 */ -U_STABLE UStringPrepProfile* U_EXPORT2 +U_CAPI UStringPrepProfile* U_EXPORT2 usprep_open(const char* path, const char* fileName, UErrorCode* status); @@ -197,7 +200,7 @@ usprep_open(const char* path, * @see usprep_close() * @stable ICU 4.2 */ -U_STABLE UStringPrepProfile* U_EXPORT2 +U_CAPI UStringPrepProfile* U_EXPORT2 usprep_openByType(UStringPrepProfileType type, UErrorCode* status); @@ -206,7 +209,7 @@ usprep_openByType(UStringPrepProfileType type, * @param profile The profile to close * @stable ICU 2.8 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 usprep_close(UStringPrepProfile* profile); #if U_SHOW_CPLUSPLUS_API @@ -257,7 +260,7 @@ U_NAMESPACE_END * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 usprep_prepare( const UStringPrepProfile* prep, const UChar* src, int32_t srcLength, UChar* dest, int32_t destCapacity, diff --git a/deps/icu-small/source/common/unicode/ustring.h b/deps/icu-small/source/common/unicode/ustring.h index 0d2274a0cabb51..3243acbb7ebfce 100644 --- a/deps/icu-small/source/common/unicode/ustring.h +++ b/deps/icu-small/source/common/unicode/ustring.h @@ -89,7 +89,7 @@ * @return The number of UChars in chars, minus the terminator. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strlen(const UChar *s); /*@}*/ @@ -106,7 +106,7 @@ u_strlen(const UChar *s); * @return The number of code points in the specified code units. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_countChar32(const UChar *s, int32_t length); /** @@ -127,7 +127,7 @@ u_countChar32(const UChar *s, int32_t length); * than 'number'. Same as (u_countChar32(s, length)>number). * @stable ICU 2.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 u_strHasMoreChar32Than(const UChar *s, int32_t length, int32_t number); /** @@ -140,7 +140,7 @@ u_strHasMoreChar32Than(const UChar *s, int32_t length, int32_t number); * @return A pointer to dst. * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strcat(UChar *dst, const UChar *src); @@ -158,7 +158,7 @@ u_strcat(UChar *dst, * @return A pointer to dst. * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strncat(UChar *dst, const UChar *src, int32_t n); @@ -183,7 +183,7 @@ u_strncat(UChar *dst, * @see u_strFindFirst * @see u_strFindLast */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strstr(const UChar *s, const UChar *substring); /** @@ -207,7 +207,7 @@ u_strstr(const UChar *s, const UChar *substring); * @see u_strstr * @see u_strFindLast */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strFindFirst(const UChar *s, int32_t length, const UChar *substring, int32_t subLength); /** @@ -227,7 +227,7 @@ u_strFindFirst(const UChar *s, int32_t length, const UChar *substring, int32_t s * @see u_strstr * @see u_strFindFirst */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strchr(const UChar *s, UChar c); /** @@ -247,7 +247,7 @@ u_strchr(const UChar *s, UChar c); * @see u_strstr * @see u_strFindFirst */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strchr32(const UChar *s, UChar32 c); /** @@ -270,7 +270,7 @@ u_strchr32(const UChar *s, UChar32 c); * @see u_strFindFirst * @see u_strFindLast */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strrstr(const UChar *s, const UChar *substring); /** @@ -294,7 +294,7 @@ u_strrstr(const UChar *s, const UChar *substring); * @see u_strstr * @see u_strFindLast */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strFindLast(const UChar *s, int32_t length, const UChar *substring, int32_t subLength); /** @@ -314,7 +314,7 @@ u_strFindLast(const UChar *s, int32_t length, const UChar *substring, int32_t su * @see u_strrstr * @see u_strFindLast */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strrchr(const UChar *s, UChar c); /** @@ -334,7 +334,7 @@ u_strrchr(const UChar *s, UChar c); * @see u_strrstr * @see u_strFindLast */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strrchr32(const UChar *s, UChar32 c); /** @@ -349,7 +349,7 @@ u_strrchr32(const UChar *s, UChar32 c); * characters in matchSet, or NULL if no such character is found. * @stable ICU 2.0 */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strpbrk(const UChar *string, const UChar *matchSet); /** @@ -365,7 +365,7 @@ u_strpbrk(const UChar *string, const UChar *matchSet); * @see u_strspn * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strcspn(const UChar *string, const UChar *matchSet); /** @@ -381,7 +381,7 @@ u_strcspn(const UChar *string, const UChar *matchSet); * @see u_strcspn * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strspn(const UChar *string, const UChar *matchSet); /** @@ -409,7 +409,7 @@ u_strspn(const UChar *string, const UChar *matchSet); * when there are no more tokens. * @stable ICU 2.0 */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strtok_r(UChar *src, const UChar *delim, UChar **saveState); @@ -424,7 +424,7 @@ u_strtok_r(UChar *src, * value if s1 is bitwise greater than s2. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strcmp(const UChar *s1, const UChar *s2); @@ -439,7 +439,7 @@ u_strcmp(const UChar *s1, * in code point order * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strcmpCodePointOrder(const UChar *s1, const UChar *s2); /** @@ -462,14 +462,14 @@ u_strcmpCodePointOrder(const UChar *s1, const UChar *s2); * @param s2 Second source string. * @param length2 Length of second source string, or -1 if NUL-terminated. * - * @param codePointOrder Choose between code unit order (FALSE) - * and code point order (TRUE). + * @param codePointOrder Choose between code unit order (false) + * and code point order (true). * * @return <0 or 0 or >0 as usual for string comparisons * * @stable ICU 2.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strCompare(const UChar *s1, int32_t length1, const UChar *s2, int32_t length2, UBool codePointOrder); @@ -485,8 +485,8 @@ u_strCompare(const UChar *s1, int32_t length1, * * @param iter1 First source string iterator. * @param iter2 Second source string iterator. - * @param codePointOrder Choose between code unit order (FALSE) - * and code point order (TRUE). + * @param codePointOrder Choose between code unit order (false) + * and code point order (true). * * @return <0 or 0 or >0 as usual for string comparisons * @@ -494,7 +494,7 @@ u_strCompare(const UChar *s1, int32_t length1, * * @stable ICU 2.6 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrder); /** @@ -537,7 +537,7 @@ u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrde * * @stable ICU 2.2 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strCaseCompare(const UChar *s1, int32_t length1, const UChar *s2, int32_t length2, uint32_t options, @@ -555,7 +555,7 @@ u_strCaseCompare(const UChar *s1, int32_t length1, * value if s1 is bitwise greater than s2. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strncmp(const UChar *ucs1, const UChar *ucs2, int32_t n); @@ -573,7 +573,7 @@ u_strncmp(const UChar *ucs1, * in code point order * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n); /** @@ -595,7 +595,7 @@ u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n); * @return A negative, zero, or positive integer indicating the comparison result. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options); /** @@ -619,7 +619,7 @@ u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options); * @return A negative, zero, or positive integer indicating the comparison result. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options); /** @@ -643,7 +643,7 @@ u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options); * @return A negative, zero, or positive integer indicating the comparison result. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options); /** @@ -654,7 +654,7 @@ u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options) * @return A pointer to dst. * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strcpy(UChar *dst, const UChar *src); @@ -669,7 +669,7 @@ u_strcpy(UChar *dst, * @return A pointer to dst. * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strncpy(UChar *dst, const UChar *src, int32_t n); @@ -686,7 +686,7 @@ u_strncpy(UChar *dst, * @return A pointer to dst. * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 u_uastrcpy(UChar *dst, +U_CAPI UChar* U_EXPORT2 u_uastrcpy(UChar *dst, const char *src ); /** @@ -701,7 +701,7 @@ U_STABLE UChar* U_EXPORT2 u_uastrcpy(UChar *dst, * @return A pointer to dst. * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 u_uastrncpy(UChar *dst, +U_CAPI UChar* U_EXPORT2 u_uastrncpy(UChar *dst, const char *src, int32_t n); @@ -715,7 +715,7 @@ U_STABLE UChar* U_EXPORT2 u_uastrncpy(UChar *dst, * @return A pointer to dst. * @stable ICU 2.0 */ -U_STABLE char* U_EXPORT2 u_austrcpy(char *dst, +U_CAPI char* U_EXPORT2 u_austrcpy(char *dst, const UChar *src ); /** @@ -730,7 +730,7 @@ U_STABLE char* U_EXPORT2 u_austrcpy(char *dst, * @return A pointer to dst. * @stable ICU 2.0 */ -U_STABLE char* U_EXPORT2 u_austrncpy(char *dst, +U_CAPI char* U_EXPORT2 u_austrncpy(char *dst, const UChar *src, int32_t n ); @@ -744,7 +744,7 @@ U_STABLE char* U_EXPORT2 u_austrncpy(char *dst, * @return A pointer to dest * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_memcpy(UChar *dest, const UChar *src, int32_t count); /** @@ -755,7 +755,7 @@ u_memcpy(UChar *dest, const UChar *src, int32_t count); * @return A pointer to dest * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_memmove(UChar *dest, const UChar *src, int32_t count); /** @@ -767,7 +767,7 @@ u_memmove(UChar *dest, const UChar *src, int32_t count); * @return A pointer to dest. * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_memset(UChar *dest, UChar c, int32_t count); /** @@ -781,7 +781,7 @@ u_memset(UChar *dest, UChar c, int32_t count); * When buf1 > buf2, a positive number is returned. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count); /** @@ -797,7 +797,7 @@ u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count); * in code point order * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count); /** @@ -817,7 +817,7 @@ u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count); * @see u_memchr32 * @see u_strFindFirst */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_memchr(const UChar *s, UChar c, int32_t count); /** @@ -837,7 +837,7 @@ u_memchr(const UChar *s, UChar c, int32_t count); * @see u_memchr * @see u_strFindFirst */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_memchr32(const UChar *s, UChar32 c, int32_t count); /** @@ -857,7 +857,7 @@ u_memchr32(const UChar *s, UChar32 c, int32_t count); * @see u_memrchr32 * @see u_strFindLast */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_memrchr(const UChar *s, UChar c, int32_t count); /** @@ -877,7 +877,7 @@ u_memrchr(const UChar *s, UChar c, int32_t count); * @see u_memrchr * @see u_strFindLast */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_memrchr32(const UChar *s, UChar32 c, int32_t count); /** @@ -903,13 +903,13 @@ u_memrchr32(const UChar *s, UChar32 c, int32_t count); * * U_STRING_DECL(ustringVar1, "Quick-Fox 2", 11); * U_STRING_DECL(ustringVar2, "jumps 5%", 8); - * static UBool didInit=FALSE; + * static UBool didInit=false; * * int32_t function() { * if(!didInit) { * U_STRING_INIT(ustringVar1, "Quick-Fox 2", 11); * U_STRING_INIT(ustringVar2, "jumps 5%", 8); - * didInit=TRUE; + * didInit=true; * } * return u_strcmp(ustringVar1, ustringVar2); * } @@ -992,7 +992,7 @@ u_memrchr32(const UChar *s, UChar32 c, int32_t count); * @see UnicodeString#unescapeAt() * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_unescape(const char *src, UChar *dest, int32_t destCapacity); @@ -1040,7 +1040,7 @@ U_CDECL_END * @see UnicodeString#unescapeAt() * @stable ICU 2.0 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 u_unescapeAt(UNESCAPE_CHAR_AT charAt, int32_t *offset, int32_t length, @@ -1066,7 +1066,7 @@ u_unescapeAt(UNESCAPE_CHAR_AT charAt, * only some of the result was written to the destination buffer. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strToUpper(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, const char *locale, @@ -1092,7 +1092,7 @@ u_strToUpper(UChar *dest, int32_t destCapacity, * only some of the result was written to the destination buffer. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strToLower(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, const char *locale, @@ -1138,7 +1138,7 @@ u_strToLower(UChar *dest, int32_t destCapacity, * only some of the result was written to the destination buffer. * @stable ICU 2.1 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strToTitle(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UBreakIterator *titleIter, @@ -1171,7 +1171,7 @@ u_strToTitle(UChar *dest, int32_t destCapacity, * only some of the result was written to the destination buffer. * @stable ICU 2.0 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_strFoldCase(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, uint32_t options, @@ -1200,7 +1200,7 @@ u_strFoldCase(UChar *dest, int32_t destCapacity, * @return The pointer to destination buffer. * @stable ICU 2.0 */ -U_STABLE wchar_t* U_EXPORT2 +U_CAPI wchar_t* U_EXPORT2 u_strToWCS(wchar_t *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1229,7 +1229,7 @@ u_strToWCS(wchar_t *dest, * @return The pointer to destination buffer. * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strFromWCS(UChar *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1260,7 +1260,7 @@ u_strFromWCS(UChar *dest, * @see u_strToUTF8WithSub * @see u_strFromUTF8 */ -U_STABLE char* U_EXPORT2 +U_CAPI char* U_EXPORT2 u_strToUTF8(char *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1290,7 +1290,7 @@ u_strToUTF8(char *dest, * @see u_strFromUTF8WithSub * @see u_strFromUTF8Lenient */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strFromUTF8(UChar *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1333,7 +1333,7 @@ u_strFromUTF8(UChar *dest, * @see u_strFromUTF8WithSub * @stable ICU 3.6 */ -U_STABLE char* U_EXPORT2 +U_CAPI char* U_EXPORT2 u_strToUTF8WithSub(char *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1378,7 +1378,7 @@ u_strToUTF8WithSub(char *dest, * @see u_strToUTF8WithSub * @stable ICU 3.6 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strFromUTF8WithSub(UChar *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1438,7 +1438,7 @@ u_strFromUTF8WithSub(UChar *dest, * @see u_strToUTF8WithSub * @stable ICU 3.6 */ -U_STABLE UChar * U_EXPORT2 +U_CAPI UChar * U_EXPORT2 u_strFromUTF8Lenient(UChar *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1468,7 +1468,7 @@ u_strFromUTF8Lenient(UChar *dest, * @see u_strFromUTF32 * @stable ICU 2.0 */ -U_STABLE UChar32* U_EXPORT2 +U_CAPI UChar32* U_EXPORT2 u_strToUTF32(UChar32 *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1498,7 +1498,7 @@ u_strToUTF32(UChar32 *dest, * @see u_strToUTF32 * @stable ICU 2.0 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strFromUTF32(UChar *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1541,7 +1541,7 @@ u_strFromUTF32(UChar *dest, * @see u_strFromUTF32WithSub * @stable ICU 4.2 */ -U_STABLE UChar32* U_EXPORT2 +U_CAPI UChar32* U_EXPORT2 u_strToUTF32WithSub(UChar32 *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1585,7 +1585,7 @@ u_strToUTF32WithSub(UChar32 *dest, * @see u_strToUTF32WithSub * @stable ICU 4.2 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strFromUTF32WithSub(UChar *dest, int32_t destCapacity, int32_t *pDestLength, @@ -1626,7 +1626,7 @@ u_strFromUTF32WithSub(UChar *dest, * @see u_strToUTF8WithSub * @see u_strFromJavaModifiedUTF8WithSub */ -U_STABLE char* U_EXPORT2 +U_CAPI char* U_EXPORT2 u_strToJavaModifiedUTF8( char *dest, int32_t destCapacity, @@ -1676,7 +1676,7 @@ u_strToJavaModifiedUTF8( * @see u_strToJavaModifiedUTF8 * @stable ICU 4.4 */ -U_STABLE UChar* U_EXPORT2 +U_CAPI UChar* U_EXPORT2 u_strFromJavaModifiedUTF8WithSub( UChar *dest, int32_t destCapacity, diff --git a/deps/icu-small/source/common/unicode/utext.h b/deps/icu-small/source/common/unicode/utext.h index d36c1c035e70f1..084362be78fc9d 100644 --- a/deps/icu-small/source/common/unicode/utext.h +++ b/deps/icu-small/source/common/unicode/utext.h @@ -180,7 +180,7 @@ typedef struct UText UText; /**< C typedef for struct UText. @stable ICU 3.6 */ * * @stable ICU 3.4 */ -U_STABLE UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 utext_close(UText *ut); /** @@ -204,7 +204,7 @@ utext_close(UText *ut); * will always be used and returned. * @stable ICU 3.4 */ -U_STABLE UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status); @@ -222,7 +222,7 @@ utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status); * will always be used and returned. * @stable ICU 3.4 */ -U_STABLE UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status); @@ -239,7 +239,7 @@ utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status); * will always be used and returned. * @stable ICU 3.4 */ -U_STABLE UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 utext_openUnicodeString(UText *ut, icu::UnicodeString *s, UErrorCode *status); @@ -255,7 +255,7 @@ utext_openUnicodeString(UText *ut, icu::UnicodeString *s, UErrorCode *status); * will always be used and returned. * @stable ICU 3.4 */ -U_STABLE UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode *status); @@ -271,7 +271,7 @@ utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode * @see Replaceable * @stable ICU 3.4 */ -U_STABLE UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status); /** @@ -286,7 +286,7 @@ utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status); * @see Replaceable * @stable ICU 3.4 */ -U_STABLE UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *status); #endif @@ -323,7 +323,7 @@ utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *s * shallow clones provide some protection against errors of this type by * disabling text modification via the cloned UText. * - * A shallow clone made with the readOnly parameter == FALSE will preserve the + * A shallow clone made with the readOnly parameter == false will preserve the * utext_isWritable() state of the source object. Note, however, that * write operations must be avoided while more than one UText exists that refer * to the same underlying text. @@ -339,8 +339,8 @@ utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *s * If non-NULL, must refer to an already existing UText, which will then * be reset to become the clone. * @param src The UText to be cloned. - * @param deep TRUE to request a deep clone, FALSE for a shallow clone. - * @param readOnly TRUE to request that the cloned UText have read only access to the + * @param deep true to request a deep clone, false for a shallow clone. + * @param readOnly true to request that the cloned UText have read only access to the * underlying text. * @param status Errors are returned here. For deep clones, U_UNSUPPORTED_ERROR @@ -349,7 +349,7 @@ utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *s * @return The newly created clone, or NULL if the clone operation failed. * @stable ICU 3.4 */ -U_STABLE UText * U_EXPORT2 +U_CAPI UText * U_EXPORT2 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status); @@ -357,14 +357,14 @@ utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCod * Compare two UText objects for equality. * UTexts are equal if they are iterating over the same text, and * have the same iteration position within the text. - * If either or both of the parameters are NULL, the comparison is FALSE. + * If either or both of the parameters are NULL, the comparison is false. * * @param a The first of the two UTexts to compare. * @param b The other UText to be compared. - * @return TRUE if the two UTexts are equal. + * @return true if the two UTexts are equal. * @stable ICU 3.6 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 utext_equals(const UText *a, const UText *b); @@ -385,11 +385,11 @@ utext_equals(const UText *a, const UText *b); * * @stable ICU 3.4 */ -U_STABLE int64_t U_EXPORT2 +U_CAPI int64_t U_EXPORT2 utext_nativeLength(UText *ut); /** - * Return TRUE if calculating the length of the text could be expensive. + * Return true if calculating the length of the text could be expensive. * Finding the length of NUL terminated strings is considered to be expensive. * * Note that the value of this function may change @@ -398,10 +398,10 @@ utext_nativeLength(UText *ut); * be expensive to report it. * * @param ut the text to be accessed. - * @return TRUE if determining the length of the text could be time consuming. + * @return true if determining the length of the text could be time consuming. * @stable ICU 3.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 utext_isLengthExpensive(const UText *ut); /** @@ -429,7 +429,7 @@ utext_isLengthExpensive(const UText *ut); * @return the code point at the specified index. * @stable ICU 3.4 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 utext_char32At(UText *ut, int64_t nativeIndex); @@ -443,7 +443,7 @@ utext_char32At(UText *ut, int64_t nativeIndex); * @return the Unicode code point at the current iterator position. * @stable ICU 3.4 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 utext_current32(UText *ut); @@ -465,7 +465,7 @@ utext_current32(UText *ut); * @see UTEXT_NEXT32 * @stable ICU 3.4 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 utext_next32(UText *ut); @@ -486,7 +486,7 @@ utext_next32(UText *ut); * @see UTEXT_PREVIOUS32 * @stable ICU 3.4 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 utext_previous32(UText *ut); @@ -508,7 +508,7 @@ utext_previous32(UText *ut); * or U_SENTINEL (-1) if it is out of bounds. * @stable ICU 3.4 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 utext_next32From(UText *ut, int64_t nativeIndex); @@ -528,7 +528,7 @@ utext_next32From(UText *ut, int64_t nativeIndex); * * @stable ICU 3.4 */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 utext_previous32From(UText *ut, int64_t nativeIndex); /** @@ -543,7 +543,7 @@ utext_previous32From(UText *ut, int64_t nativeIndex); * @return the current index position, in the native units of the text provider. * @stable ICU 3.4 */ -U_STABLE int64_t U_EXPORT2 +U_CAPI int64_t U_EXPORT2 utext_getNativeIndex(const UText *ut); /** @@ -569,7 +569,7 @@ utext_getNativeIndex(const UText *ut); * @param nativeIndex the native unit index of the new iteration position. * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 utext_setNativeIndex(UText *ut, int64_t nativeIndex); /** @@ -584,11 +584,11 @@ utext_setNativeIndex(UText *ut, int64_t nativeIndex); * * @param ut the text to be accessed. * @param delta the signed number of code points to move the iteration position. - * @return TRUE if the position could be moved the requested number of positions while + * @return true if the position could be moved the requested number of positions while * staying within the range [0 - text length]. * @stable ICU 3.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 utext_moveIndex32(UText *ut, int32_t delta); /** @@ -613,7 +613,7 @@ utext_moveIndex32(UText *ut, int32_t delta); * or zero if the current position is at the start of the text. * @stable ICU 3.6 */ -U_STABLE int64_t U_EXPORT2 +U_CAPI int64_t U_EXPORT2 utext_getPreviousNativeIndex(UText *ut); @@ -651,7 +651,7 @@ utext_getPreviousNativeIndex(UText *ut); * * @stable ICU 3.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 utext_extract(UText *ut, int64_t nativeStart, int64_t nativeLimit, UChar *dest, int32_t destCapacity, @@ -768,16 +768,16 @@ utext_extract(UText *ut, /** - * Return TRUE if the text can be written (modified) with utext_replace() or + * Return true if the text can be written (modified) with utext_replace() or * utext_copy(). For the text to be writable, the text provider must * be of a type that supports writing and the UText must not be frozen. * - * Attempting to modify text when utext_isWriteable() is FALSE will fail - + * Attempting to modify text when utext_isWriteable() is false will fail - * the text will not be modified, and an error will be returned from the function * that attempted the modification. * * @param ut the UText to be tested. - * @return TRUE if the text is modifiable. + * @return true if the text is modifiable. * * @see utext_freeze() * @see utext_replace() @@ -785,7 +785,7 @@ utext_extract(UText *ut, * @stable ICU 3.4 * */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 utext_isWritable(const UText *ut); @@ -794,10 +794,10 @@ utext_isWritable(const UText *ut); * @see Replaceable::hasMetaData() * * @param ut The UText to be tested - * @return TRUE if the underlying text includes meta data. + * @return true if the underlying text includes meta data. * @stable ICU 3.4 */ -U_STABLE UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 utext_hasMetaData(const UText *ut); @@ -808,7 +808,7 @@ utext_hasMetaData(const UText *ut); * newly inserted replacement text. * * This function is only available on UText types that support writing, - * that is, ones where utext_isWritable() returns TRUE. + * that is, ones where utext_isWritable() returns true. * * When using this function, there should be only a single UText opened onto the * underlying native text string. Behavior after a replace operation @@ -828,7 +828,7 @@ utext_hasMetaData(const UText *ut); * * @stable ICU 3.4 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 utext_replace(UText *ut, int64_t nativeStart, int64_t nativeLimit, const UChar *replacementText, int32_t replacementLength, @@ -850,7 +850,7 @@ utext_replace(UText *ut, * at the destination position. * * This function is only available on UText types that support writing, - * that is, ones where utext_isWritable() returns TRUE. + * that is, ones where utext_isWritable() returns true. * * When using this function, there should be only a single UText opened onto the * underlying native text string. Behavior after a copy operation @@ -863,12 +863,12 @@ utext_replace(UText *ut, * to be copied. * @param destIndex The native destination index to which the source substring is * copied or moved. - * @param move If TRUE, then the substring is moved, not copied/duplicated. + * @param move If true, then the substring is moved, not copied/duplicated. * @param status receives any error status. Possible errors include U_NO_WRITE_PERMISSION * * @stable ICU 3.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 utext_copy(UText *ut, int64_t nativeStart, int64_t nativeLimit, int64_t destIndex, @@ -897,7 +897,7 @@ utext_copy(UText *ut, * @see utext_isWritable() * @stable ICU 3.6 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 utext_freeze(UText *ut); @@ -972,7 +972,7 @@ enum { * @param dest A UText struct to be filled in with the result of the clone operation, * or NULL if the clone function should heap-allocate a new UText struct. * @param src The UText to be cloned. - * @param deep TRUE to request a deep clone, FALSE for a shallow clone. + * @param deep true to request a deep clone, false for a shallow clone. * @param status Errors are returned here. For deep clones, U_UNSUPPORTED_ERROR * should be returned if the text provider is unable to clone the * original text. @@ -1008,9 +1008,9 @@ UTextNativeLength(UText *ut); * * @param ut the UText being accessed. * @param nativeIndex Requested index of the text to be accessed. - * @param forward If TRUE, then the returned chunk must contain text + * @param forward If true, then the returned chunk must contain text * starting from the index, so that start<=indexUsage: * ICU coding guidelines for if() statements should be followed when using these macros. @@ -124,7 +124,7 @@ /** * Is this code point a Unicode noncharacter? * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U_IS_UNICODE_NONCHAR(c) \ @@ -145,7 +145,7 @@ * and that boundary is tested first for performance. * * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U_IS_UNICODE_CHAR(c) \ @@ -155,7 +155,7 @@ /** * Is this code point a BMP code point (U+0000..U+ffff)? * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.8 */ #define U_IS_BMP(c) ((uint32_t)(c)<=0xffff) @@ -163,7 +163,7 @@ /** * Is this code point a supplementary code point (U+10000..U+10ffff)? * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.8 */ #define U_IS_SUPPLEMENTARY(c) ((uint32_t)((c)-0x10000)<=0xfffff) @@ -171,7 +171,7 @@ /** * Is this code point a lead surrogate (U+d800..U+dbff)? * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U_IS_LEAD(c) (((c)&0xfffffc00)==0xd800) @@ -179,7 +179,7 @@ /** * Is this code point a trail surrogate (U+dc00..U+dfff)? * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00) @@ -187,7 +187,7 @@ /** * Is this code point a surrogate (U+d800..U+dfff)? * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800) @@ -196,7 +196,7 @@ * Assuming c is a surrogate code point (U_IS_SURROGATE(c)), * is it a lead surrogate? * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) @@ -205,7 +205,7 @@ * Assuming c is a surrogate code point (U_IS_SURROGATE(c)), * is it a trail surrogate? * @param c 32-bit code point - * @return TRUE or FALSE + * @return true or false * @stable ICU 4.2 */ #define U_IS_SURROGATE_TRAIL(c) (((c)&0x400)!=0) diff --git a/deps/icu-small/source/common/unicode/utf16.h b/deps/icu-small/source/common/unicode/utf16.h index 3315214ae69d86..9d68902d2de0f3 100644 --- a/deps/icu-small/source/common/unicode/utf16.h +++ b/deps/icu-small/source/common/unicode/utf16.h @@ -23,7 +23,7 @@ * This file defines macros to deal with 16-bit Unicode (UTF-16) code units and strings. * * For more information see utf.h and the ICU User Guide Strings chapter - * (http://userguide.icu-project.org/strings). + * (https://unicode-org.github.io/icu/userguide/strings). * * Usage: * ICU coding guidelines for if() statements should be followed when using these macros. @@ -34,6 +34,7 @@ #ifndef __UTF16_H__ #define __UTF16_H__ +#include #include "unicode/umachine.h" #ifndef __UTF_H__ # include "unicode/utf.h" @@ -44,7 +45,7 @@ /** * Does this code unit alone encode a code point (BMP, not a surrogate)? * @param c 16-bit code unit - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U16_IS_SINGLE(c) !U_IS_SURROGATE(c) @@ -52,7 +53,7 @@ /** * Is this code unit a lead surrogate (U+d800..U+dbff)? * @param c 16-bit code unit - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800) @@ -60,7 +61,7 @@ /** * Is this code unit a trail surrogate (U+dc00..U+dfff)? * @param c 16-bit code unit - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00) @@ -68,7 +69,7 @@ /** * Is this code unit a surrogate (U+d800..U+dfff)? * @param c 16-bit code unit - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U16_IS_SURROGATE(c) U_IS_SURROGATE(c) @@ -77,7 +78,7 @@ * Assuming c is a surrogate code point (U16_IS_SURROGATE(c)), * is it a lead surrogate? * @param c 16-bit code unit - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) @@ -86,7 +87,7 @@ * Assuming c is a surrogate code point (U16_IS_SURROGATE(c)), * is it a trail surrogate? * @param c 16-bit code unit - * @return TRUE or FALSE + * @return true or false * @stable ICU 4.2 */ #define U16_IS_SURROGATE_TRAIL(c) (((c)&0x400)!=0) @@ -379,13 +380,13 @@ * "Safe" macro, checks for a valid code point. * If a surrogate pair is written, checks for sufficient space in the string. * If the code point is not valid or a trail surrogate does not fit, - * then isError is set to TRUE. + * then isError is set to true. * * @param s const UChar * string buffer * @param i string offset, must be i>10)+0xd7c0); \ (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ } else /* c>0x10ffff or not enough space */ { \ - (isError)=TRUE; \ + (isError)=true; \ } \ } UPRV_BLOCK_MACRO_END diff --git a/deps/icu-small/source/common/unicode/utf8.h b/deps/icu-small/source/common/unicode/utf8.h index bb001303747efe..58bda2cbe51290 100644 --- a/deps/icu-small/source/common/unicode/utf8.h +++ b/deps/icu-small/source/common/unicode/utf8.h @@ -23,7 +23,7 @@ * This file defines macros to deal with 8-bit Unicode (UTF-8) code units (bytes) and strings. * * For more information see utf.h and the ICU User Guide Strings chapter - * (http://userguide.icu-project.org/strings). + * (https://unicode-org.github.io/icu/userguide/strings). * * Usage: * ICU coding guidelines for if() statements should be followed when using these macros. @@ -34,6 +34,7 @@ #ifndef __UTF8_H__ #define __UTF8_H__ +#include #include "unicode/umachine.h" #ifndef __UTF_H__ # include "unicode/utf.h" @@ -117,48 +118,48 @@ * Function for handling "next code point" with error-checking. * * This is internal since it is not meant to be called directly by external clients; - * however it is U_STABLE (not U_INTERNAL) since it is called by public macros in this + * however it is called by public macros in this * file and thus must remain stable, and should not be hidden when other internal * functions are hidden (otherwise public macros would fail to compile). * @internal */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 utf8_nextCharSafeBody(const uint8_t *s, int32_t *pi, int32_t length, UChar32 c, UBool strict); /** * Function for handling "append code point" with error-checking. * * This is internal since it is not meant to be called directly by external clients; - * however it is U_STABLE (not U_INTERNAL) since it is called by public macros in this + * however it is called by public macros in this * file and thus must remain stable, and should not be hidden when other internal * functions are hidden (otherwise public macros would fail to compile). * @internal */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 utf8_appendCharSafeBody(uint8_t *s, int32_t i, int32_t length, UChar32 c, UBool *pIsError); /** * Function for handling "previous code point" with error-checking. * * This is internal since it is not meant to be called directly by external clients; - * however it is U_STABLE (not U_INTERNAL) since it is called by public macros in this + * however it is called by public macros in this * file and thus must remain stable, and should not be hidden when other internal * functions are hidden (otherwise public macros would fail to compile). * @internal */ -U_STABLE UChar32 U_EXPORT2 +U_CAPI UChar32 U_EXPORT2 utf8_prevCharSafeBody(const uint8_t *s, int32_t start, int32_t *pi, UChar32 c, UBool strict); /** * Function for handling "skip backward one code point" with error-checking. * * This is internal since it is not meant to be called directly by external clients; - * however it is U_STABLE (not U_INTERNAL) since it is called by public macros in this + * however it is called by public macros in this * file and thus must remain stable, and should not be hidden when other internal * functions are hidden (otherwise public macros would fail to compile). * @internal */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i); /* single-code point definitions -------------------------------------------- */ @@ -166,7 +167,7 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i); /** * Does this code unit (byte) encode a code point by itself (US-ASCII 0..0x7f)? * @param c 8-bit code unit (byte) - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U8_IS_SINGLE(c) (((c)&0x80)==0) @@ -174,7 +175,7 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i); /** * Is this code unit (byte) a UTF-8 lead byte? (0xC2..0xF4) * @param c 8-bit code unit (byte) - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U8_IS_LEAD(c) ((uint8_t)((c)-0xc2)<=0x32) @@ -183,7 +184,7 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i); /** * Is this code unit (byte) a UTF-8 trail byte? (0x80..0xBF) * @param c 8-bit code unit (byte) - * @return TRUE or FALSE + * @return true or false * @stable ICU 2.4 */ #define U8_IS_TRAIL(c) ((int8_t)(c)<-0x40) @@ -445,13 +446,13 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i); * "Safe" macro, checks for a valid code point. * If a non-ASCII code point is written, checks for sufficient space in the string. * If the code point is not valid or trail bytes do not fit, - * then isError is set to TRUE. + * then isError is set to true. * * @param s const uint8_t * string buffer * @param i int32_t string offset, must be i>6)&0x3f)|0x80); \ (s)[(i)++]=(uint8_t)((__uc&0x3f)|0x80); \ } else { \ - (isError)=TRUE; \ + (isError)=true; \ } \ } UPRV_BLOCK_MACRO_END diff --git a/deps/icu-small/source/common/unicode/utf_old.h b/deps/icu-small/source/common/unicode/utf_old.h index b2428e6b31e282..160f5ad0a9f248 100644 --- a/deps/icu-small/source/common/unicode/utf_old.h +++ b/deps/icu-small/source/common/unicode/utf_old.h @@ -109,7 +109,7 @@ * Where such a distinction is useful, there are two versions of the macros, "unsafe" and "safe" * ones with ..._UNSAFE and ..._SAFE suffixes. The unsafe macros are fast but may cause * program failures if the strings are not well-formed. The safe macros have an additional, boolean - * parameter "strict". If strict is FALSE, then only illegal sequences are detected. + * parameter "strict". If strict is false, then only illegal sequences are detected. * Otherwise, irregular sequences and non-characters are detected as well (like single surrogates). * Safe macros return special error code points for illegal/irregular sequences: * Typically, U+ffff, or values that would result in a code unit sequence of the same length @@ -181,7 +181,7 @@ typedef int32_t UTextOffset; /** * The default choice for general Unicode string macros is to use the ..._SAFE macro implementations - * with strict=FALSE. + * with strict=false. * * @deprecated ICU 2.4. Obsolete, see utf_old.h. */ diff --git a/deps/icu-small/source/common/unicode/utrace.h b/deps/icu-small/source/common/unicode/utrace.h index c7d51ff44f5bf7..bb8e3e8109cc66 100644 --- a/deps/icu-small/source/common/unicode/utrace.h +++ b/deps/icu-small/source/common/unicode/utrace.h @@ -112,11 +112,9 @@ typedef enum UTraceFunctionNumber { UTRACE_COLLATION_LIMIT, #endif // U_HIDE_DEPRECATED_API -#ifndef U_HIDE_DRAFT_API - /** * The lowest resource/data location. - * @draft ICU 65 + * @stable ICU 65 */ UTRACE_UDATA_START=0x3000, @@ -133,7 +131,7 @@ typedef enum UTraceFunctionNumber { * - "get" (a path was loaded, but the value was not accessed) * - "getalias" (a path was loaded, and an alias was resolved) * - * @draft ICU 65 + * @stable ICU 65 */ UTRACE_UDATA_RESOURCE=UTRACE_UDATA_START, @@ -141,7 +139,7 @@ typedef enum UTraceFunctionNumber { * Indicates that a resource bundle was opened. * * Provides one C-style string to UTraceData: file name. - * @draft ICU 65 + * @stable ICU 65 */ UTRACE_UDATA_BUNDLE, @@ -150,7 +148,7 @@ typedef enum UTraceFunctionNumber { * * Provides one C-style string to UTraceData: file name. * - * @draft ICU 65 + * @stable ICU 65 */ UTRACE_UDATA_DATA_FILE, @@ -163,12 +161,10 @@ typedef enum UTraceFunctionNumber { * * Provides one C-style string to UTraceData: file name. * - * @draft ICU 65 + * @stable ICU 65 */ UTRACE_UDATA_RES_FILE, -#endif // U_HIDE_DRAFT_API - #ifndef U_HIDE_INTERNAL_API /** * One more than the highest normal resource/data trace location. @@ -249,7 +245,7 @@ typedef enum UTraceFunctionNumber { * @param traceLevel A UTraceLevel value. * @stable ICU 2.8 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 utrace_setLevel(int32_t traceLevel); /** @@ -257,7 +253,7 @@ utrace_setLevel(int32_t traceLevel); * @return The UTraceLevel value being used by ICU. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 utrace_getLevel(void); /* Trace function pointers types ----------------------------- */ @@ -331,7 +327,7 @@ UTraceData(const void *context, int32_t fnNumber, int32_t level, * * @stable ICU 2.8 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 utrace_setFunctions(const void *context, UTraceEntry *e, UTraceExit *x, UTraceData *d); @@ -345,7 +341,7 @@ utrace_setFunctions(const void *context, * @param d The currently installed UTraceData function. * @stable ICU 2.8 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 utrace_getFunctions(const void **context, UTraceEntry **e, UTraceExit **x, UTraceData **d); @@ -467,7 +463,7 @@ utrace_getFunctions(const void **context, * If buffer capacity is insufficient, the required capacity is returned. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 utrace_vformat(char *outBuf, int32_t capacity, int32_t indent, const char *fmt, va_list args); @@ -488,7 +484,7 @@ utrace_vformat(char *outBuf, int32_t capacity, * If buffer capacity is insufficient, the required capacity is returned. * @stable ICU 2.8 */ -U_STABLE int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 utrace_format(char *outBuf, int32_t capacity, int32_t indent, const char *fmt, ...); @@ -505,7 +501,7 @@ utrace_format(char *outBuf, int32_t capacity, * @see UTraceFunctionNumber * @stable ICU 2.8 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 utrace_functionName(int32_t fnNumber); U_CDECL_END diff --git a/deps/icu-small/source/common/unicode/utypes.h b/deps/icu-small/source/common/unicode/utypes.h index c98de9e6fc3dad..6c57218db8d477 100644 --- a/deps/icu-small/source/common/unicode/utypes.h +++ b/deps/icu-small/source/common/unicode/utypes.h @@ -479,13 +479,23 @@ typedef enum UErrorCode { U_COLLATOR_VERSION_MISMATCH = 28, /**< Collator version is not compatible with the base version */ U_USELESS_COLLATOR_ERROR = 29, /**< Collator is options only and no base is specified */ U_NO_WRITE_PERMISSION = 30, /**< Attempt to modify read-only or constant data. */ +#ifndef U_HIDE_DRAFT_API + /** + * The input is impractically long for an operation. + * It is rejected because it may lead to problems such as excessive + * processing time, stack depth, or heap memory requirements. + * + * @draft ICU 68 + */ + U_INPUT_TOO_LONG_ERROR = 31, +#endif // U_HIDE_DRAFT_API #ifndef U_HIDE_DEPRECATED_API /** * One more than the highest standard error code. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. */ - U_STANDARD_ERROR_LIMIT, + U_STANDARD_ERROR_LIMIT = 32, #endif // U_HIDE_DEPRECATED_API /* @@ -715,7 +725,7 @@ typedef enum UErrorCode { * in the UErrorCode enum above. * @stable ICU 2.0 */ -U_STABLE const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 u_errorName(UErrorCode code); diff --git a/deps/icu-small/source/common/unicode/uvernum.h b/deps/icu-small/source/common/unicode/uvernum.h index c66776d10b5826..a4cbb9e0fe8661 100644 --- a/deps/icu-small/source/common/unicode/uvernum.h +++ b/deps/icu-small/source/common/unicode/uvernum.h @@ -60,7 +60,7 @@ * This value will change in the subsequent releases of ICU * @stable ICU 2.4 */ -#define U_ICU_VERSION_MAJOR_NUM 67 +#define U_ICU_VERSION_MAJOR_NUM 68 /** The current ICU minor version as an integer. * This value will change in the subsequent releases of ICU @@ -86,7 +86,7 @@ * This value will change in the subsequent releases of ICU * @stable ICU 2.6 */ -#define U_ICU_VERSION_SUFFIX _67 +#define U_ICU_VERSION_SUFFIX _68 /** * \def U_DEF2_ICU_ENTRY_POINT_RENAME @@ -139,7 +139,7 @@ * This value will change in the subsequent releases of ICU * @stable ICU 2.4 */ -#define U_ICU_VERSION "67.1" +#define U_ICU_VERSION "68.1" /** * The current ICU library major version number as a string, for library name suffixes. @@ -148,17 +148,17 @@ * Until ICU 4.8, this was the combination of the single-digit major and minor ICU version numbers * into one string without dots ("48"). * Since ICU 49, it is the double-digit major ICU version number. - * See http://userguide.icu-project.org/design#TOC-Version-Numbers-in-ICU + * See https://unicode-org.github.io/icu/userguide/design#version-numbers-in-icu * * @stable ICU 2.6 */ -#define U_ICU_VERSION_SHORT "67" +#define U_ICU_VERSION_SHORT "68" #ifndef U_HIDE_INTERNAL_API /** Data version in ICU4C. * @internal ICU 4.4 Internal Use Only **/ -#define U_ICU_DATA_VERSION "67.1" +#define U_ICU_DATA_VERSION "68.1" #endif /* U_HIDE_INTERNAL_API */ /*=========================================================================== diff --git a/deps/icu-small/source/common/unicode/uversion.h b/deps/icu-small/source/common/unicode/uversion.h index c8c7a374c820b2..dde3059261047c 100644 --- a/deps/icu-small/source/common/unicode/uversion.h +++ b/deps/icu-small/source/common/unicode/uversion.h @@ -141,7 +141,7 @@ typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH]; * values of up to 255 each. * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_versionFromString(UVersionInfo versionArray, const char *versionString); /** @@ -155,7 +155,7 @@ u_versionFromString(UVersionInfo versionArray, const char *versionString); * fields with values of up to 255 each. * @stable ICU 4.2 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_versionFromUString(UVersionInfo versionArray, const UChar *versionString); @@ -171,7 +171,7 @@ u_versionFromUString(UVersionInfo versionArray, const UChar *versionString); * The buffer size must be at least U_MAX_VERSION_STRING_LENGTH. * @stable ICU 2.4 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_versionToString(const UVersionInfo versionArray, char *versionString); /** @@ -182,6 +182,6 @@ u_versionToString(const UVersionInfo versionArray, char *versionString); * @param versionArray the version # information, the result will be filled in * @stable ICU 2.0 */ -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 u_getVersion(UVersionInfo versionArray); #endif diff --git a/deps/icu-small/source/common/unifiedcache.cpp b/deps/icu-small/source/common/unifiedcache.cpp index f2dd916559588c..493ab79f6d9067 100644 --- a/deps/icu-small/source/common/unifiedcache.cpp +++ b/deps/icu-small/source/common/unifiedcache.cpp @@ -311,7 +311,7 @@ void UnifiedCache::_putNew( } keyToAdopt->fCreationStatus = creationStatus; if (value->softRefCount == 0) { - _registerMaster(keyToAdopt, value); + _registerPrimary(keyToAdopt, value); } void *oldValue = uhash_put(fHashtable, keyToAdopt, (void *) value, &status); U_ASSERT(oldValue == nullptr); @@ -338,7 +338,7 @@ void UnifiedCache::_putIfAbsentAndGet( } else { _put(element, value, status); } - // Run an eviction slice. This will run even if we added a master entry + // Run an eviction slice. This will run even if we added a primary entry // which doesn't increase the unused count, but that is still o.k _runEvictionSlice(); } @@ -403,9 +403,9 @@ void UnifiedCache::_get( } } -void UnifiedCache::_registerMaster( +void UnifiedCache::_registerPrimary( const CacheKeyBase *theKey, const SharedObject *value) const { - theKey->fIsMaster = true; + theKey->fIsPrimary = true; value->cachePtr = this; ++fNumValuesTotal; ++fNumValuesInUse; @@ -420,7 +420,7 @@ void UnifiedCache::_put( const SharedObject *oldValue = (const SharedObject *) element->value.pointer; theKey->fCreationStatus = status; if (value->softRefCount == 0) { - _registerMaster(theKey, value); + _registerPrimary(theKey, value); } value->softRefCount++; UHashElement *ptr = const_cast(element); @@ -474,9 +474,9 @@ UBool UnifiedCache::_isEvictable(const UHashElement *element) const return FALSE; } - // We can evict entries that are either not a master or have just + // We can evict entries that are either not a primary or have just // one reference (The one reference being from the cache itself). - return (!theKey->fIsMaster || (theValue->softRefCount == 1 && theValue->noHardReferences())); + return (!theKey->fIsPrimary || (theValue->softRefCount == 1 && theValue->noHardReferences())); } void UnifiedCache::removeSoftRef(const SharedObject *value) const { diff --git a/deps/icu-small/source/common/unifiedcache.h b/deps/icu-small/source/common/unifiedcache.h index 5c0bd76f4a2b94..865f4545105cb6 100644 --- a/deps/icu-small/source/common/unifiedcache.h +++ b/deps/icu-small/source/common/unifiedcache.h @@ -34,13 +34,13 @@ class UnifiedCache; */ class U_COMMON_API CacheKeyBase : public UObject { public: - CacheKeyBase() : fCreationStatus(U_ZERO_ERROR), fIsMaster(FALSE) {} + CacheKeyBase() : fCreationStatus(U_ZERO_ERROR), fIsPrimary(false) {} /** * Copy constructor. Needed to support cloning. */ CacheKeyBase(const CacheKeyBase &other) - : UObject(other), fCreationStatus(other.fCreationStatus), fIsMaster(FALSE) { } + : UObject(other), fCreationStatus(other.fCreationStatus), fIsPrimary(false) { } virtual ~CacheKeyBase(); /** @@ -88,7 +88,7 @@ class U_COMMON_API CacheKeyBase : public UObject { } private: mutable UErrorCode fCreationStatus; - mutable UBool fIsMaster; + mutable UBool fIsPrimary; friend class UnifiedCache; }; @@ -147,10 +147,10 @@ class LocaleCacheKey : public CacheKey { virtual UBool operator == (const CacheKeyBase &other) const { // reflexive if (this == &other) { - return TRUE; + return true; } if (!CacheKey::operator == (other)) { - return FALSE; + return false; } // We know this and other are of same class because operator== on // CacheKey returned true. @@ -359,7 +359,7 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase { /** * Flushes the contents of the cache. If cache values hold references to other - * cache values then _flush should be called in a loop until it returns FALSE. + * cache values then _flush should be called in a loop until it returns false. * * On entry, gCacheMutex must be held. * On exit, those values with are evictable are flushed. @@ -370,7 +370,7 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase { * hard (external) references are not deleted, but are detached from * the cache, so that a subsequent removeRefs can delete them. * _flush is not thread safe when all is true. - * @return TRUE if any value in cache was flushed or FALSE otherwise. + * @return true if any value in cache was flushed or false otherwise. */ UBool _flush(UBool all) const; @@ -395,11 +395,11 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase { * Attempts to fetch value and status for key from cache. * On entry, gCacheMutex must not be held value must be NULL and status must * be U_ZERO_ERROR. - * On exit, either returns FALSE (In this - * case caller should try to create the object) or returns TRUE with value + * On exit, either returns false (In this + * case caller should try to create the object) or returns true with value * pointing to the fetched value and status set to fetched status. When - * FALSE is returned status may be set to failure if an in progress hash - * entry could not be made but value will remain unchanged. When TRUE is + * false is returned status may be set to failure if an in progress hash + * entry could not be made but value will remain unchanged. When true is * returned, caller must call removeRef() on value. */ UBool _poll( @@ -463,17 +463,17 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase { void _runEvictionSlice() const; /** - * Register a master cache entry. A master key is the first key to create + * Register a primary cache entry. A primary key is the first key to create * a given SharedObject value. Subsequent keys whose create function - * produce referneces to an already existing SharedObject are not masters - + * produce referneces to an already existing SharedObject are not primary - * they can be evicted and subsequently recreated. * * On entry, gCacheMutex must be held. - * On exit, items in use count incremented, entry is marked as a master + * On exit, items in use count incremented, entry is marked as a primary * entry, and value registered with cache so that subsequent calls to * addRef() and removeRef() on it correctly interact with the cache. */ - void _registerMaster(const CacheKeyBase *theKey, const SharedObject *value) const; + void _registerPrimary(const CacheKeyBase *theKey, const SharedObject *value) const; /** * Store a value and creation error status in given hash entry. diff --git a/deps/icu-small/source/common/uniquecharstr.h b/deps/icu-small/source/common/uniquecharstr.h new file mode 100644 index 00000000000000..10cc924f7f9eb2 --- /dev/null +++ b/deps/icu-small/source/common/uniquecharstr.h @@ -0,0 +1,98 @@ +// © 2020 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +// uniquecharstr.h +// created: 2020sep01 Frank Yung-Fong Tang + +#ifndef __UNIQUECHARSTR_H__ +#define __UNIQUECHARSTR_H__ + +#include "charstr.h" +#include "uassert.h" +#include "uhash.h" + +U_NAMESPACE_BEGIN + +/** + * Stores NUL-terminated strings with duplicate elimination. + * Checks for unique UTF-16 string pointers and converts to invariant characters. + * + * Intended to be stack-allocated. Add strings, get a unique number for each, + * freeze the object, get a char * pointer for each string, + * call orphanCharStrings() to capture the string storage, and let this object go out of scope. + */ +class UniqueCharStrings { +public: + UniqueCharStrings(UErrorCode &errorCode) : strings(nullptr) { + // Note: We hash on string contents but store stable char16_t * pointers. + // If the strings are stored in resource bundles which should be built with + // duplicate elimination, then we should be able to hash on just the pointer values. + uhash_init(&map, uhash_hashUChars, uhash_compareUChars, uhash_compareLong, &errorCode); + if (U_FAILURE(errorCode)) { return; } + strings = new CharString(); + if (strings == nullptr) { + errorCode = U_MEMORY_ALLOCATION_ERROR; + } + } + ~UniqueCharStrings() { + uhash_close(&map); + delete strings; + } + + /** Returns/orphans the CharString that contains all strings. */ + CharString *orphanCharStrings() { + CharString *result = strings; + strings = nullptr; + return result; + } + + /** + * Adds a string and returns a unique number for it. + * The string's buffer contents must not change, nor move around in memory, + * while this UniqueCharStrings is in use. + * The string contents must be NUL-terminated exactly at s.length(). + * + * Best used with read-only-alias UnicodeString objects that point to + * stable storage, such as strings returned by resource bundle functions. + */ + int32_t add(const UnicodeString &s, UErrorCode &errorCode) { + if (U_FAILURE(errorCode)) { return 0; } + if (isFrozen) { + errorCode = U_NO_WRITE_PERMISSION; + return 0; + } + // The string points into the resource bundle. + const char16_t *p = s.getBuffer(); + int32_t oldIndex = uhash_geti(&map, p); + if (oldIndex != 0) { // found duplicate + return oldIndex; + } + // Explicit NUL terminator for the previous string. + // The strings object is also terminated with one implicit NUL. + strings->append(0, errorCode); + int32_t newIndex = strings->length(); + strings->appendInvariantChars(s, errorCode); + uhash_puti(&map, const_cast(p), newIndex, &errorCode); + return newIndex; + } + + void freeze() { isFrozen = true; } + + /** + * Returns a string pointer for its unique number, if this object is frozen. + * Otherwise nullptr. + */ + const char *get(int32_t i) const { + U_ASSERT(isFrozen); + return isFrozen && i > 0 ? strings->data() + i : nullptr; + } + +private: + UHashtable map; + CharString *strings; + bool isFrozen = false; +}; + +U_NAMESPACE_END + +#endif // __UNIQUECHARSTR_H__ diff --git a/deps/icu-small/source/common/unisetspan.h b/deps/icu-small/source/common/unisetspan.h index f1e78ff3ee2b00..9a1307a9078aab 100644 --- a/deps/icu-small/source/common/unisetspan.h +++ b/deps/icu-small/source/common/unisetspan.h @@ -65,8 +65,8 @@ class UnicodeSetStringSpan : public UMemory { /* * Do the strings need to be checked in span() etc.? - * @return TRUE if strings need to be checked (call span() here), - * FALSE if not (use a BMPSet for best performance). + * @return true if strings need to be checked (call span() here), + * false if not (use a BMPSet for best performance). */ inline UBool needsStringSpanUTF16(); inline UBool needsStringSpanUTF8(); diff --git a/deps/icu-small/source/common/unormimp.h b/deps/icu-small/source/common/unormimp.h index 7f280551f7ef8e..e09c5c1c916773 100644 --- a/deps/icu-small/source/common/unormimp.h +++ b/deps/icu-small/source/common/unormimp.h @@ -418,7 +418,7 @@ enum { * The same bit is used for NFC and NFKC; (c) differs for them. * As usual, we build the "not skippable" flags so that unassigned * code points get a 0 bit. - * This bit is only valid after (a)..(e) test FALSE; test NFD_NO before (f) as well. + * This bit is only valid after (a)..(e) test false; test NFD_NO before (f) as well. * Test Hangul LV syllables entirely in code. * * diff --git a/deps/icu-small/source/common/uresbund.cpp b/deps/icu-small/source/common/uresbund.cpp index f4efb8ccab5a0b..743df1f8c505ce 100644 --- a/deps/icu-small/source/common/uresbund.cpp +++ b/deps/icu-small/source/common/uresbund.cpp @@ -1792,7 +1792,7 @@ ures_findSubResource(const UResourceBundle *resB, char* path, UResourceBundle *f return result; } -U_INTERNAL const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ures_getStringByKeyWithFallback(const UResourceBundle *resB, const char* inKey, int32_t* len, @@ -2210,7 +2210,7 @@ ures_getUTF8StringByKey(const UResourceBundle *resB, * INTERNAL: Get the name of the first real locale (not placeholder) * that has resource bundle data. */ -U_INTERNAL const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 ures_getLocaleInternal(const UResourceBundle* resourceBundle, UErrorCode* status) { if (status==NULL || U_FAILURE(*status)) { @@ -2357,7 +2357,7 @@ ures_openDirect(const char* path, const char* localeID, UErrorCode* status) { * * Same as ures_open(), but uses the fill-in parameter and does not allocate a new bundle. */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 ures_openFillIn(UResourceBundle *r, const char* path, const char* localeID, UErrorCode* status) { if(U_SUCCESS(*status) && r == NULL) { @@ -2370,7 +2370,7 @@ ures_openFillIn(UResourceBundle *r, const char* path, /** * Same as ures_openDirect(), but uses the fill-in parameter and does not allocate a new bundle. */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 ures_openDirectFillIn(UResourceBundle *r, const char* path, const char* localeID, UErrorCode* status) { if(U_SUCCESS(*status) && r == NULL) { *status = U_ILLEGAL_ARGUMENT_ERROR; @@ -2420,7 +2420,7 @@ ures_countArrayItems(const UResourceBundle* resourceBundle, * @see ures_getVersion * @internal */ -U_INTERNAL const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 ures_getVersionNumberInternal(const UResourceBundle *resourceBundle) { if (!resourceBundle) return NULL; @@ -3016,7 +3016,7 @@ ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status) } #if 0 /* This code isn't needed, and given the documentation warnings the implementation is suspect */ -U_INTERNAL UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ures_equal(const UResourceBundle* res1, const UResourceBundle* res2){ if(res1==NULL || res2==NULL){ return res1==res2; /* pointer comparision */ @@ -3052,7 +3052,7 @@ ures_equal(const UResourceBundle* res1, const UResourceBundle* res2){ } return TRUE; } -U_INTERNAL UResourceBundle* U_EXPORT2 +U_CAPI UResourceBundle* U_EXPORT2 ures_clone(const UResourceBundle* res, UErrorCode* status){ UResourceBundle* bundle = NULL; UResourceBundle* ret = NULL; @@ -3068,7 +3068,7 @@ ures_clone(const UResourceBundle* res, UErrorCode* status){ } return ret; } -U_INTERNAL const UResourceBundle* U_EXPORT2 +U_CAPI const UResourceBundle* U_EXPORT2 ures_getParentBundle(const UResourceBundle* res){ if(res==NULL){ return NULL; @@ -3077,7 +3077,7 @@ ures_getParentBundle(const UResourceBundle* res){ } #endif -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 ures_getVersionByKey(const UResourceBundle* res, const char *key, UVersionInfo ver, UErrorCode *status) { const UChar *str; int32_t len; diff --git a/deps/icu-small/source/common/uresdata.cpp b/deps/icu-small/source/common/uresdata.cpp index 1bb938be62c35b..4e3309f497522c 100644 --- a/deps/icu-small/source/common/uresdata.cpp +++ b/deps/icu-small/source/common/uresdata.cpp @@ -963,7 +963,7 @@ res_findResource(const ResourceData *pResData, Resource r, char** path, const ch if(t2 == RES_BOGUS) { /* if we fail to get the resource by key, maybe we got an index */ indexR = uprv_strtol(pathP, &closeIndex, 10); - if(indexR >= 0 && *closeIndex == 0) { + if(indexR >= 0 && *closeIndex == 0 && (*pathP != '0' || closeIndex - pathP == 1)) { /* if we indeed have an index, try to get the item by index */ t2 = res_getTableItemByIndex(pResData, t1, indexR, key); } // else t2 is already RES_BOGUS diff --git a/deps/icu-small/source/common/uresdata.h b/deps/icu-small/source/common/uresdata.h index d1b67babf29049..7c2152e57b500d 100644 --- a/deps/icu-small/source/common/uresdata.h +++ b/deps/icu-small/source/common/uresdata.h @@ -402,7 +402,7 @@ typedef struct ResourceData { /* * Read a resource bundle from memory. */ -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 res_read(ResourceData *pResData, const UDataInfo *pInfo, const void *inBytes, int32_t length, UErrorCode *errorCode); @@ -422,7 +422,7 @@ res_load(ResourceData *pResData, U_CFUNC void res_unload(ResourceData *pResData); -U_INTERNAL UResType U_EXPORT2 +U_CAPI UResType U_EXPORT2 res_getPublicType(Resource res); /////////////////////////////////////////////////////////////////////////// @@ -434,31 +434,31 @@ res_getPublicType(Resource res); * and set its length in *pLength. * Returns NULL if not found. */ -U_INTERNAL const UChar * U_EXPORT2 +U_CAPI const UChar * U_EXPORT2 res_getStringNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength); -U_INTERNAL const uint8_t * U_EXPORT2 +U_CAPI const uint8_t * U_EXPORT2 res_getBinaryNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength); -U_INTERNAL const int32_t * U_EXPORT2 +U_CAPI const int32_t * U_EXPORT2 res_getIntVectorNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength); -U_INTERNAL const UChar * U_EXPORT2 +U_CAPI const UChar * U_EXPORT2 res_getAlias(const ResourceData *pResData, Resource res, int32_t *pLength); -U_INTERNAL Resource U_EXPORT2 +U_CAPI Resource U_EXPORT2 res_getResource(const ResourceData *pResData, const char *key); -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 res_countArrayItems(const ResourceData *pResData, Resource res); -U_INTERNAL Resource U_EXPORT2 +U_CAPI Resource U_EXPORT2 res_getArrayItem(const ResourceData *pResData, Resource array, int32_t indexS); -U_INTERNAL Resource U_EXPORT2 +U_CAPI Resource U_EXPORT2 res_getTableItemByIndex(const ResourceData *pResData, Resource table, int32_t indexS, const char ** key); -U_INTERNAL Resource U_EXPORT2 +U_CAPI Resource U_EXPORT2 res_getTableItemByKey(const ResourceData *pResData, Resource table, int32_t *indexS, const char* * key); /** diff --git a/deps/icu-small/source/common/uresimp.h b/deps/icu-small/source/common/uresimp.h index 2e477dfad3e98f..12154dcb7c68d4 100644 --- a/deps/icu-small/source/common/uresimp.h +++ b/deps/icu-small/source/common/uresimp.h @@ -157,7 +157,7 @@ U_CFUNC const char* ures_getName(const UResourceBundle* resB); U_CFUNC const char* ures_getPath(const UResourceBundle* resB); /** * If anything was in the RB cache, dump it to the screen. - * @return TRUE if there was anything into the cache + * @return true if there was anything into the cache */ U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void); #endif @@ -218,7 +218,7 @@ ures_findSubResource(const UResourceBundle *resB, * @param isAvailable If non-null, pointer to fillin parameter that indicates whether the * requested locale was available. The locale is defined as 'available' if it physically * exists within the specified tree. - * @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE' + * @param omitDefault if true, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE' * @param status error code * @return the actual buffer size needed for the full locale. If it's greater * than resultCapacity, the returned full name will be truncated and an error code will be returned. diff --git a/deps/icu-small/source/common/ustr_imp.h b/deps/icu-small/source/common/ustr_imp.h index 85d8e6d8ee6970..5b249ade3d21bb 100644 --- a/deps/icu-small/source/common/ustr_imp.h +++ b/deps/icu-small/source/common/ustr_imp.h @@ -29,7 +29,7 @@ /** * Compare two strings in code point order or code unit order. * Works in strcmp style (both lengths -1), - * strncmp style (lengths equal and >=0, flag TRUE), + * strncmp style (lengths equal and >=0, flag true), * and memcmp/UnicodeString style (at least one length >=0). */ U_CFUNC int32_t U_EXPORT2 @@ -37,13 +37,13 @@ uprv_strCompare(const UChar *s1, int32_t length1, const UChar *s2, int32_t length2, UBool strncmpStyle, UBool codePointOrder); -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ustr_hashUCharsN(const UChar *str, int32_t length); -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ustr_hashCharsN(const char *str, int32_t length); -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ustr_hashICharsN(const char *str, int32_t length); /** @@ -53,7 +53,7 @@ ustr_hashICharsN(const char *str, int32_t length); * @return If UChar is a lowercase ASCII character, returns the uppercase version. * Otherwise, returns the input character. */ -U_INTERNAL UChar U_EXPORT2 +U_CAPI UChar U_EXPORT2 u_asciiToUpper(UChar c); // TODO: Add u_asciiToLower if/when there is a need for it. @@ -70,28 +70,28 @@ u_asciiToUpper(UChar c); * @param pErrorCode ICU error code. * @return length */ -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); /** * NUL-terminate a char * string if possible. * Same as u_terminateUChars() but for a different string type. */ -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); /** * NUL-terminate a UChar32 * string if possible. * Same as u_terminateUChars() but for a different string type. */ -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); /** * NUL-terminate a wchar_t * string if possible. * Same as u_terminateUChars() but for a different string type. */ -U_INTERNAL int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); /** @@ -133,7 +133,7 @@ class UTF8 { * @param t The i-th byte following the lead byte. * @param i The index (1..3) of byte t in the byte sequence. 0 length) { + tailLimit = length; + } + c = (UChar) u_unescapeAt(charAt, &ahead, tailLimit, + context); } if (U16_IS_TRAIL(c)) { *offset = ahead; diff --git a/deps/icu-small/source/common/util.h b/deps/icu-small/source/common/util.h index a2be25056e9acb..2a709e408a2698 100644 --- a/deps/icu-small/source/common/util.h +++ b/deps/icu-small/source/common/util.h @@ -64,8 +64,8 @@ class U_COMMON_API ICU_Utility /* not : public UObject because all methods are s /** * Escape unprintable characters using \uxxxx notation for U+0000 to * U+FFFF and \Uxxxxxxxx for U+10000 and above. If the character is - * printable ASCII, then do nothing and return FALSE. Otherwise, - * append the escaped notation and return TRUE. + * printable ASCII, then do nothing and return false. Otherwise, + * append the escaped notation and return true. */ static UBool escapeUnprintable(UnicodeString& result, UChar32 c); @@ -95,7 +95,7 @@ class U_COMMON_API ICU_Utility /* not : public UObject because all methods are s * after pos, or str.length(), if there is none. */ static int32_t skipWhitespace(const UnicodeString& str, int32_t& pos, - UBool advance = FALSE); + UBool advance = false); /** * Skip over Pattern_White_Space in a Replaceable. diff --git a/deps/icu-small/source/common/utrie.h b/deps/icu-small/source/common/utrie.h index 532ba778eb6ed1..2fd2c461ffb250 100644 --- a/deps/icu-small/source/common/utrie.h +++ b/deps/icu-small/source/common/utrie.h @@ -460,13 +460,13 @@ UTrieEnumValue(const void *context, uint32_t value); * of code points with the same value as retrieved from the trie and * transformed by the UTrieEnumValue function. * - * The callback function can stop the enumeration by returning FALSE. + * The callback function can stop the enumeration by returning false. * * @param context an opaque pointer, as passed into utrie_enum() * @param start the first code point in a contiguous range with value * @param limit one past the last code point in a contiguous range with value * @param value the value that is set for all code points in [start..limit[ - * @return FALSE to stop the enumeration + * @return false to stop the enumeration */ typedef UBool U_CALLCONV UTrieEnumRange(const void *context, UChar32 start, UChar32 limit, uint32_t value); @@ -667,7 +667,7 @@ utrie_getData(UNewTrie *trie, int32_t *pLength); * @param trie the build-time trie * @param c the code point * @param value the value - * @return FALSE if a failure occurred (illegal argument or data array overrun) + * @return false if a failure occurred (illegal argument or data array overrun) */ U_CAPI UBool U_EXPORT2 utrie_set32(UNewTrie *trie, UChar32 c, uint32_t value); @@ -677,7 +677,7 @@ utrie_set32(UNewTrie *trie, UChar32 c, uint32_t value); * * @param trie the build-time trie * @param c the code point - * @param pInBlockZero if not NULL, then *pInBlockZero is set to TRUE + * @param pInBlockZero if not NULL, then *pInBlockZero is set to true * iff the value is retrieved from block 0; * block 0 is the all-initial-value initial block * @return the value @@ -688,14 +688,14 @@ utrie_get32(UNewTrie *trie, UChar32 c, UBool *pInBlockZero); /** * Set a value in a range of code points [start..limit[. * All code points c with start<=cswapArray32(ds, &inTrie->signature, 4, &outTrie->signature, pErrorCode); ds->swapArray16(ds, &inTrie->options, 12, &outTrie->options, pErrorCode); - /* swap the index and the data */ + /* swap the index */ + const uint16_t *inIndex=reinterpret_cast(inTrie+1); + uint16_t *outIndex=reinterpret_cast(outTrie+1); + ds->swapArray16(ds, inIndex, trie.indexLength*2, outIndex, pErrorCode); + + /* swap the data */ + const uint16_t *inData=inIndex+trie.indexLength; + uint16_t *outData=outIndex+trie.indexLength; switch(valueWidth) { case UCPTRIE_VALUE_BITS_16: - ds->swapArray16(ds, inTrie+1, (trie.indexLength+dataLength)*2, outTrie+1, pErrorCode); + ds->swapArray16(ds, inData, dataLength*2, outData, pErrorCode); break; case UCPTRIE_VALUE_BITS_32: - ds->swapArray16(ds, inTrie+1, trie.indexLength*2, outTrie+1, pErrorCode); - ds->swapArray32(ds, (const uint16_t *)(inTrie+1)+trie.indexLength, dataLength*4, - (uint16_t *)(outTrie+1)+trie.indexLength, pErrorCode); + ds->swapArray32(ds, inData, dataLength*4, outData, pErrorCode); break; case UCPTRIE_VALUE_BITS_8: - ds->swapArray16(ds, inTrie+1, trie.indexLength*2, outTrie+1, pErrorCode); if(inTrie!=outTrie) { - uprv_memmove((outTrie+1)+trie.indexLength, (inTrie+1)+trie.indexLength, dataLength); + uprv_memmove(outData, inData, dataLength); } break; default: diff --git a/deps/icu-small/source/common/uts46.cpp b/deps/icu-small/source/common/uts46.cpp index b9e6cb023bb379..f25b4e12f124ca 100644 --- a/deps/icu-small/source/common/uts46.cpp +++ b/deps/icu-small/source/common/uts46.cpp @@ -714,6 +714,16 @@ UTS46::processLabel(UnicodeString &dest, UBool wasPunycode; if(labelLength>=4 && label[0]==0x78 && label[1]==0x6e && label[2]==0x2d && label[3]==0x2d) { // Label starts with "xn--", try to un-Punycode it. + // In IDNA2008, labels like "xn--" (decodes to an empty string) and + // "xn--ASCII-" (decodes to just "ASCII") fail the round-trip validation from + // comparing the ToUnicode input with the back-to-ToASCII output. + // They are alternate encodings of the respective ASCII labels. + // Ignore "xn---" here: It will fail Punycode.decode() which logically comes before + // the round-trip verification. + if(labelLength==4 || (labelLength>5 && label[labelLength-1]==u'-')) { + info.labelErrors|=UIDNA_ERROR_INVALID_ACE_LABEL; + return markBadACELabel(dest, labelStart, labelLength, toASCII, info, errorCode); + } wasPunycode=TRUE; UChar *unicodeBuffer=fromPunycode.getBuffer(-1); // capacity==-1: most labels should fit if(unicodeBuffer==NULL) { @@ -925,10 +935,10 @@ UTS46::markBadACELabel(UnicodeString &dest, UBool isASCII=TRUE; UBool onlyLDH=TRUE; const UChar *label=dest.getBuffer()+labelStart; - // Ok to cast away const because we own the UnicodeString. - UChar *s=(UChar *)label+4; // After the initial "xn--". const UChar *limit=label+labelLength; - do { + // Start after the initial "xn--". + // Ok to cast away const because we own the UnicodeString. + for(UChar *s=const_cast(label+4); sTo do * diff --git a/deps/icu-small/source/common/uvectr32.h b/deps/icu-small/source/common/uvectr32.h index 91a2dd2009eecb..92746a4f4782d8 100644 --- a/deps/icu-small/source/common/uvectr32.h +++ b/deps/icu-small/source/common/uvectr32.h @@ -214,7 +214,7 @@ class U_COMMON_API UVector32 : public UObject { inline UBool UVector32::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) { if ((minimumCapacity >= 0) && (capacity >= minimumCapacity)) { - return TRUE; + return true; } else { return expandCapacity(minimumCapacity, status); } @@ -233,7 +233,7 @@ inline void UVector32::addElement(int32_t elem, UErrorCode &status) { } inline int32_t *UVector32::reserveBlock(int32_t size, UErrorCode &status) { - if (ensureCapacity(count+size, status) == FALSE) { + if (ensureCapacity(count+size, status) == false) { return NULL; } int32_t *rp = elements+count; diff --git a/deps/icu-small/source/common/uvectr64.h b/deps/icu-small/source/common/uvectr64.h index 6d26863eabc00d..4dab16396c1d13 100644 --- a/deps/icu-small/source/common/uvectr64.h +++ b/deps/icu-small/source/common/uvectr64.h @@ -203,7 +203,7 @@ class U_COMMON_API UVector64 : public UObject { inline UBool UVector64::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) { if ((minimumCapacity >= 0) && (capacity >= minimumCapacity)) { - return TRUE; + return true; } else { return expandCapacity(minimumCapacity, status); } @@ -222,7 +222,7 @@ inline void UVector64::addElement(int64_t elem, UErrorCode &status) { } inline int64_t *UVector64::reserveBlock(int32_t size, UErrorCode &status) { - if (ensureCapacity(count+size, status) == FALSE) { + if (ensureCapacity(count+size, status) == false) { return NULL; } int64_t *rp = elements+count; diff --git a/deps/icu-small/source/common/wintz.cpp b/deps/icu-small/source/common/wintz.cpp index 115512e704cced..047f4290f10d0e 100644 --- a/deps/icu-small/source/common/wintz.cpp +++ b/deps/icu-small/source/common/wintz.cpp @@ -16,11 +16,12 @@ #if U_PLATFORM_USES_ONLY_WIN32_API #include "wintz.h" +#include "charstr.h" #include "cmemory.h" #include "cstring.h" #include "unicode/ures.h" -#include "unicode/ustring.h" +#include "unicode/unistr.h" #include "uresimp.h" #ifndef WIN32_LEAN_AND_MEAN @@ -35,89 +36,111 @@ U_NAMESPACE_BEGIN -// The max size of TimeZoneKeyName is 128, defined in DYNAMIC_TIME_ZONE_INFORMATION -#define MAX_TIMEZONE_ID_LENGTH 128 - /** * Main Windows time zone detection function. * Returns the Windows time zone converted to an ICU time zone as a heap-allocated buffer, or nullptr upon failure. -* Note: We use the Win32 API GetDynamicTimeZoneInformation to get the current time zone info. -* This API returns a non-localized time zone name, which we can then map to an ICU time zone name. +* +* Note: We use the Win32 API GetDynamicTimeZoneInformation (available since Vista+) to get the current time zone info. +* This API returns a non-localized time zone name, which is mapped to an ICU time zone ID (~ Olsen ID). */ -U_INTERNAL const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uprv_detectWindowsTimeZone() { - UErrorCode status = U_ZERO_ERROR; - char* icuid = nullptr; - char dynamicTZKeyName[MAX_TIMEZONE_ID_LENGTH]; - char tmpid[MAX_TIMEZONE_ID_LENGTH]; - int32_t len; - int id = GEOID_NOT_AVAILABLE; - int errorCode; - wchar_t ISOcodeW[3] = {}; /* 2 letter ISO code in UTF-16 */ - char ISOcode[3] = {}; /* 2 letter ISO code in UTF-8 */ - + // Obtain the DYNAMIC_TIME_ZONE_INFORMATION info to get the non-localized time zone name. DYNAMIC_TIME_ZONE_INFORMATION dynamicTZI; uprv_memset(&dynamicTZI, 0, sizeof(dynamicTZI)); - uprv_memset(dynamicTZKeyName, 0, sizeof(dynamicTZKeyName)); - uprv_memset(tmpid, 0, sizeof(tmpid)); + SYSTEMTIME systemTimeAllZero; + uprv_memset(&systemTimeAllZero, 0, sizeof(systemTimeAllZero)); - /* Obtain TIME_ZONE_INFORMATION from the API and get the non-localized time zone name. */ - if (TIME_ZONE_ID_INVALID == GetDynamicTimeZoneInformation(&dynamicTZI)) { + if (GetDynamicTimeZoneInformation(&dynamicTZI) == TIME_ZONE_ID_INVALID) { return nullptr; } - id = GetUserGeoID(GEOCLASS_NATION); - errorCode = GetGeoInfoW(id, GEO_ISO2, ISOcodeW, 3, 0); - - // convert from wchar_t* (UTF-16 on Windows) to char* (UTF-8). - u_strToUTF8(ISOcode, UPRV_LENGTHOF(ISOcode), nullptr, - reinterpret_cast(ISOcodeW), UPRV_LENGTHOF(ISOcodeW), &status); - - LocalUResourceBundlePointer bundle(ures_openDirect(nullptr, "windowsZones", &status)); - ures_getByKey(bundle.getAlias(), "mapTimezones", bundle.getAlias(), &status); + // If the DST setting has been turned off in the Control Panel, then return "Etc/GMT". + // + // Note: This logic is based on how the Control Panel itself determines if DST is 'off' on Windows. + // The code is somewhat convoluted; in a sort of pseudo-code it looks like this: + // + // IF (GetDynamicTimeZoneInformation != TIME_ZONE_ID_INVALID) && (DynamicDaylightTimeDisabled != 0) && + // (StandardDate == DaylightDate) && + // ( + // (TimeZoneKeyName != Empty && StandardDate == 0) || + // (TimeZoneKeyName == Empty && StandardDate != 0) + // ) + // THEN + // DST setting is "Disabled". + // + if (dynamicTZI.DynamicDaylightTimeDisabled != 0 && + uprv_memcmp(&dynamicTZI.StandardDate, &dynamicTZI.DaylightDate, sizeof(dynamicTZI.StandardDate)) == 0 && + ((dynamicTZI.TimeZoneKeyName[0] != L'\0' && uprv_memcmp(&dynamicTZI.StandardDate, &systemTimeAllZero, sizeof(systemTimeAllZero)) == 0) || + (dynamicTZI.TimeZoneKeyName[0] == L'\0' && uprv_memcmp(&dynamicTZI.StandardDate, &systemTimeAllZero, sizeof(systemTimeAllZero)) != 0))) + { + LONG utcOffsetMins = dynamicTZI.Bias; + if (utcOffsetMins == 0) { + return uprv_strdup("Etc/UTC"); + } - // convert from wchar_t* (UTF-16 on Windows) to char* (UTF-8). - u_strToUTF8(dynamicTZKeyName, UPRV_LENGTHOF(dynamicTZKeyName), nullptr, - reinterpret_cast(dynamicTZI.TimeZoneKeyName), -1, &status); + // No way to support when DST is turned off and the offset in minutes is not a multiple of 60. + if (utcOffsetMins % 60 == 0) { + char gmtOffsetTz[11] = {}; // "Etc/GMT+dd" is 11-char long with a terminal null. + // Note '-' before 'utcOffsetMin'. The timezone ID's sign convention + // is that a timezone ahead of UTC is Etc/GMT- and a timezone + // behind UTC is Etc/GMT+. + int ret = snprintf(gmtOffsetTz, UPRV_LENGTHOF(gmtOffsetTz), "Etc/GMT%+d", -utcOffsetMins / 60); + if (ret > 0 && ret < UPRV_LENGTHOF(gmtOffsetTz)) { + return uprv_strdup(gmtOffsetTz); + } + } + } - if (U_FAILURE(status)) { + // If DST is NOT disabled, but we have an empty TimeZoneKeyName, then it is unclear + // what we should do as this should not happen. + if (dynamicTZI.TimeZoneKeyName[0] == 0) { return nullptr; } - if (dynamicTZI.TimeZoneKeyName[0] != 0) { - StackUResourceBundle winTZ; - ures_getByKey(bundle.getAlias(), dynamicTZKeyName, winTZ.getAlias(), &status); + CharString winTZ; + UErrorCode status = U_ZERO_ERROR; + winTZ.appendInvariantChars(UnicodeString(TRUE, dynamicTZI.TimeZoneKeyName, -1), status); - if (U_SUCCESS(status)) { - const UChar* icuTZ = nullptr; - if (errorCode != 0) { - icuTZ = ures_getStringByKey(winTZ.getAlias(), ISOcode, &len, &status); - } - if (errorCode == 0 || icuTZ == nullptr) { - /* fallback to default "001" and reset status */ - status = U_ZERO_ERROR; - icuTZ = ures_getStringByKey(winTZ.getAlias(), "001", &len, &status); - } + // Map Windows Timezone name (non-localized) to ICU timezone ID (~ Olson timezone id). + StackUResourceBundle winTZBundle; + ures_openDirectFillIn(winTZBundle.getAlias(), nullptr, "windowsZones", &status); + ures_getByKey(winTZBundle.getAlias(), "mapTimezones", winTZBundle.getAlias(), &status); + ures_getByKey(winTZBundle.getAlias(), winTZ.data(), winTZBundle.getAlias(), &status); - if (U_SUCCESS(status)) { - int index = 0; + if (U_FAILURE(status)) { + return nullptr; + } - while (!(*icuTZ == '\0' || *icuTZ == ' ')) { - // time zone IDs only contain ASCII invariant characters. - tmpid[index++] = (char)(*icuTZ++); - } - tmpid[index] = '\0'; - } + // Note: Since the ISO 3166 country/region codes are all invariant ASCII chars, we can + // directly downcast from wchar_t to do the conversion. + // We could call the A version of the GetGeoInfo API, but that would be slightly slower than calling the W API, + // as the A version of the API will end up calling MultiByteToWideChar anyways internally. + wchar_t regionCodeW[3] = {}; + char regionCode[3] = {}; // 2 letter ISO 3166 country/region code made entirely of invariant chars. + int geoId = GetUserGeoID(GEOCLASS_NATION); + int regionCodeLen = GetGeoInfoW(geoId, GEO_ISO2, regionCodeW, UPRV_LENGTHOF(regionCodeW), 0); + + const UChar *icuTZ16 = nullptr; + int32_t tzLen; + + if (regionCodeLen != 0) { + for (int i = 0; i < UPRV_LENGTHOF(regionCodeW); i++) { + regionCode[i] = static_cast(regionCodeW[i]); } + icuTZ16 = ures_getStringByKey(winTZBundle.getAlias(), regionCode, &tzLen, &status); } - - // Copy the timezone ID to icuid to be returned. - if (tmpid[0] != 0) { - icuid = uprv_strdup(tmpid); + if (regionCodeLen == 0 || U_FAILURE(status)) { + // fallback to default "001" (world) + status = U_ZERO_ERROR; + icuTZ16 = ures_getStringByKey(winTZBundle.getAlias(), "001", &tzLen, &status); } - return icuid; + // Note: cloneData returns nullptr if the status is a failure, so this + // will return nullptr if the above look-up fails. + CharString icuTZStr; + return icuTZStr.appendInvariantChars(icuTZ16, tzLen, status).cloneData(status); } U_NAMESPACE_END diff --git a/deps/icu-small/source/common/wintz.h b/deps/icu-small/source/common/wintz.h index 9140d2729a98f8..b1ac8c07903738 100644 --- a/deps/icu-small/source/common/wintz.h +++ b/deps/icu-small/source/common/wintz.h @@ -28,7 +28,7 @@ U_CDECL_BEGIN typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION; U_CDECL_END -U_INTERNAL const char* U_EXPORT2 +U_CAPI const char* U_EXPORT2 uprv_detectWindowsTimeZone(); #endif /* U_PLATFORM_USES_ONLY_WIN32_API */ diff --git a/deps/icu-small/source/data/in/icudt67l.dat.bz2 b/deps/icu-small/source/data/in/icudt68l.dat.bz2 similarity index 55% rename from deps/icu-small/source/data/in/icudt67l.dat.bz2 rename to deps/icu-small/source/data/in/icudt68l.dat.bz2 index 60bc3e084f4322..fcee4ecfa17efe 100644 Binary files a/deps/icu-small/source/data/in/icudt67l.dat.bz2 and b/deps/icu-small/source/data/in/icudt68l.dat.bz2 differ diff --git a/deps/icu-small/source/i18n/buddhcal.h b/deps/icu-small/source/i18n/buddhcal.h index c3ffa6a41d3565..e5ce18883ac039 100644 --- a/deps/icu-small/source/i18n/buddhcal.h +++ b/deps/icu-small/source/i18n/buddhcal.h @@ -174,7 +174,7 @@ class BuddhistCalendar : public GregorianCalendar { UBool useMonth) const; /** - * Returns TRUE because the Buddhist Calendar does have a default century + * Returns true because the Buddhist Calendar does have a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/calendar.cpp b/deps/icu-small/source/i18n/calendar.cpp index e8b718f3c4619d..df256c154d7a4f 100644 --- a/deps/icu-small/source/i18n/calendar.cpp +++ b/deps/icu-small/source/i18n/calendar.cpp @@ -266,7 +266,7 @@ static ECalType getCalendarTypeForLocale(const char *locid) { //TODO: ULOC_FULL_NAME is out of date and too small.. char canonicalName[256]; - // canonicalize, so grandfathered variant will be transformed to keywords + // Canonicalize, so that an old-style variant will be transformed to keywords. // e.g ja_JP_TRADITIONAL -> ja_JP@calendar=japanese // NOTE: Since ICU-20187, ja_JP_TRADITIONAL no longer canonicalizes, and // the Gregorian calendar is returned instead. @@ -870,7 +870,7 @@ Calendar::createInstance(const TimeZone& zone, UErrorCode& success) Calendar* U_EXPORT2 Calendar::createInstance(const Locale& aLocale, UErrorCode& success) { - return createInstance(TimeZone::createDefault(), aLocale, success); + return createInstance(TimeZone::forLocaleOrDefault(aLocale), aLocale, success); } // ------------------------------------- Adopting diff --git a/deps/icu-small/source/i18n/cecal.cpp b/deps/icu-small/source/i18n/cecal.cpp index 458fe2f3049b9d..3389b728697db3 100644 --- a/deps/icu-small/source/i18n/cecal.cpp +++ b/deps/icu-small/source/i18n/cecal.cpp @@ -49,7 +49,7 @@ static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = { //------------------------------------------------------------------------- CECalendar::CECalendar(const Locale& aLocale, UErrorCode& success) -: Calendar(TimeZone::createDefault(), aLocale, success) +: Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success) { setTimeInMillis(getNow(), success); } diff --git a/deps/icu-small/source/i18n/cecal.h b/deps/icu-small/source/i18n/cecal.h index c380f0bea30523..80dab70f6ff0bf 100644 --- a/deps/icu-small/source/i18n/cecal.h +++ b/deps/icu-small/source/i18n/cecal.h @@ -88,7 +88,7 @@ class U_I18N_API CECalendar : public Calendar { virtual UBool inDaylightTime(UErrorCode&) const; /** - * Returns TRUE because Coptic/Ethiopic Calendar does have a default century + * Returns true because Coptic/Ethiopic Calendar does have a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/chnsecal.cpp b/deps/icu-small/source/i18n/chnsecal.cpp index 2ff9f755afe1f1..2ab08dd33925b2 100644 --- a/deps/icu-small/source/i18n/chnsecal.cpp +++ b/deps/icu-small/source/i18n/chnsecal.cpp @@ -123,7 +123,7 @@ ChineseCalendar* ChineseCalendar::clone() const { } ChineseCalendar::ChineseCalendar(const Locale& aLocale, UErrorCode& success) -: Calendar(TimeZone::createDefault(), aLocale, success), +: Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success), isLeapYear(FALSE), fEpochYear(CHINESE_EPOCH_YEAR), fZoneAstroCalc(getChineseCalZoneAstroCalc()) @@ -133,7 +133,7 @@ ChineseCalendar::ChineseCalendar(const Locale& aLocale, UErrorCode& success) ChineseCalendar::ChineseCalendar(const Locale& aLocale, int32_t epochYear, const TimeZone* zoneAstroCalc, UErrorCode &success) -: Calendar(TimeZone::createDefault(), aLocale, success), +: Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success), isLeapYear(FALSE), fEpochYear(epochYear), fZoneAstroCalc(zoneAstroCalc) diff --git a/deps/icu-small/source/i18n/chnsecal.h b/deps/icu-small/source/i18n/chnsecal.h index c7c063738145e7..77a68a48929e10 100644 --- a/deps/icu-small/source/i18n/chnsecal.h +++ b/deps/icu-small/source/i18n/chnsecal.h @@ -242,7 +242,7 @@ class U_I18N_API ChineseCalendar : public Calendar { /** - * Returns TRUE because the Islamic Calendar does have a default century + * Returns true because the Islamic Calendar does have a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/collation.h b/deps/icu-small/source/i18n/collation.h index e9256c9c12c5a7..ecbba29057f03a 100644 --- a/deps/icu-small/source/i18n/collation.h +++ b/deps/icu-small/source/i18n/collation.h @@ -356,7 +356,7 @@ class U_I18N_API Collation { } /** - * @return TRUE if the ce32 yields one or more CEs without further data lookups + * @return true if the ce32 yields one or more CEs without further data lookups */ static UBool isSelfContainedCE32(uint32_t ce32) { return !isSpecialCE32(ce32) || diff --git a/deps/icu-small/source/i18n/collationbuilder.h b/deps/icu-small/source/i18n/collationbuilder.h index 2f20050f93ba1d..82f0459748f051 100644 --- a/deps/icu-small/source/i18n/collationbuilder.h +++ b/deps/icu-small/source/i18n/collationbuilder.h @@ -42,7 +42,7 @@ class U_I18N_API CollationBuilder : public CollationRuleParser::Sink { CollationBuilder(const CollationTailoring *base, UErrorCode &errorCode); virtual ~CollationBuilder(); - void disableFastLatin() { fastLatinEnabled = FALSE; } + void disableFastLatin() { fastLatinEnabled = false; } CollationTailoring *parseAndBuild(const UnicodeString &ruleString, const UVersionInfo rulesVersion, diff --git a/deps/icu-small/source/i18n/collationdatabuilder.h b/deps/icu-small/source/i18n/collationdatabuilder.h index fee444deee77dc..6ae77772fd5a46 100644 --- a/deps/icu-small/source/i18n/collationdatabuilder.h +++ b/deps/icu-small/source/i18n/collationdatabuilder.h @@ -73,12 +73,12 @@ class U_I18N_API CollationDataBuilder : public UObject { } /** - * @return TRUE if this builder has mappings (e.g., add() has been called) + * @return true if this builder has mappings (e.g., add() has been called) */ UBool hasMappings() const { return modified; } /** - * @return TRUE if c has CEs in this builder + * @return true if c has CEs in this builder */ UBool isAssigned(UChar32 c) const; @@ -118,7 +118,7 @@ class U_I18N_API CollationDataBuilder : public UObject { * @param primary primary weight for 'start' * @param step per-code point primary-weight increment * @param errorCode ICU in/out error code - * @return TRUE if an OFFSET_TAG range was used for start..end + * @return true if an OFFSET_TAG range was used for start..end */ UBool maybeSetPrimaryRange(UChar32 start, UChar32 end, uint32_t primary, int32_t step, @@ -150,7 +150,7 @@ class U_I18N_API CollationDataBuilder : public UObject { void optimize(const UnicodeSet &set, UErrorCode &errorCode); void suppressContractions(const UnicodeSet &set, UErrorCode &errorCode); - void enableFastLatin() { fastLatinEnabled = TRUE; } + void enableFastLatin() { fastLatinEnabled = true; } virtual void build(CollationData &data, UErrorCode &errorCode); /** diff --git a/deps/icu-small/source/i18n/collationfcd.h b/deps/icu-small/source/i18n/collationfcd.h index ec7167d76bab75..3a5738efb24a7c 100644 --- a/deps/icu-small/source/i18n/collationfcd.h +++ b/deps/icu-small/source/i18n/collationfcd.h @@ -84,7 +84,7 @@ class U_I18N_API CollationFCD { // Handles all of Unicode 0..10FFFF. // c can be negative, e.g., U_SENTINEL. // U+0300 is the first character with lccc!=0. - if(c < 0x300) { return FALSE; } + if(c < 0x300) { return false; } if(c > 0xffff) { c = U16_LEAD(c); } int32_t i; return @@ -101,7 +101,7 @@ class U_I18N_API CollationFCD { * This is a fast and imprecise test. * * @param c a code point - * @return TRUE if c is U+0F73, U+0F75 or U+0F81 or one of several other Tibetan characters + * @return true if c is U+0F73, U+0F75 or U+0F81 or one of several other Tibetan characters */ static inline UBool maybeTibetanCompositeVowel(UChar32 c) { return (c & 0x1fff01) == 0xf01; @@ -116,7 +116,7 @@ class U_I18N_API CollationFCD { * They have distinct lccc/tccc combinations: 129/130 or 129/132. * * @param fcd16 the FCD value (lccc/tccc combination) of a code point - * @return TRUE if fcd16 is from U+0F73, U+0F75 or U+0F81 + * @return true if fcd16 is from U+0F73, U+0F75 or U+0F81 */ static inline UBool isFCD16OfTibetanCompositeVowel(uint16_t fcd16) { return fcd16 == 0x8182 || fcd16 == 0x8184; diff --git a/deps/icu-small/source/i18n/collationiterator.h b/deps/icu-small/source/i18n/collationiterator.h index 12e05b4482fab2..869f0956c34d0d 100644 --- a/deps/icu-small/source/i18n/collationiterator.h +++ b/deps/icu-small/source/i18n/collationiterator.h @@ -76,9 +76,9 @@ class U_I18N_API CollationIterator : public UObject { // (Rather than buffer.getCapacity().) if(length < INITIAL_CAPACITY || ensureAppendCapacity(1, errorCode)) { ++length; - return TRUE; + return true; } else { - return FALSE; + return false; } } @@ -251,9 +251,9 @@ class U_I18N_API CollationIterator : public UObject { virtual UBool foundNULTerminator(); /** - * @return FALSE if surrogate code points U+D800..U+DFFF + * @return false if surrogate code points U+D800..U+DFFF * map to their own implicit primary weights (for UTF-16), - * or TRUE if they map to CE(U+FFFD) (for UTF-8) + * or true if they map to CE(U+FFFD) (for UTF-8) */ virtual UBool forbidSurrogateCodePoints() const; diff --git a/deps/icu-small/source/i18n/collationkeys.h b/deps/icu-small/source/i18n/collationkeys.h index 60d9e50c0d9106..c526a4f14f2df8 100644 --- a/deps/icu-small/source/i18n/collationkeys.h +++ b/deps/icu-small/source/i18n/collationkeys.h @@ -65,7 +65,7 @@ class SortKeyByteSink : public ByteSink { } UBool Overflowed() const { return appended_ > capacity_; } - /** @return FALSE if memory allocation failed */ + /** @return false if memory allocation failed */ UBool IsOk() const { return buffer_ != NULL; } protected: @@ -94,8 +94,8 @@ class U_I18N_API CollationKeys /* not : public UObject because all methods are s virtual ~LevelCallback(); /** * @param level The next level about to be written to the ByteSink. - * @return TRUE if the level is to be written - * (the base class implementation always returns TRUE) + * @return true if the level is to be written + * (the base class implementation always returns true) */ virtual UBool needToWrite(Collation::Level level); }; @@ -103,7 +103,7 @@ class U_I18N_API CollationKeys /* not : public UObject because all methods are s /** * Writes the sort key bytes for minLevel up to the iterator data's strength. * Optionally writes the case level. - * Stops writing levels when callback.needToWrite(level) returns FALSE. + * Stops writing levels when callback.needToWrite(level) returns false. * Separates levels with the LEVEL_SEPARATOR_BYTE * but does not write a TERMINATOR_BYTE. */ diff --git a/deps/icu-small/source/i18n/collationtailoring.h b/deps/icu-small/source/i18n/collationtailoring.h index e1bc34c7d7683b..5fc2bac2d307fb 100644 --- a/deps/icu-small/source/i18n/collationtailoring.h +++ b/deps/icu-small/source/i18n/collationtailoring.h @@ -50,7 +50,7 @@ struct U_I18N_API CollationTailoring : public SharedObject { virtual ~CollationTailoring(); /** - * Returns TRUE if the constructor could not initialize properly. + * Returns true if the constructor could not initialize properly. */ UBool isBogus() { return settings == NULL; } diff --git a/deps/icu-small/source/i18n/collationweights.h b/deps/icu-small/source/i18n/collationweights.h index d8cee79e33fd87..bbd88b27e9e3d7 100644 --- a/deps/icu-small/source/i18n/collationweights.h +++ b/deps/icu-small/source/i18n/collationweights.h @@ -62,7 +62,7 @@ class U_I18N_API CollationWeights : public UMemory { * weights less than this one. * @param n The number of collation element weights w necessary such that * lowerLimitclone(): nullptr; fTimePattern = (itvfmt.fTimePattern)? itvfmt.fTimePattern->clone(): nullptr; fDateTimeFormat = (itvfmt.fDateTimeFormat)? itvfmt.fDateTimeFormat->clone(): nullptr; + fCapitalizationContext = itvfmt.fCapitalizationContext; } return *this; } @@ -239,7 +243,7 @@ DateIntervalFormat::operator==(const Format& other) const { if (fDateFormat && fmt->fDateFormat && (*fDateFormat != *fmt->fDateFormat)) {return FALSE;} } // note: fFromCalendar and fToCalendar hold no persistent state, and therefore do not participate in operator ==. - // fDateFormat has the master calendar for the DateIntervalFormat. + // fDateFormat has the primary calendar for the DateIntervalFormat. if (fSkeleton != fmt->fSkeleton) {return FALSE;} if (fDatePattern != fmt->fDatePattern && (fDatePattern == nullptr || fmt->fDatePattern == nullptr)) {return FALSE;} if (fDatePattern && fmt->fDatePattern && (*fDatePattern != *fmt->fDatePattern)) {return FALSE;} @@ -254,6 +258,7 @@ DateIntervalFormat::operator==(const Format& other) const { if (fIntervalPatterns[i].secondPart != fmt->fIntervalPatterns[i].secondPart ) {return FALSE;} if (fIntervalPatterns[i].laterDateFirst != fmt->fIntervalPatterns[i].laterDateFirst) {return FALSE;} } + if (fCapitalizationContext != fmt->fCapitalizationContext) {return FALSE;} return TRUE; } @@ -409,6 +414,7 @@ UnicodeString& DateIntervalFormat::formatIntervalImpl( } +// The following is only called from within the gFormatterMutex lock UnicodeString& DateIntervalFormat::formatImpl(Calendar& fromCalendar, Calendar& toCalendar, @@ -464,6 +470,11 @@ DateIntervalFormat::formatImpl(Calendar& fromCalendar, if ( U_FAILURE(status) ) { return appendTo; } + UErrorCode tempStatus = U_ZERO_ERROR; // for setContext, ignored + // Set up fDateFormat to handle the first or only part of the interval + // (override later for any second part). Inside lock, OK to modify fDateFormat. + fDateFormat->setContext(fCapitalizationContext, tempStatus); + if ( field == UCAL_FIELD_COUNT ) { /* ignore the millisecond etc. small fields' difference. * use single date when all the above are the same. @@ -521,6 +532,9 @@ DateIntervalFormat::formatImpl(Calendar& fromCalendar, if ( !intervalPattern.secondPart.isEmpty() ) { fDateFormat->applyPattern(intervalPattern.secondPart); + // No capitalization for second part of interval + tempStatus = U_ZERO_ERROR; + fDateFormat->setContext(UDISPCTX_CAPITALIZATION_NONE, tempStatus); fDateFormat->_format(*secondCal, appendTo, fphandler, status); } fDateFormat->applyPattern(originalPattern); @@ -583,7 +597,7 @@ DateIntervalFormat::adoptTimeZone(TimeZone* zone) if (fDateFormat != nullptr) { fDateFormat->adoptTimeZone(zone); } - // The fDateFormat has the master calendar for the DateIntervalFormat and has + // The fDateFormat has the primary calendar for the DateIntervalFormat and has // ownership of any adopted TimeZone; fFromCalendar and fToCalendar are internal // work clones of that calendar (and should not also be given ownership of the // adopted TimeZone). @@ -601,7 +615,7 @@ DateIntervalFormat::setTimeZone(const TimeZone& zone) if (fDateFormat != nullptr) { fDateFormat->setTimeZone(zone); } - // The fDateFormat has the master calendar for the DateIntervalFormat; + // The fDateFormat has the primary calendar for the DateIntervalFormat; // fFromCalendar and fToCalendar are internal work clones of that calendar. if (fFromCalendar) { fFromCalendar->setTimeZone(zone); @@ -622,6 +636,30 @@ DateIntervalFormat::getTimeZone() const return *(TimeZone::createDefault()); } +void +DateIntervalFormat::setContext(UDisplayContext value, UErrorCode& status) +{ + if (U_FAILURE(status)) + return; + if ( (UDisplayContextType)((uint32_t)value >> 8) == UDISPCTX_TYPE_CAPITALIZATION ) { + fCapitalizationContext = value; + } else { + status = U_ILLEGAL_ARGUMENT_ERROR; + } +} + +UDisplayContext +DateIntervalFormat::getContext(UDisplayContextType type, UErrorCode& status) const +{ + if (U_FAILURE(status)) + return (UDisplayContext)0; + if (type != UDISPCTX_TYPE_CAPITALIZATION) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return (UDisplayContext)0; + } + return fCapitalizationContext; +} + DateIntervalFormat::DateIntervalFormat(const Locale& locale, DateIntervalInfo* dtItvInfo, const UnicodeString* skeleton, @@ -633,7 +671,8 @@ DateIntervalFormat::DateIntervalFormat(const Locale& locale, fLocale(locale), fDatePattern(nullptr), fTimePattern(nullptr), - fDateTimeFormat(nullptr) + fDateTimeFormat(nullptr), + fCapitalizationContext(UDISPCTX_CAPITALIZATION_NONE) { LocalPointer info(dtItvInfo, status); LocalPointer dtfmt(static_cast( @@ -751,7 +790,7 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { /* the difference between time skeleton and normalizedTimeSkeleton are: * 1. (Formerly, normalized time skeleton folded 'H' to 'h'; no longer true) - * 2. 'a' is omitted in normalized time skeleton. + * 2. (Formerly, 'a' was omitted in normalized time skeleton; this is now handled elsewhere) * 3. there is only one appearance for 'h' or 'H', 'm','v', 'z' in normalized * time skeleton * @@ -760,7 +799,8 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { * 2. 'E' and 'EE' are normalized into 'EEE' * 3. 'MM' is normalized into 'M' */ - getDateTimeSkeleton(fSkeleton, dateSkeleton, normalizedDateSkeleton, + UnicodeString convertedSkeleton = normalizeHourMetacharacters(fSkeleton); + getDateTimeSkeleton(convertedSkeleton, dateSkeleton, normalizedDateSkeleton, timeSkeleton, normalizedTimeSkeleton); #ifdef DTITVFMT_DEBUG @@ -899,6 +939,91 @@ DateIntervalFormat::initializePattern(UErrorCode& status) { +UnicodeString +DateIntervalFormat::normalizeHourMetacharacters(const UnicodeString& skeleton) const { + UnicodeString result = skeleton; + + UChar hourMetachar = u'\0'; + int32_t metacharStart = 0; + int32_t metacharCount = 0; + for (int32_t i = 0; i < result.length(); i++) { + UChar c = result[i]; + if (c == LOW_J || c == CAP_J || c == CAP_C) { + if (hourMetachar == u'\0') { + hourMetachar = c; + metacharStart = i; + } + ++metacharCount; + } else { + if (hourMetachar != u'\0') { + break; + } + } + } + + if (hourMetachar != u'\0') { + UErrorCode err = U_ZERO_ERROR; + UChar hourChar = CAP_H; + UChar dayPeriodChar = LOW_A; + UnicodeString convertedPattern = DateFormat::getBestPattern(fLocale, UnicodeString(hourMetachar), err); + + if (U_SUCCESS(err)) { + // strip literal text from the pattern (so literal characters don't get mistaken for pattern + // characters-- such as the 'h' in 'Uhr' in Germam) + int32_t firstQuotePos; + while ((firstQuotePos = convertedPattern.indexOf(u'\'')) != -1) { + int32_t secondQuotePos = convertedPattern.indexOf(u'\'', firstQuotePos + 1); + if (secondQuotePos == -1) { + secondQuotePos = firstQuotePos; + } + convertedPattern.replace(firstQuotePos, (secondQuotePos - firstQuotePos) + 1, UnicodeString()); + } + + if (convertedPattern.indexOf(LOW_H) != -1) { + hourChar = LOW_H; + } else if (convertedPattern.indexOf(CAP_K) != -1) { + hourChar = CAP_K; + } else if (convertedPattern.indexOf(LOW_K) != -1) { + hourChar = LOW_K; + } + + if (convertedPattern.indexOf(LOW_B) != -1) { + dayPeriodChar = LOW_B; + } else if (convertedPattern.indexOf(CAP_B) != -1) { + dayPeriodChar = CAP_B; + } + } + + if (hourChar == CAP_H || hourChar == LOW_K) { + result.replace(metacharStart, metacharCount, hourChar); + } else { + UnicodeString hourAndDayPeriod(hourChar); + switch (metacharCount) { + case 1: + case 2: + default: + hourAndDayPeriod.append(UnicodeString(dayPeriodChar)); + break; + case 3: + case 4: + for (int32_t i = 0; i < 4; i++) { + hourAndDayPeriod.append(dayPeriodChar); + } + break; + case 5: + case 6: + for (int32_t i = 0; i < 5; i++) { + hourAndDayPeriod.append(dayPeriodChar); + } + break; + } + result.replace(metacharStart, metacharCount, hourAndDayPeriod); + } + } + return result; +} + + void U_EXPORT2 DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, UnicodeString& dateSkeleton, @@ -911,11 +1036,10 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, int32_t dCount = 0; int32_t MCount = 0; int32_t yCount = 0; - int32_t hCount = 0; - int32_t HCount = 0; int32_t mCount = 0; int32_t vCount = 0; int32_t zCount = 0; + UChar hourChar = u'\0'; int32_t i; for (i = 0; i < skeleton.length(); ++i) { @@ -956,17 +1080,14 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, normalizedDateSkeleton.append(ch); dateSkeleton.append(ch); break; - case LOW_A: - // 'a' is implicitly handled - timeSkeleton.append(ch); - break; case LOW_H: - timeSkeleton.append(ch); - ++hCount; - break; case CAP_H: + case LOW_K: + case CAP_K: timeSkeleton.append(ch); - ++HCount; + if (hourChar == u'\0') { + hourChar = ch; + } break; case LOW_M: timeSkeleton.append(ch); @@ -980,14 +1101,15 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, ++vCount; timeSkeleton.append(ch); break; + case LOW_A: case CAP_V: case CAP_Z: - case LOW_K: - case CAP_K: case LOW_J: case LOW_S: case CAP_S: case CAP_A: + case LOW_B: + case CAP_B: timeSkeleton.append(ch); normalizedTimeSkeleton.append(ch); break; @@ -1023,11 +1145,8 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton, } /* generate normalized form for time */ - if ( HCount != 0 ) { - normalizedTimeSkeleton.append(CAP_H); - } - else if ( hCount != 0 ) { - normalizedTimeSkeleton.append(LOW_H); + if ( hourChar != u'\0' ) { + normalizedTimeSkeleton.append(hourChar); } if ( mCount != 0 ) { normalizedTimeSkeleton.append(LOW_M); @@ -1335,10 +1454,11 @@ DateIntervalFormat::setIntervalPattern(UCalendarDateFields field, } } if ( !pattern.isEmpty() ) { - if ( differenceInfo != 0 ) { + UBool suppressDayPeriodField = fSkeleton.indexOf(CAP_J) != -1; + if ( differenceInfo != 0 || suppressDayPeriodField) { UnicodeString adjustIntervalPattern; adjustFieldWidth(*skeleton, *bestSkeleton, pattern, differenceInfo, - adjustIntervalPattern); + suppressDayPeriodField, adjustIntervalPattern); setIntervalPattern(field, adjustIntervalPattern); } else { setIntervalPattern(field, pattern); @@ -1425,6 +1545,7 @@ DateIntervalFormat::splitPatternInto2Part(const UnicodeString& intervalPattern) return (i - count); } +// The following is only called from fallbackFormat, i.e. within the gFormatterMutex lock void DateIntervalFormat::fallbackFormatRange( Calendar& fromCalendar, Calendar& toCalendar, @@ -1441,12 +1562,15 @@ void DateIntervalFormat::fallbackFormatRange( int32_t offsets[2]; UnicodeString patternBody = sf.getTextWithNoArguments(offsets, 2); + UErrorCode tempStatus = U_ZERO_ERROR; // for setContext, ignored // TODO(ICU-20406): Use SimpleFormatter Iterator interface when available. if (offsets[0] < offsets[1]) { firstIndex = 0; appendTo.append(patternBody.tempSubStringBetween(0, offsets[0])); fDateFormat->_format(fromCalendar, appendTo, fphandler, status); appendTo.append(patternBody.tempSubStringBetween(offsets[0], offsets[1])); + // No capitalization for second part of interval + fDateFormat->setContext(UDISPCTX_CAPITALIZATION_NONE, tempStatus); fDateFormat->_format(toCalendar, appendTo, fphandler, status); appendTo.append(patternBody.tempSubStringBetween(offsets[1])); } else { @@ -1454,11 +1578,14 @@ void DateIntervalFormat::fallbackFormatRange( appendTo.append(patternBody.tempSubStringBetween(0, offsets[1])); fDateFormat->_format(toCalendar, appendTo, fphandler, status); appendTo.append(patternBody.tempSubStringBetween(offsets[1], offsets[0])); + // No capitalization for second part of interval + fDateFormat->setContext(UDISPCTX_CAPITALIZATION_NONE, tempStatus); fDateFormat->_format(fromCalendar, appendTo, fphandler, status); appendTo.append(patternBody.tempSubStringBetween(offsets[0])); } } +// The following is only called from formatImpl, i.e. within the gFormatterMutex lock UnicodeString& DateIntervalFormat::fallbackFormat(Calendar& fromCalendar, Calendar& toCalendar, @@ -1483,6 +1610,7 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar, UnicodeString fullPattern; // for saving the pattern in fDateFormat fDateFormat->toPattern(fullPattern); // save current pattern, restore later + UErrorCode tempStatus = U_ZERO_ERROR; // for setContext, ignored // {0} is time range // {1} is single date portion // TODO(ICU-20406): Use SimpleFormatter Iterator interface when available. @@ -1492,6 +1620,8 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar, fallbackFormatRange(fromCalendar, toCalendar, appendTo, firstIndex, fphandler, status); appendTo.append(patternBody.tempSubStringBetween(offsets[0], offsets[1])); fDateFormat->applyPattern(*fDatePattern); + // No capitalization for second portion + fDateFormat->setContext(UDISPCTX_CAPITALIZATION_NONE, tempStatus); fDateFormat->_format(fromCalendar, appendTo, fphandler, status); appendTo.append(patternBody.tempSubStringBetween(offsets[1])); } else { @@ -1500,6 +1630,8 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar, fDateFormat->_format(fromCalendar, appendTo, fphandler, status); appendTo.append(patternBody.tempSubStringBetween(offsets[1], offsets[0])); fDateFormat->applyPattern(*fTimePattern); + // No capitalization for second portion + fDateFormat->setContext(UDISPCTX_CAPITALIZATION_NONE, tempStatus); fallbackFormatRange(fromCalendar, toCalendar, appendTo, firstIndex, fphandler, status); appendTo.append(patternBody.tempSubStringBetween(offsets[0])); } @@ -1530,6 +1662,7 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, const UnicodeString& bestMatchSkeleton, const UnicodeString& bestIntervalPattern, int8_t differenceInfo, + UBool suppressDayPeriodField, UnicodeString& adjustedPtn) { adjustedPtn = bestIntervalPattern; int32_t inputSkeletonFieldWidth[] = @@ -1556,19 +1689,44 @@ DateIntervalFormat::adjustFieldWidth(const UnicodeString& inputSkeleton, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const int8_t PATTERN_CHAR_BASE = 0x41; + DateIntervalInfo::parseSkeleton(inputSkeleton, inputSkeletonFieldWidth); DateIntervalInfo::parseSkeleton(bestMatchSkeleton, bestMatchSkeletonFieldWidth); + if (suppressDayPeriodField) { + adjustedPtn.findAndReplace(UnicodeString(LOW_A), UnicodeString()); + adjustedPtn.findAndReplace(UnicodeString(" "), UnicodeString(" ")); + adjustedPtn.trim(); + } if ( differenceInfo == 2 ) { - adjustedPtn.findAndReplace(UnicodeString((UChar)0x76 /* v */), - UnicodeString((UChar)0x7a /* z */)); + if (inputSkeleton.indexOf(LOW_Z) != -1) { + adjustedPtn.findAndReplace(UnicodeString(LOW_V), + UnicodeString(LOW_Z)); + } + if (inputSkeleton.indexOf(CAP_K) != -1) { + adjustedPtn.findAndReplace(UnicodeString(LOW_H), + UnicodeString(CAP_K)); + } + if (inputSkeleton.indexOf(LOW_K) != -1) { + adjustedPtn.findAndReplace(UnicodeString(CAP_H), + UnicodeString(LOW_K)); + } + if (inputSkeleton.indexOf(LOW_B) != -1) { + adjustedPtn.findAndReplace(UnicodeString(LOW_A), + UnicodeString(LOW_B)); + } } + if (adjustedPtn.indexOf(LOW_A) != -1 && bestMatchSkeletonFieldWidth[LOW_A - PATTERN_CHAR_BASE] == 0) { + bestMatchSkeletonFieldWidth[LOW_A - PATTERN_CHAR_BASE] = 1; + } + if (adjustedPtn.indexOf(LOW_B) != -1 && bestMatchSkeletonFieldWidth[LOW_B - PATTERN_CHAR_BASE] == 0) { + bestMatchSkeletonFieldWidth[LOW_B - PATTERN_CHAR_BASE] = 1; + } UBool inQuote = false; UChar prevCh = 0; int32_t count = 0; - const int8_t PATTERN_CHAR_BASE = 0x41; - // loop through the pattern string character by character int32_t adjustedPtnLength = adjustedPtn.length(); int32_t i; diff --git a/deps/icu-small/source/i18n/dtitvinf.cpp b/deps/icu-small/source/i18n/dtitvinf.cpp index 25536346ec74f0..39fd44a392d694 100644 --- a/deps/icu-small/source/i18n/dtitvinf.cpp +++ b/deps/icu-small/source/i18n/dtitvinf.cpp @@ -339,6 +339,9 @@ struct DateIntervalInfo::DateIntervalSink : public ResourceSink { return UCAL_DATE; } else if (c0 == 'a') { return UCAL_AM_PM; + } else if (c0 == 'B') { + // TODO: Using AM/PM as a proxy for flexible day period isn't really correct, but it's close + return UCAL_AM_PM; } else if (c0 == 'h' || c0 == 'H') { return UCAL_HOUR; } else if (c0 == 'm') { @@ -594,20 +597,23 @@ DateIntervalInfo::getBestSkeleton(const UnicodeString& skeleton, const int32_t DIFFERENT_FIELD = 0x1000; const int32_t STRING_NUMERIC_DIFFERENCE = 0x100; const int32_t BASE = 0x41; - const UChar CHAR_V = 0x0076; - const UChar CHAR_Z = 0x007A; - // hack for 'v' and 'z'. - // resource bundle only have time skeletons ending with 'v', - // but not for time skeletons ending with 'z'. - UBool replaceZWithV = false; + // hack for certain alternate characters + // resource bundles only have time skeletons containing 'v', 'h', and 'H' + // but not time skeletons containing 'z', 'K', or 'k' + // the skeleton may also include 'a' or 'b', which never occur in the resource bundles, so strip them out too + UBool replacedAlternateChars = false; const UnicodeString* inputSkeleton = &skeleton; UnicodeString copySkeleton; - if ( skeleton.indexOf(CHAR_Z) != -1 ) { + if ( skeleton.indexOf(LOW_Z) != -1 || skeleton.indexOf(LOW_K) != -1 || skeleton.indexOf(CAP_K) != -1 || skeleton.indexOf(LOW_A) != -1 || skeleton.indexOf(LOW_B) != -1 ) { copySkeleton = skeleton; - copySkeleton.findAndReplace(UnicodeString(CHAR_Z), UnicodeString(CHAR_V)); + copySkeleton.findAndReplace(UnicodeString(LOW_Z), UnicodeString(LOW_V)); + copySkeleton.findAndReplace(UnicodeString(LOW_K), UnicodeString(CAP_H)); + copySkeleton.findAndReplace(UnicodeString(CAP_K), UnicodeString(LOW_H)); + copySkeleton.findAndReplace(UnicodeString(LOW_A), UnicodeString()); + copySkeleton.findAndReplace(UnicodeString(LOW_B), UnicodeString()); inputSkeleton = ©Skeleton; - replaceZWithV = true; + replacedAlternateChars = true; } parseSkeleton(*inputSkeleton, inputSkeletonFieldWidth); @@ -616,7 +622,7 @@ DateIntervalInfo::getBestSkeleton(const UnicodeString& skeleton, // 0 means exact the same skeletons; // 1 means having the same field, but with different length, - // 2 means only z/v differs + // 2 means only z/v, h/K, or H/k differs // -1 means having different field. bestMatchDistanceInfo = 0; int8_t fieldLength = UPRV_LENGTHOF(skeletonFieldWidth); @@ -672,7 +678,7 @@ DateIntervalInfo::getBestSkeleton(const UnicodeString& skeleton, break; } } - if ( replaceZWithV && bestMatchDistanceInfo != -1 ) { + if ( replacedAlternateChars && bestMatchDistanceInfo != -1 ) { bestMatchDistanceInfo = 2; } return bestSkeleton; diff --git a/deps/icu-small/source/i18n/dtptngen.cpp b/deps/icu-small/source/i18n/dtptngen.cpp index 279fb49a7aa9b9..78273ef01e2281 100644 --- a/deps/icu-small/source/i18n/dtptngen.cpp +++ b/deps/icu-small/source/i18n/dtptngen.cpp @@ -311,6 +311,16 @@ DateTimePatternGenerator::createInstance(const Locale& locale, UErrorCode& statu return U_SUCCESS(status) ? result.orphan() : nullptr; } +DateTimePatternGenerator* U_EXPORT2 +DateTimePatternGenerator::createInstanceNoStdPat(const Locale& locale, UErrorCode& status) { + if (U_FAILURE(status)) { + return nullptr; + } + LocalPointer result( + new DateTimePatternGenerator(locale, status, true), status); + return U_SUCCESS(status) ? result.orphan() : nullptr; +} + DateTimePatternGenerator* U_EXPORT2 DateTimePatternGenerator::createEmptyInstance(UErrorCode& status) { if (U_FAILURE(status)) { @@ -336,7 +346,7 @@ DateTimePatternGenerator::DateTimePatternGenerator(UErrorCode &status) : } } -DateTimePatternGenerator::DateTimePatternGenerator(const Locale& locale, UErrorCode &status) : +DateTimePatternGenerator::DateTimePatternGenerator(const Locale& locale, UErrorCode &status, UBool skipStdPatterns) : skipMatcher(nullptr), fAvailableFormatKeyHash(nullptr), fDefaultHourFormatChar(0), @@ -350,7 +360,7 @@ DateTimePatternGenerator::DateTimePatternGenerator(const Locale& locale, UErrorC internalErrorCode = status = U_MEMORY_ALLOCATION_ERROR; } else { - initData(locale, status); + initData(locale, status, skipStdPatterns); } } @@ -489,13 +499,15 @@ enum AllowedHourFormat{ } // namespace void -DateTimePatternGenerator::initData(const Locale& locale, UErrorCode &status) { +DateTimePatternGenerator::initData(const Locale& locale, UErrorCode &status, UBool skipStdPatterns) { //const char *baseLangName = locale.getBaseName(); // unused skipMatcher = nullptr; fAvailableFormatKeyHash=nullptr; addCanonicalItems(status); - addICUPatterns(locale, status); + if (!skipStdPatterns) { // skip to prevent circular dependency when called from SimpleDateFormat::construct + addICUPatterns(locale, status); + } addCLDRData(locale, status); setDateTimeFromCalendar(locale, status); setDecimalSymbols(locale, status); @@ -893,7 +905,7 @@ DateTimePatternGenerator::getCalendarTypeToUse(const Locale& locale, CharString& err = localStatus; return; } - if (calendarTypeLen < ULOC_KEYWORDS_CAPACITY) { + if (calendarTypeLen > 0 && calendarTypeLen < ULOC_KEYWORDS_CAPACITY) { destination.clear().append(calendarType, -1, err); if (U_FAILURE(err)) { return; } } diff --git a/deps/icu-small/source/i18n/dtptngen_impl.h b/deps/icu-small/source/i18n/dtptngen_impl.h index ade9f57331e769..9b9442d5787142 100644 --- a/deps/icu-small/source/i18n/dtptngen_impl.h +++ b/deps/icu-small/source/i18n/dtptngen_impl.h @@ -195,7 +195,7 @@ class FormatParser : public UMemory { void getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex); UBool isPatternSeparator(const UnicodeString& field) const; static UBool isQuoteLiteral(const UnicodeString& s); - static int32_t getCanonicalIndex(const UnicodeString& s) { return getCanonicalIndex(s, TRUE); } + static int32_t getCanonicalIndex(const UnicodeString& s) { return getCanonicalIndex(s, true); } static int32_t getCanonicalIndex(const UnicodeString& s, UBool strict); private: diff --git a/deps/icu-small/source/i18n/fmtable.cpp b/deps/icu-small/source/i18n/fmtable.cpp index 10a6fdb0ff3441..44c3087fb91aa6 100644 --- a/deps/icu-small/source/i18n/fmtable.cpp +++ b/deps/icu-small/source/i18n/fmtable.cpp @@ -895,7 +895,7 @@ U_NAMESPACE_END U_NAMESPACE_USE -U_DRAFT UFormattable* U_EXPORT2 +U_CAPI UFormattable* U_EXPORT2 ufmt_open(UErrorCode *status) { if( U_FAILURE(*status) ) { return NULL; @@ -908,14 +908,14 @@ ufmt_open(UErrorCode *status) { return fmt; } -U_DRAFT void U_EXPORT2 +U_CAPI void U_EXPORT2 ufmt_close(UFormattable *fmt) { Formattable *obj = Formattable::fromUFormattable(fmt); delete obj; } -U_INTERNAL UFormattableType U_EXPORT2 +U_CAPI UFormattableType U_EXPORT2 ufmt_getType(const UFormattable *fmt, UErrorCode *status) { if(U_FAILURE(*status)) { return (UFormattableType)UFMT_COUNT; @@ -925,27 +925,27 @@ ufmt_getType(const UFormattable *fmt, UErrorCode *status) { } -U_INTERNAL UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ufmt_isNumeric(const UFormattable *fmt) { const Formattable *obj = Formattable::fromUFormattable(fmt); return obj->isNumeric(); } -U_DRAFT UDate U_EXPORT2 +U_CAPI UDate U_EXPORT2 ufmt_getDate(const UFormattable *fmt, UErrorCode *status) { const Formattable *obj = Formattable::fromUFormattable(fmt); return obj->getDate(*status); } -U_DRAFT double U_EXPORT2 +U_CAPI double U_EXPORT2 ufmt_getDouble(UFormattable *fmt, UErrorCode *status) { Formattable *obj = Formattable::fromUFormattable(fmt); return obj->getDouble(*status); } -U_DRAFT int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ufmt_getLong(UFormattable *fmt, UErrorCode *status) { Formattable *obj = Formattable::fromUFormattable(fmt); @@ -953,7 +953,7 @@ ufmt_getLong(UFormattable *fmt, UErrorCode *status) { } -U_DRAFT const void *U_EXPORT2 +U_CAPI const void *U_EXPORT2 ufmt_getObject(const UFormattable *fmt, UErrorCode *status) { const Formattable *obj = Formattable::fromUFormattable(fmt); @@ -966,7 +966,7 @@ ufmt_getObject(const UFormattable *fmt, UErrorCode *status) { return ret; } -U_DRAFT const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ufmt_getUChars(UFormattable *fmt, int32_t *len, UErrorCode *status) { Formattable *obj = Formattable::fromUFormattable(fmt); @@ -986,7 +986,7 @@ ufmt_getUChars(UFormattable *fmt, int32_t *len, UErrorCode *status) { return str.getTerminatedBuffer(); } -U_DRAFT int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ufmt_getArrayLength(const UFormattable* fmt, UErrorCode *status) { const Formattable *obj = Formattable::fromUFormattable(fmt); @@ -995,7 +995,7 @@ ufmt_getArrayLength(const UFormattable* fmt, UErrorCode *status) { return count; } -U_DRAFT UFormattable * U_EXPORT2 +U_CAPI UFormattable * U_EXPORT2 ufmt_getArrayItemByIndex(UFormattable* fmt, int32_t n, UErrorCode *status) { Formattable *obj = Formattable::fromUFormattable(fmt); int32_t count; @@ -1010,7 +1010,7 @@ ufmt_getArrayItemByIndex(UFormattable* fmt, int32_t n, UErrorCode *status) { } } -U_DRAFT const char * U_EXPORT2 +U_CAPI const char * U_EXPORT2 ufmt_getDecNumChars(UFormattable *fmt, int32_t *len, UErrorCode *status) { if(U_FAILURE(*status)) { return ""; @@ -1031,7 +1031,7 @@ ufmt_getDecNumChars(UFormattable *fmt, int32_t *len, UErrorCode *status) { } } -U_DRAFT int64_t U_EXPORT2 +U_CAPI int64_t U_EXPORT2 ufmt_getInt64(UFormattable *fmt, UErrorCode *status) { Formattable *obj = Formattable::fromUFormattable(fmt); return obj->getInt64(*status); diff --git a/deps/icu-small/source/i18n/fmtable_cnv.cpp b/deps/icu-small/source/i18n/fmtable_cnv.cpp index 9a647927797dbd..bc3847b6963e70 100644 --- a/deps/icu-small/source/i18n/fmtable_cnv.cpp +++ b/deps/icu-small/source/i18n/fmtable_cnv.cpp @@ -30,8 +30,6 @@ U_NAMESPACE_BEGIN // ------------------------------------- // Creates a formattable object with a char* string. // This API is useless. The API that takes a UnicodeString is actually just as good. -// This is just a grandfathered API. - Formattable::Formattable(const char* stringToCopy) { init(); diff --git a/deps/icu-small/source/i18n/format.cpp b/deps/icu-small/source/i18n/format.cpp index e5abbe9eb0fa7d..a010defff93c40 100644 --- a/deps/icu-small/source/i18n/format.cpp +++ b/deps/icu-small/source/i18n/format.cpp @@ -26,7 +26,7 @@ #include "unicode/utypes.h" #ifndef U_I18N_IMPLEMENTATION -#error U_I18N_IMPLEMENTATION not set - must be set for all ICU source files in i18n/ - see http://userguide.icu-project.org/howtouseicu +#error U_I18N_IMPLEMENTATION not set - must be set for all ICU source files in i18n/ - see https://unicode-org.github.io/icu/userguide/howtouseicu #endif /* diff --git a/deps/icu-small/source/i18n/formatted_string_builder.h b/deps/icu-small/source/i18n/formatted_string_builder.h index 4567dc1d66b0ce..92bcf07d782cde 100644 --- a/deps/icu-small/source/i18n/formatted_string_builder.h +++ b/deps/icu-small/source/i18n/formatted_string_builder.h @@ -25,7 +25,7 @@ class FormattedValueStringBuilderImpl; * *

      *
    1. Efficient prepend as well as append. - *
    2. Keeps tracks of Fields in an efficient manner. + *
    3. Keeps track of Fields in an efficient manner. *
    * * See also FormattedValueStringBuilderImpl. @@ -55,7 +55,6 @@ class U_I18N_API FormattedStringBuilder : public UMemory { // Convention: bottom 4 bits for field, top 4 bits for field category. // Field category 0 implies the number category so that the number field // literals can be directly passed as a Field type. - // See the helper functions in "StringBuilderFieldUtils" below. // Exported as U_I18N_API so it can be used by other exports on Windows. struct U_I18N_API Field { uint8_t bits; diff --git a/deps/icu-small/source/i18n/formattedval_impl.h b/deps/icu-small/source/i18n/formattedval_impl.h index 73ae9a3ea2ab3a..8005b0abb4d848 100644 --- a/deps/icu-small/source/i18n/formattedval_impl.h +++ b/deps/icu-small/source/i18n/formattedval_impl.h @@ -69,6 +69,9 @@ U_NAMESPACE_BEGIN /** * Implementation of FormattedValue using FieldPositionHandler to accept fields. + * + * TODO(ICU-20897): This class is unused. If it is not needed when fixing ICU-20897, + * it should be deleted. */ class FormattedValueFieldPositionIteratorImpl : public UMemory, public FormattedValue { public: @@ -114,6 +117,18 @@ class FormattedValueFieldPositionIteratorImpl : public UMemory, public Formatted }; +// Export an explicit template instantiation of the MaybeStackArray that +// is used as a data member of CEBuffer. +// +// When building DLLs for Windows this is required even though +// no direct access to the MaybeStackArray leaks out of the i18n library. +// +// See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples. +// +#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN +template class U_I18N_API MaybeStackArray; +#endif + /** * Implementation of FormattedValue based on FormattedStringBuilder. * @@ -147,12 +162,17 @@ class U_I18N_API FormattedValueStringBuilderImpl : public UMemory, public Format return fString; } + void appendSpanIndex(int32_t index); + void prependSpanIndex(int32_t index); + private: FormattedStringBuilder fString; FormattedStringBuilder::Field fNumericField; + MaybeStackArray spanIndices; bool nextPositionImpl(ConstrainedFieldPosition& cfpos, FormattedStringBuilder::Field numericField, UErrorCode& status) const; static bool isIntOrGroup(FormattedStringBuilder::Field field); + static bool isTrimmable(FormattedStringBuilder::Field field); int32_t trimBack(int32_t limit) const; int32_t trimFront(int32_t start) const; }; @@ -211,7 +231,7 @@ struct UFormattedValueImpl : public UMemory, public UFormattedValueApiHelper { return fData->appendTo(appendable, status); \ } \ UBool Name::nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const { \ - UPRV_FORMATTED_VALUE_METHOD_GUARD(FALSE) \ + UPRV_FORMATTED_VALUE_METHOD_GUARD(false) \ return fData->nextPosition(cfpos, status); \ } @@ -230,7 +250,7 @@ struct UFormattedValueImpl : public UMemory, public UFormattedValueApiHelper { } \ return static_cast(impl)->exportForC(); \ } \ - U_DRAFT const UFormattedValue* U_EXPORT2 \ + U_CAPI const UFormattedValue* U_EXPORT2 \ Prefix ## _resultAsValue (const CType* uresult, UErrorCode* ec) { \ const ImplType* result = HelperType::validate(uresult, *ec); \ if (U_FAILURE(*ec)) { return nullptr; } \ diff --git a/deps/icu-small/source/i18n/formattedval_sbimpl.cpp b/deps/icu-small/source/i18n/formattedval_sbimpl.cpp index dfe3af6686df2f..b2ae4c34c0a66d 100644 --- a/deps/icu-small/source/i18n/formattedval_sbimpl.cpp +++ b/deps/icu-small/source/i18n/formattedval_sbimpl.cpp @@ -15,6 +15,7 @@ #include "formatted_string_builder.h" #include "number_utils.h" #include "static_unicode_sets.h" +#include "unicode/listformatter.h" U_NAMESPACE_BEGIN @@ -102,14 +103,25 @@ static constexpr Field kEndField = Field(0xf, 0xf); bool FormattedValueStringBuilderImpl::nextPositionImpl(ConstrainedFieldPosition& cfpos, Field numericField, UErrorCode& /*status*/) const { int32_t fieldStart = -1; Field currField = kUndefinedField; + UFieldCategory spanCategory = UFIELD_CATEGORY_UNDEFINED; + int32_t spanValue; for (int32_t i = fString.fZero + cfpos.getLimit(); i <= fString.fZero + fString.fLength; i++) { Field _field = (i < fString.fZero + fString.fLength) ? fString.getFieldPtr()[i] : kEndField; // Case 1: currently scanning a field. if (currField != kUndefinedField) { if (currField != _field) { int32_t end = i - fString.fZero; + // Handle span fields; don't trim them + if (spanCategory != UFIELD_CATEGORY_UNDEFINED) { + cfpos.setState( + spanCategory, + spanValue, + fieldStart, + end); + return true; + } // Grouping separators can be whitespace; don't throw them out! - if (currField != Field(UFIELD_CATEGORY_NUMBER, UNUM_GROUPING_SEPARATOR_FIELD)) { + if (isTrimmable(currField)) { end = trimBack(i - fString.fZero); } if (end <= fieldStart) { @@ -120,7 +132,7 @@ bool FormattedValueStringBuilderImpl::nextPositionImpl(ConstrainedFieldPosition& continue; } int32_t start = fieldStart; - if (currField != Field(UFIELD_CATEGORY_NUMBER, UNUM_GROUPING_SEPARATOR_FIELD)) { + if (isTrimmable(currField)) { start = trimFront(start); } cfpos.setState(currField.getCategory(), currField.getField(), start, end); @@ -154,7 +166,8 @@ bool FormattedValueStringBuilderImpl::nextPositionImpl(ConstrainedFieldPosition& || cfpos.getField() != numericField.getField()) && fString.getFieldPtr()[i - 1].isNumeric() && !_field.isNumeric()) { - int j = i - 1; + // Re-wind to the beginning of the field and then emit it + int32_t j = i - 1; for (; j >= fString.fZero && fString.getFieldPtr()[j].isNumeric(); j--) {} cfpos.setState( numericField.getCategory(), @@ -163,6 +176,23 @@ bool FormattedValueStringBuilderImpl::nextPositionImpl(ConstrainedFieldPosition& i - fString.fZero); return true; } + // Special case: emit normalField if we are pointing at the end of spanField. + if (i > fString.fZero) { + auto elementField = fString.getFieldPtr()[i-1]; + if (elementField == Field(UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD) + && cfpos.matchesField(elementField.getCategory(), elementField.getField()) + && (cfpos.getLimit() < i - fString.fZero || cfpos.getCategory() != elementField.getCategory())) { + // Re-wind to the beginning of the field and then emit it + int32_t j = i - 1; + for (; j >= fString.fZero && fString.getFieldPtr()[j] == fString.getFieldPtr()[i-1]; j--) {} + cfpos.setState( + elementField.getCategory(), + elementField.getField(), + j - fString.fZero + 1, + i - fString.fZero); + return true; + } + } // Special case: skip over INTEGER; will be coalesced later. if (_field == Field(UFIELD_CATEGORY_NUMBER, UNUM_INTEGER_FIELD)) { _field = kUndefinedField; @@ -172,6 +202,23 @@ bool FormattedValueStringBuilderImpl::nextPositionImpl(ConstrainedFieldPosition& continue; } // Case 3: check for field starting at this position + // Case 3a: Need to add a SpanField + if (_field == Field(UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD) + // don't return the same field twice in a row: + && (i == fString.fZero + || fString.getFieldPtr()[i-1].getCategory() != UFIELD_CATEGORY_LIST + || fString.getFieldPtr()[i-1].getField() != ULISTFMT_ELEMENT_FIELD)) { + int64_t si = cfpos.getInt64IterationContext(); + spanValue = spanIndices[si]; + cfpos.setInt64IterationContext(si + 1); + if (cfpos.matchesField(UFIELD_CATEGORY_LIST_SPAN, spanValue)) { + spanCategory = UFIELD_CATEGORY_LIST_SPAN; + fieldStart = i - fString.fZero; + currField = _field; + continue; + } + } + // Case 3b: No SpanField or SpanField did not match if (cfpos.matchesField(_field.getCategory(), _field.getField())) { fieldStart = i - fString.fZero; currField = _field; @@ -182,11 +229,33 @@ bool FormattedValueStringBuilderImpl::nextPositionImpl(ConstrainedFieldPosition& return false; } +void FormattedValueStringBuilderImpl::appendSpanIndex(int32_t position) { + if (spanIndices.getCapacity() <= position) { + spanIndices.resize(position * 2); + } + spanIndices[position] = position; +} + +void FormattedValueStringBuilderImpl::prependSpanIndex(int32_t position) { + if (spanIndices.getCapacity() <= position) { + spanIndices.resize(position * 2); + } + for (int32_t i = 0; i < position; i++) { + spanIndices[i+1] = spanIndices[i]; + } + spanIndices[0] = position; +} + bool FormattedValueStringBuilderImpl::isIntOrGroup(Field field) { return field == Field(UFIELD_CATEGORY_NUMBER, UNUM_INTEGER_FIELD) || field == Field(UFIELD_CATEGORY_NUMBER, UNUM_GROUPING_SEPARATOR_FIELD); } +bool FormattedValueStringBuilderImpl::isTrimmable(Field field) { + return field != Field(UFIELD_CATEGORY_NUMBER, UNUM_GROUPING_SEPARATOR_FIELD) + && field.getCategory() != UFIELD_CATEGORY_LIST; +} + int32_t FormattedValueStringBuilderImpl::trimBack(int32_t limit) const { return unisets::get(unisets::DEFAULT_IGNORABLES)->spanBack( fString.getCharPtr() + fString.fZero, diff --git a/deps/icu-small/source/i18n/formattedvalue.cpp b/deps/icu-small/source/i18n/formattedvalue.cpp index e2c9c42fc88a36..79ecf0a841cf9b 100644 --- a/deps/icu-small/source/i18n/formattedvalue.cpp +++ b/deps/icu-small/source/i18n/formattedvalue.cpp @@ -193,7 +193,7 @@ ucfpos_close(UConstrainedFieldPosition* ptr) { } -U_DRAFT const UChar* U_EXPORT2 +U_CAPI const UChar* U_EXPORT2 ufmtval_getString( const UFormattedValue* ufmtval, int32_t* pLength, @@ -213,7 +213,7 @@ ufmtval_getString( } -U_DRAFT UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ufmtval_nextPosition( const UFormattedValue* ufmtval, UConstrainedFieldPosition* ucfpos, diff --git a/deps/icu-small/source/i18n/fphdlimp.h b/deps/icu-small/source/i18n/fphdlimp.h index b9fa9b218149d4..4fb0c7b6fe686e 100644 --- a/deps/icu-small/source/i18n/fphdlimp.h +++ b/deps/icu-small/source/i18n/fphdlimp.h @@ -41,8 +41,8 @@ class U_I18N_API FieldPositionHandler: public UMemory { class FieldPositionOnlyHandler : public FieldPositionHandler { FieldPosition& pos; - UBool acceptFirstOnly = FALSE; - UBool seenFirst = FALSE; + UBool acceptFirstOnly = false; + UBool seenFirst = false; public: FieldPositionOnlyHandler(FieldPosition& pos); diff --git a/deps/icu-small/source/i18n/gregocal.cpp b/deps/icu-small/source/i18n/gregocal.cpp index 028ab05aa9accc..38a20dd93fb704 100644 --- a/deps/icu-small/source/i18n/gregocal.cpp +++ b/deps/icu-small/source/i18n/gregocal.cpp @@ -185,7 +185,7 @@ fIsGregorian(TRUE), fInvertGregorian(FALSE) // ------------------------------------- GregorianCalendar::GregorianCalendar(const Locale& aLocale, UErrorCode& status) -: Calendar(TimeZone::createDefault(), aLocale, status), +: Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, status), fGregorianCutover(kPapalCutover), fCutoverJulianDay(kCutoverJulianDay), fNormalizedGregorianCutover(fGregorianCutover), fGregorianCutoverYear(1582), fIsGregorian(TRUE), fInvertGregorian(FALSE) diff --git a/deps/icu-small/source/i18n/gregoimp.h b/deps/icu-small/source/i18n/gregoimp.h index eb3844f8523eeb..edcae9dbcc65ff 100644 --- a/deps/icu-small/source/i18n/gregoimp.h +++ b/deps/icu-small/source/i18n/gregoimp.h @@ -148,9 +148,9 @@ class ClockMath { class Grego { public: /** - * Return TRUE if the given year is a leap year. + * Return true if the given year is a leap year. * @param year Gregorian year, with 0 == 1 BCE, -1 == 2 BCE, etc. - * @return TRUE if the year is a leap year + * @return true if the year is a leap year */ static inline UBool isLeapYear(int32_t year); diff --git a/deps/icu-small/source/i18n/hebrwcal.cpp b/deps/icu-small/source/i18n/hebrwcal.cpp index 085ded784651a6..98cbb4a1050d01 100644 --- a/deps/icu-small/source/i18n/hebrwcal.cpp +++ b/deps/icu-small/source/i18n/hebrwcal.cpp @@ -155,7 +155,7 @@ U_NAMESPACE_BEGIN * @internal */ HebrewCalendar::HebrewCalendar(const Locale& aLocale, UErrorCode& success) -: Calendar(TimeZone::createDefault(), aLocale, success) +: Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. @@ -393,7 +393,8 @@ int32_t HebrewCalendar::startOfYear(int32_t year, UErrorCode &status) int32_t day = CalendarCache::get(&gCache, year, status); if (day == 0) { - int32_t months = (235 * year - 234) / 19; // # of months before year + // # of months before year + int32_t months = (int32_t)ClockMath::floorDivide((235 * (int64_t)year - 234), (int64_t)19); int64_t frac = (int64_t)months * MONTH_FRACT + BAHARAD; // Fractional part of day # day = months * 29 + (int32_t)(frac / DAY_PARTS); // Whole # part of calculation @@ -566,8 +567,8 @@ void HebrewCalendar::validateField(UCalendarDateFields field, UErrorCode &status */ void HebrewCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) { int32_t d = julianDay - 347997; - double m = ((d * (double)DAY_PARTS)/ (double) MONTH_PARTS); // Months (approx) - int32_t year = (int32_t)( ((19. * m + 234.) / 235.) + 1.); // Years (approx) + double m = ClockMath::floorDivide((d * (double)DAY_PARTS), (double) MONTH_PARTS); // Months (approx) + int32_t year = (int32_t)(ClockMath::floorDivide((19. * m + 234.), 235.) + 1.); // Years (approx) int32_t ys = startOfYear(year, status); // 1st day of year int32_t dayOfYear = (d - ys); diff --git a/deps/icu-small/source/i18n/hebrwcal.h b/deps/icu-small/source/i18n/hebrwcal.h index 97e8511705e776..34450ffa61855d 100644 --- a/deps/icu-small/source/i18n/hebrwcal.h +++ b/deps/icu-small/source/i18n/hebrwcal.h @@ -386,7 +386,7 @@ class U_I18N_API HebrewCalendar : public Calendar { virtual UBool inDaylightTime(UErrorCode& status) const; /** - * Returns TRUE because the Hebrew Calendar does have a default century + * Returns true because the Hebrew Calendar does have a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/indiancal.cpp b/deps/icu-small/source/i18n/indiancal.cpp index f1266bb7757939..42a91c55e2f526 100644 --- a/deps/icu-small/source/i18n/indiancal.cpp +++ b/deps/icu-small/source/i18n/indiancal.cpp @@ -40,7 +40,7 @@ IndianCalendar* IndianCalendar::clone() const { } IndianCalendar::IndianCalendar(const Locale& aLocale, UErrorCode& success) - : Calendar(TimeZone::createDefault(), aLocale, success) + : Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. } @@ -83,7 +83,6 @@ static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = { {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH }; -static const double JULIAN_EPOCH = 1721425.5; static const int32_t INDIAN_ERA_START = 78; static const int32_t INDIAN_YEAR_START = 80; @@ -96,7 +95,7 @@ int32_t IndianCalendar::handleGetLimit(UCalendarDateFields field, ELimitType lim */ static UBool isGregorianLeap(int32_t year) { - return ((year % 4) == 0) && (!(((year % 100) == 0) && ((year % 400) != 0))); + return Grego::isLeapYear(year); } //---------------------------------------------------------------------- @@ -137,56 +136,22 @@ int32_t IndianCalendar::handleGetYearLength(int32_t eyear) const { * Returns the Julian Day corresponding to gregorian date * * @param year The Gregorian year - * @param month The month in Gregorian Year + * @param month The month in Gregorian Year, 0 based. * @param date The date in Gregorian day in month */ static double gregorianToJD(int32_t year, int32_t month, int32_t date) { - double julianDay = (JULIAN_EPOCH - 1) + - (365 * (year - 1)) + - uprv_floor((year - 1) / 4) + - (-uprv_floor((year - 1) / 100)) + - uprv_floor((year - 1) / 400) + - uprv_floor((((367 * month) - 362) / 12) + - ((month <= 2) ? 0 : - (isGregorianLeap(year) ? -1 : -2) - ) + - date); - - return julianDay; + return Grego::fieldsToDay(year, month, date) + kEpochStartAsJulianDay - 0.5; } /* * Returns the Gregorian Date corresponding to a given Julian Day + * Month is 0 based. * @param jd The Julian Day */ static int32_t* jdToGregorian(double jd, int32_t gregorianDate[3]) { - double wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad, yindex, yearday, leapadj; - int32_t year, month, day; - wjd = uprv_floor(jd - 0.5) + 0.5; - depoch = wjd - JULIAN_EPOCH; - quadricent = uprv_floor(depoch / 146097); - dqc = (int32_t)uprv_floor(depoch) % 146097; - cent = uprv_floor(dqc / 36524); - dcent = (int32_t)uprv_floor(dqc) % 36524; - quad = uprv_floor(dcent / 1461); - dquad = (int32_t)uprv_floor(dcent) % 1461; - yindex = uprv_floor(dquad / 365); - year = (int32_t)((quadricent * 400) + (cent * 100) + (quad * 4) + yindex); - if (!((cent == 4) || (yindex == 4))) { - year++; - } - yearday = wjd - gregorianToJD(year, 1, 1); - leapadj = ((wjd < gregorianToJD(year, 3, 1)) ? 0 - : - (isGregorianLeap(year) ? 1 : 2) - ); - month = (int32_t)uprv_floor((((yearday + leapadj) * 12) + 373) / 367); - day = (int32_t)(wjd - gregorianToJD(year, month, 1)) + 1; - - gregorianDate[0] = year; - gregorianDate[1] = month; - gregorianDate[2] = day; - + int32_t gdow; + Grego::dayToFields(jd - kEpochStartAsJulianDay, + gregorianDate[0], gregorianDate[1], gregorianDate[2], gdow); return gregorianDate; } @@ -203,11 +168,11 @@ static double IndianToJD(int32_t year, int32_t month, int32_t date) { if(isGregorianLeap(gyear)) { leapMonth = 31; - start = gregorianToJD(gyear, 3, 21); + start = gregorianToJD(gyear, 2 /* The third month in 0 based month */, 21); } else { leapMonth = 30; - start = gregorianToJD(gyear, 3, 22); + start = gregorianToJD(gyear, 2 /* The third month in 0 based month */, 22); } if (month == 1) { @@ -297,7 +262,7 @@ void IndianCalendar::handleComputeFields(int32_t julianDay, UErrorCode& /* stat gregorianYear = jdToGregorian(julianDay, gd)[0]; // Gregorian date for Julian day IndianYear = gregorianYear - INDIAN_ERA_START; // Year in Saka era - jdAtStartOfGregYear = gregorianToJD(gregorianYear, 1, 1); // JD at start of Gregorian year + jdAtStartOfGregYear = gregorianToJD(gregorianYear, 0, 1); // JD at start of Gregorian year yday = (int32_t)(julianDay - jdAtStartOfGregYear); // Day number in Gregorian year (starting from 0) if (yday < INDIAN_YEAR_START) { diff --git a/deps/icu-small/source/i18n/indiancal.h b/deps/icu-small/source/i18n/indiancal.h index 142597ce0e6b02..624cec73b53efc 100644 --- a/deps/icu-small/source/i18n/indiancal.h +++ b/deps/icu-small/source/i18n/indiancal.h @@ -147,7 +147,7 @@ class U_I18N_API IndianCalendar : public Calendar { * @param aLocale The given locale. * @param success Indicates the status of IndianCalendar object construction. * Returns U_ZERO_ERROR if constructed successfully. - * @param beCivil Whether the calendar should be civil (default-TRUE) or religious (FALSE) + * @param beCivil Whether the calendar should be civil (default-true) or religious (false) * @internal */ IndianCalendar(const Locale& aLocale, UErrorCode &success); @@ -303,7 +303,7 @@ class U_I18N_API IndianCalendar : public Calendar { /** - * Returns TRUE because the Indian Calendar does have a default century + * Returns true because the Indian Calendar does have a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/islamcal.cpp b/deps/icu-small/source/i18n/islamcal.cpp index 4e4a6648048208..6e21e51150ab88 100644 --- a/deps/icu-small/source/i18n/islamcal.cpp +++ b/deps/icu-small/source/i18n/islamcal.cpp @@ -232,7 +232,7 @@ IslamicCalendar* IslamicCalendar::clone() const { } IslamicCalendar::IslamicCalendar(const Locale& aLocale, UErrorCode& success, ECalculationType type) -: Calendar(TimeZone::createDefault(), aLocale, success), +: Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success), cType(type) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. @@ -368,7 +368,7 @@ int32_t IslamicCalendar::yearStart(int32_t year) const{ if (cType == CIVIL || cType == TBLA || (cType == UMALQURA && (year < UMALQURA_YEAR_START || year > UMALQURA_YEAR_END))) { - return (year-1)*354 + ClockMath::floorDivide((3+11*year),30); + return (year-1)*354 + ClockMath::floorDivide((3+11*(int64_t)year),(int64_t)30); } else if(cType==ASTRONOMICAL){ return trueMonthStart(12*(year-1)); } else { @@ -391,7 +391,7 @@ int32_t IslamicCalendar::monthStart(int32_t year, int32_t month) const { if (cType == CIVIL || cType == TBLA) { // This does not handle months out of the range 0..11 return (int32_t)uprv_ceil(29.5*month) - + (year-1)*354 + (int32_t)ClockMath::floorDivide((3+11*year),30); + + (year-1)*354 + (int32_t)ClockMath::floorDivide((3+11*(int64_t)year),(int64_t)30); } else if(cType==ASTRONOMICAL){ return trueMonthStart(12*(year-1) + month); } else { @@ -447,7 +447,8 @@ int32_t IslamicCalendar::trueMonthStart(int32_t month) const } } while (age < 0); } - start = (int32_t)ClockMath::floorDivide((origin - HIJRA_MILLIS), (double)kOneDay) + 1; + start = (int32_t)(ClockMath::floorDivide( + (int64_t)((int64_t)origin - HIJRA_MILLIS), (int64_t)kOneDay) + 1); CalendarCache::put(&gMonthCache, month, start, status); } trueMonthStartEnd : @@ -639,13 +640,14 @@ void IslamicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) months--; } - year = months / 12 + 1; - month = months % 12; + year = months >= 0 ? ((months / 12) + 1) : ((months + 1 ) / 12); + month = ((months % 12) + 12 ) % 12; } else if(cType == UMALQURA) { int32_t umalquraStartdays = yearStart(UMALQURA_YEAR_START) ; if( days < umalquraStartdays){ //Use Civil calculation - year = (int)ClockMath::floorDivide( (double)(30 * days + 10646) , 10631.0 ); + year = (int32_t)ClockMath::floorDivide( + (30 * (int64_t)days + 10646) , (int64_t)10631.0 ); month = (int32_t)uprv_ceil((days - 29 - yearStart(year)) / 29.5 ); month = month<11?month:11; startDate = monthStart(year, month); diff --git a/deps/icu-small/source/i18n/islamcal.h b/deps/icu-small/source/i18n/islamcal.h index aad8f07be0f984..b4ead411da9e04 100644 --- a/deps/icu-small/source/i18n/islamcal.h +++ b/deps/icu-small/source/i18n/islamcal.h @@ -395,7 +395,7 @@ class U_I18N_API IslamicCalendar : public Calendar { /** - * Returns TRUE because the Islamic Calendar does have a default century + * Returns true because the Islamic Calendar does have a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/japancal.h b/deps/icu-small/source/i18n/japancal.h index ee86c4ed0e3b93..d313fcd99ab508 100644 --- a/deps/icu-small/source/i18n/japancal.h +++ b/deps/icu-small/source/i18n/japancal.h @@ -167,7 +167,7 @@ class JapaneseCalendar : public GregorianCalendar { virtual const char * getType() const; /** - * @return FALSE - no default century in Japanese + * @return false - no default century in Japanese * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/listformatter.cpp b/deps/icu-small/source/i18n/listformatter.cpp index 4b27587555219c..ab04ac9080a5ab 100644 --- a/deps/icu-small/source/i18n/listformatter.cpp +++ b/deps/icu-small/source/i18n/listformatter.cpp @@ -52,10 +52,12 @@ class PatternHandler : public UObject { virtual PatternHandler* clone() const { return new PatternHandler(twoPattern, endPattern); } + /** Argument: final string in the list. */ virtual const SimpleFormatter& getTwoPattern(const UnicodeString&) const { return twoPattern; } + /** Argument: final string in the list. */ virtual const SimpleFormatter& getEndPattern(const UnicodeString&) const { return endPattern; } @@ -237,9 +239,9 @@ ListFormatInternal(const ListFormatInternal &other) : #if !UCONFIG_NO_FORMATTING -class FormattedListData : public FormattedValueFieldPositionIteratorImpl { +class FormattedListData : public FormattedValueStringBuilderImpl { public: - FormattedListData(UErrorCode& status) : FormattedValueFieldPositionIteratorImpl(5, status) {} + FormattedListData(UErrorCode&) : FormattedValueStringBuilderImpl(kUndefinedField) {} virtual ~FormattedListData(); }; @@ -557,50 +559,89 @@ ListFormatter::~ListFormatter() { delete owned; } -/** - * Joins first and second using the pattern pat. - * On entry offset is an offset into first or -1 if offset unspecified. - * On exit offset is offset of second in result if recordOffset was set - * Otherwise if it was >=0 it is set to point into result where it used - * to point into first. On exit, result is the join of first and second - * according to pat. Any previous value of result gets replaced. - */ -static void joinStringsAndReplace( - const SimpleFormatter& pat, - const UnicodeString& first, - const UnicodeString& second, - UnicodeString &result, - UBool recordOffset, - int32_t &offset, - int32_t *offsetFirst, - int32_t *offsetSecond, - UErrorCode& errorCode) { - if (U_FAILURE(errorCode)) { - return; - } - const UnicodeString *params[2] = {&first, &second}; - int32_t offsets[2]; - pat.formatAndReplace( - params, - UPRV_LENGTHOF(params), - result, - offsets, - UPRV_LENGTHOF(offsets), - errorCode); - if (U_FAILURE(errorCode)) { - return; +namespace { + +class FormattedListBuilder { +public: + LocalPointer data; + + /** For lists of length 1+ */ + FormattedListBuilder(const UnicodeString& start, UErrorCode& status) + : data(new FormattedListData(status), status) { + if (U_SUCCESS(status)) { + data->getStringRef().append( + start, + {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD}, + status); + data->appendSpanIndex(0); + } } - if (offsets[0] == -1 || offsets[1] == -1) { - errorCode = U_INVALID_FORMAT_ERROR; - return; + + /** For lists of length 0 */ + FormattedListBuilder(UErrorCode& status) + : data(new FormattedListData(status), status) { } - if (recordOffset) { - offset = offsets[1]; - } else if (offset >= 0) { - offset += offsets[0]; + + void append(const SimpleFormatter& pattern, const UnicodeString& next, int32_t position, UErrorCode& status) { + if (U_FAILURE(status)) { + return; + } + if (pattern.getArgumentLimit() != 2) { + status = U_INTERNAL_PROGRAM_ERROR; + return; + } + // In the pattern, {0} are the pre-existing elements and {1} is the new element. + int32_t offsets[] = {0, 0}; + UnicodeString temp = pattern.getTextWithNoArguments(offsets, 2); + if (offsets[0] <= offsets[1]) { + // prefix{0}infix{1}suffix + // Prepend prefix, then append infix, element, and suffix + data->getStringRef().insert( + 0, + temp.tempSubStringBetween(0, offsets[0]), + {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD}, + status); + data->getStringRef().append( + temp.tempSubStringBetween(offsets[0], offsets[1]), + {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD}, + status); + data->getStringRef().append( + next, + {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD}, + status); + data->appendSpanIndex(position); + data->getStringRef().append( + temp.tempSubString(offsets[1]), + {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD}, + status); + } else { + // prefix{1}infix{0}suffix + // Prepend infix, element, and prefix, then append suffix. + // (We prepend in reverse order because prepending at index 0 is fast.) + data->getStringRef().insert( + 0, + temp.tempSubStringBetween(offsets[1], offsets[0]), + {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD}, + status); + data->getStringRef().insert( + 0, + next, + {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD}, + status); + data->prependSpanIndex(position); + data->getStringRef().insert( + 0, + temp.tempSubStringBetween(0, offsets[1]), + {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD}, + status); + data->getStringRef().append( + temp.tempSubString(offsets[0]), + {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD}, + status); + } } - if (offsetFirst != nullptr) *offsetFirst = offsets[0]; - if (offsetSecond != nullptr) *offsetSecond = offsets[1]; +}; + } UnicodeString& ListFormatter::format( @@ -619,7 +660,19 @@ UnicodeString& ListFormatter::format( int32_t index, int32_t &offset, UErrorCode& errorCode) const { - return format_(items, nItems, appendTo, index, offset, nullptr, errorCode); +#if !UCONFIG_NO_FORMATTING + int32_t initialOffset = appendTo.length(); + auto result = formatStringsToValue(items, nItems, errorCode); + UnicodeStringAppendable appendable(appendTo); + result.appendTo(appendable, errorCode); + if (index >= 0) { + ConstrainedFieldPosition cfpos; + cfpos.constrainField(UFIELD_CATEGORY_LIST_SPAN, index); + result.nextPosition(cfpos, errorCode); + offset = initialOffset + cfpos.getStart(); + } +#endif + return appendTo; } #if !UCONFIG_NO_FORMATTING @@ -627,182 +680,68 @@ FormattedList ListFormatter::formatStringsToValue( const UnicodeString items[], int32_t nItems, UErrorCode& errorCode) const { - LocalPointer result(new FormattedListData(errorCode), errorCode); - if (U_FAILURE(errorCode)) { - return FormattedList(errorCode); + if (nItems == 0) { + FormattedListBuilder result(errorCode); + if (U_FAILURE(errorCode)) { + return FormattedList(errorCode); + } else { + return FormattedList(result.data.orphan()); + } + } else if (nItems == 1) { + FormattedListBuilder result(items[0], errorCode); + result.data->getStringRef().writeTerminator(errorCode); + if (U_FAILURE(errorCode)) { + return FormattedList(errorCode); + } else { + return FormattedList(result.data.orphan()); + } + } else if (nItems == 2) { + FormattedListBuilder result(items[0], errorCode); + if (U_FAILURE(errorCode)) { + return FormattedList(errorCode); + } + result.append( + data->patternHandler->getTwoPattern(items[1]), + items[1], + 1, + errorCode); + result.data->getStringRef().writeTerminator(errorCode); + if (U_FAILURE(errorCode)) { + return FormattedList(errorCode); + } else { + return FormattedList(result.data.orphan()); + } } - UnicodeString string; - int32_t offset; - auto handler = result->getHandler(errorCode); - handler.setCategory(UFIELD_CATEGORY_LIST); - format_(items, nItems, string, -1, offset, &handler, errorCode); - handler.getError(errorCode); - result->appendString(string, errorCode); + + FormattedListBuilder result(items[0], errorCode); if (U_FAILURE(errorCode)) { return FormattedList(errorCode); } - - // Add span fields and sort - ConstrainedFieldPosition cfpos; - cfpos.constrainField(UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD); - int32_t i = 0; - handler.setCategory(UFIELD_CATEGORY_LIST_SPAN); - while (result->nextPosition(cfpos, errorCode)) { - handler.addAttribute(i++, cfpos.getStart(), cfpos.getLimit()); + result.append( + data->startPattern, + items[1], + 1, + errorCode); + for (int32_t i = 2; i < nItems - 1; i++) { + result.append( + data->middlePattern, + items[i], + i, + errorCode); } - handler.getError(errorCode); + result.append( + data->patternHandler->getEndPattern(items[nItems-1]), + items[nItems-1], + nItems-1, + errorCode); + result.data->getStringRef().writeTerminator(errorCode); if (U_FAILURE(errorCode)) { return FormattedList(errorCode); + } else { + return FormattedList(result.data.orphan()); } - result->sort(); - - return FormattedList(result.orphan()); } #endif -UnicodeString& ListFormatter::format_( - const UnicodeString items[], - int32_t nItems, - UnicodeString& appendTo, - int32_t index, - int32_t &offset, - FieldPositionHandler* handler, - UErrorCode& errorCode) const { -#if !UCONFIG_NO_FORMATTING - offset = -1; - if (U_FAILURE(errorCode)) { - return appendTo; - } - if (data == nullptr) { - errorCode = U_INVALID_STATE_ERROR; - return appendTo; - } - - if (nItems <= 0) { - return appendTo; - } - if (nItems == 1) { - if (index == 0) { - offset = appendTo.length(); - } - if (handler != nullptr) { - handler->addAttribute(ULISTFMT_ELEMENT_FIELD, - appendTo.length(), - appendTo.length() + items[0].length()); - } - appendTo.append(items[0]); - return appendTo; - } - UnicodeString result(items[0]); - if (index == 0) { - offset = 0; - } - int32_t offsetFirst = 0; - int32_t offsetSecond = 0; - int32_t prefixLength = 0; - // for n items, there are 2 * (n + 1) boundary including 0 and the upper - // edge. - MaybeStackArray offsets((handler != nullptr) ? 2 * (nItems + 1): 0); - if (nItems == 2) { - joinStringsAndReplace( - data->patternHandler->getTwoPattern(items[1]), - result, - items[1], - result, - index == 1, - offset, - &offsetFirst, - &offsetSecond, - errorCode); - } else { - joinStringsAndReplace( - data->startPattern, - result, - items[1], - result, - index == 1, - offset, - &offsetFirst, - &offsetSecond, - errorCode); - } - if (handler != nullptr) { - offsets[0] = 0; - prefixLength += offsetFirst; - offsets[1] = offsetSecond - prefixLength; - } - if (nItems > 2) { - for (int32_t i = 2; i < nItems - 1; ++i) { - joinStringsAndReplace( - data->middlePattern, - result, - items[i], - result, - index == i, - offset, - &offsetFirst, - &offsetSecond, - errorCode); - if (handler != nullptr) { - prefixLength += offsetFirst; - offsets[i] = offsetSecond - prefixLength; - } - } - joinStringsAndReplace( - data->patternHandler->getEndPattern(items[nItems - 1]), - result, - items[nItems - 1], - result, - index == nItems - 1, - offset, - &offsetFirst, - &offsetSecond, - errorCode); - if (handler != nullptr) { - prefixLength += offsetFirst; - offsets[nItems - 1] = offsetSecond - prefixLength; - } - } - if (handler != nullptr) { - // If there are already some data in appendTo, we need to adjust the index - // by shifting that lenght while insert into handler. - int32_t shift = appendTo.length() + prefixLength; - // Output the ULISTFMT_ELEMENT_FIELD in the order of the input elements - for (int32_t i = 0; i < nItems; ++i) { - offsets[i + nItems] = offsets[i] + items[i].length() + shift; - offsets[i] += shift; - handler->addAttribute( - ULISTFMT_ELEMENT_FIELD, // id - offsets[i], // index - offsets[i + nItems]); // limit - } - // The locale pattern may reorder the items (such as in ur-IN locale), - // so we cannot assume the array is in accendning order. - // To handle the edging case, just insert the two ends into the array - // and sort. Then we output ULISTFMT_LITERAL_FIELD if the indecies - // between the even and odd position are not the same in the sorted array. - offsets[2 * nItems] = shift - prefixLength; - offsets[2 * nItems + 1] = result.length() + shift - prefixLength; - uprv_sortArray(offsets.getAlias(), 2 * (nItems + 1), sizeof(int32_t), - uprv_int32Comparator, nullptr, - false, &errorCode); - for (int32_t i = 0; i <= nItems; ++i) { - if (offsets[i * 2] != offsets[i * 2 + 1]) { - handler->addAttribute( - ULISTFMT_LITERAL_FIELD, // id - offsets[i * 2], // index - offsets[i * 2 + 1]); // limit - } - } - } - if (U_SUCCESS(errorCode)) { - if (offset >= 0) { - offset += appendTo.length(); - } - appendTo += result; - } -#endif - return appendTo; -} U_NAMESPACE_END diff --git a/deps/icu-small/source/i18n/measfmt.cpp b/deps/icu-small/source/i18n/measfmt.cpp index a98a6dda4705b5..3e7f7bae157cf7 100644 --- a/deps/icu-small/source/i18n/measfmt.cpp +++ b/deps/icu-small/source/i18n/measfmt.cpp @@ -861,7 +861,7 @@ UnicodeString &MeasureFormat::formatMeasuresSlowTrack( return appendTo; } // Fix up FieldPosition indexes if our field is found. - if (offset != -1) { + if (fieldPositionFoundIndex != -1 && offset != -1) { pos.setBeginIndex(fpos.getBeginIndex() + offset); pos.setEndIndex(fpos.getEndIndex() + offset); } diff --git a/deps/icu-small/source/i18n/measunit.cpp b/deps/icu-small/source/i18n/measunit.cpp index 2486ca9b15a05e..dab3abb5e21ff6 100644 --- a/deps/icu-small/source/i18n/measunit.cpp +++ b/deps/icu-small/source/i18n/measunit.cpp @@ -33,9 +33,9 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(MeasureUnit) // update this code, refer to: // http://site.icu-project.org/design/formatting/measureformat/updating-measure-unit // -// Start generated code - +// Start generated code for measunit.cpp +// Maps from Type ID to offset in gSubTypes. static const int32_t gOffsets[] = { 0, 2, @@ -50,45 +50,20 @@ static const int32_t gOffsets[] = { 368, 370, 374, - 381, - 402, + 382, 404, - 418, - 421, - 427, - 437, - 441, - 445, - 447, - 474 + 408, + 423, + 424, + 430, + 440, + 444, + 448, + 450, + 484 }; -static const int32_t gIndexes[] = { - 0, - 2, - 7, - 17, - 25, - 29, - 29, - 40, - 56, - 60, - 69, - 71, - 75, - 82, - 103, - 105, - 119, - 122, - 128, - 138, - 142, - 146, - 148, - 175 -}; +static const int32_t kCurrencyOffset = 5; // Must be sorted alphabetically. static const char * const gTypes[] = { @@ -493,6 +468,7 @@ static const char * const gSubTypes[] = { "hertz", "kilohertz", "megahertz", + "dot", "dot-per-centimeter", "dot-per-inch", "em", @@ -503,6 +479,7 @@ static const char * const gSubTypes[] = { "astronomical-unit", "centimeter", "decimeter", + "earth-radius", "fathom", "foot", "furlong", @@ -521,11 +498,14 @@ static const char * const gSubTypes[] = { "point", "solar-radius", "yard", + "candela", + "lumen", "lux", "solar-luminosity", "carat", "dalton", "earth-mass", + "grain", "gram", "kilogram", "metric-ton", @@ -537,9 +517,7 @@ static const char * const gSubTypes[] = { "solar-mass", "stone", "ton", - "", // TODO(ICU-21076): manual edit of what should have been generated by Java. - "percent", // TODO(ICU-21076): regenerate, deal with duplication. - "permille", // TODO(ICU-21076): regenerate, deal with duplication. + "", "gigawatt", "horsepower", "kilowatt", @@ -580,35 +558,28 @@ static const char * const gSubTypes[] = { "cup", "cup-metric", "deciliter", + "dessert-spoon", + "dessert-spoon-imperial", + "dram", + "drop", "fluid-ounce", "fluid-ounce-imperial", "gallon", "gallon-imperial", "hectoliter", + "jigger", "liter", "megaliter", "milliliter", + "pinch", "pint", "pint-metric", "quart", + "quart-imperial", "tablespoon", "teaspoon" }; -// Must be sorted by first value and then second value. -static int32_t unitPerUnitToSingleUnit[][4] = { - {378, 382, 12, 5}, - {378, 387, 12, 6}, - {388, 343, 19, 0}, - {390, 350, 19, 2}, - {392, 343, 19, 3}, - {392, 463, 4, 2}, - {392, 464, 4, 3}, - {411, 460, 3, 1}, - {414, 12, 18, 9}, - {466, 388, 4, 1} -}; - // Shortcuts to the base unit in order to make the default constructor fast static const int32_t kBaseTypeIdx = 16; static const int32_t kBaseSubTypeIdx = 0; @@ -781,14 +752,6 @@ MeasureUnit MeasureUnit::getMole() { return MeasureUnit(3, 3); } -MeasureUnit *MeasureUnit::createPartPerMillion(UErrorCode &status) { - return MeasureUnit::create(3, 6, status); -} - -MeasureUnit MeasureUnit::getPartPerMillion() { - return MeasureUnit(3, 6); -} - MeasureUnit *MeasureUnit::createPercent(UErrorCode &status) { return MeasureUnit::create(3, 4, status); } @@ -805,6 +768,14 @@ MeasureUnit MeasureUnit::getPermille() { return MeasureUnit(3, 5); } +MeasureUnit *MeasureUnit::createPartPerMillion(UErrorCode &status) { + return MeasureUnit::create(3, 6, status); +} + +MeasureUnit MeasureUnit::getPartPerMillion() { + return MeasureUnit(3, 6); +} + MeasureUnit *MeasureUnit::createPermyriad(UErrorCode &status) { return MeasureUnit::create(3, 7, status); } @@ -1213,62 +1184,70 @@ MeasureUnit MeasureUnit::getMegahertz() { return MeasureUnit(11, 3); } -MeasureUnit *MeasureUnit::createDotPerCentimeter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createDot(UErrorCode &status) { return MeasureUnit::create(12, 0, status); } -MeasureUnit MeasureUnit::getDotPerCentimeter() { +MeasureUnit MeasureUnit::getDot() { return MeasureUnit(12, 0); } -MeasureUnit *MeasureUnit::createDotPerInch(UErrorCode &status) { +MeasureUnit *MeasureUnit::createDotPerCentimeter(UErrorCode &status) { return MeasureUnit::create(12, 1, status); } -MeasureUnit MeasureUnit::getDotPerInch() { +MeasureUnit MeasureUnit::getDotPerCentimeter() { return MeasureUnit(12, 1); } -MeasureUnit *MeasureUnit::createEm(UErrorCode &status) { +MeasureUnit *MeasureUnit::createDotPerInch(UErrorCode &status) { return MeasureUnit::create(12, 2, status); } -MeasureUnit MeasureUnit::getEm() { +MeasureUnit MeasureUnit::getDotPerInch() { return MeasureUnit(12, 2); } -MeasureUnit *MeasureUnit::createMegapixel(UErrorCode &status) { +MeasureUnit *MeasureUnit::createEm(UErrorCode &status) { return MeasureUnit::create(12, 3, status); } -MeasureUnit MeasureUnit::getMegapixel() { +MeasureUnit MeasureUnit::getEm() { return MeasureUnit(12, 3); } -MeasureUnit *MeasureUnit::createPixel(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMegapixel(UErrorCode &status) { return MeasureUnit::create(12, 4, status); } -MeasureUnit MeasureUnit::getPixel() { +MeasureUnit MeasureUnit::getMegapixel() { return MeasureUnit(12, 4); } -MeasureUnit *MeasureUnit::createPixelPerCentimeter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createPixel(UErrorCode &status) { return MeasureUnit::create(12, 5, status); } -MeasureUnit MeasureUnit::getPixelPerCentimeter() { +MeasureUnit MeasureUnit::getPixel() { return MeasureUnit(12, 5); } -MeasureUnit *MeasureUnit::createPixelPerInch(UErrorCode &status) { +MeasureUnit *MeasureUnit::createPixelPerCentimeter(UErrorCode &status) { return MeasureUnit::create(12, 6, status); } -MeasureUnit MeasureUnit::getPixelPerInch() { +MeasureUnit MeasureUnit::getPixelPerCentimeter() { return MeasureUnit(12, 6); } +MeasureUnit *MeasureUnit::createPixelPerInch(UErrorCode &status) { + return MeasureUnit::create(12, 7, status); +} + +MeasureUnit MeasureUnit::getPixelPerInch() { + return MeasureUnit(12, 7); +} + MeasureUnit *MeasureUnit::createAstronomicalUnit(UErrorCode &status) { return MeasureUnit::create(13, 0, status); } @@ -1293,166 +1272,190 @@ MeasureUnit MeasureUnit::getDecimeter() { return MeasureUnit(13, 2); } -MeasureUnit *MeasureUnit::createFathom(UErrorCode &status) { +MeasureUnit *MeasureUnit::createEarthRadius(UErrorCode &status) { return MeasureUnit::create(13, 3, status); } -MeasureUnit MeasureUnit::getFathom() { +MeasureUnit MeasureUnit::getEarthRadius() { return MeasureUnit(13, 3); } -MeasureUnit *MeasureUnit::createFoot(UErrorCode &status) { +MeasureUnit *MeasureUnit::createFathom(UErrorCode &status) { return MeasureUnit::create(13, 4, status); } -MeasureUnit MeasureUnit::getFoot() { +MeasureUnit MeasureUnit::getFathom() { return MeasureUnit(13, 4); } -MeasureUnit *MeasureUnit::createFurlong(UErrorCode &status) { +MeasureUnit *MeasureUnit::createFoot(UErrorCode &status) { return MeasureUnit::create(13, 5, status); } -MeasureUnit MeasureUnit::getFurlong() { +MeasureUnit MeasureUnit::getFoot() { return MeasureUnit(13, 5); } -MeasureUnit *MeasureUnit::createInch(UErrorCode &status) { +MeasureUnit *MeasureUnit::createFurlong(UErrorCode &status) { return MeasureUnit::create(13, 6, status); } -MeasureUnit MeasureUnit::getInch() { +MeasureUnit MeasureUnit::getFurlong() { return MeasureUnit(13, 6); } -MeasureUnit *MeasureUnit::createKilometer(UErrorCode &status) { +MeasureUnit *MeasureUnit::createInch(UErrorCode &status) { return MeasureUnit::create(13, 7, status); } -MeasureUnit MeasureUnit::getKilometer() { +MeasureUnit MeasureUnit::getInch() { return MeasureUnit(13, 7); } -MeasureUnit *MeasureUnit::createLightYear(UErrorCode &status) { +MeasureUnit *MeasureUnit::createKilometer(UErrorCode &status) { return MeasureUnit::create(13, 8, status); } -MeasureUnit MeasureUnit::getLightYear() { +MeasureUnit MeasureUnit::getKilometer() { return MeasureUnit(13, 8); } -MeasureUnit *MeasureUnit::createMeter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createLightYear(UErrorCode &status) { return MeasureUnit::create(13, 9, status); } -MeasureUnit MeasureUnit::getMeter() { +MeasureUnit MeasureUnit::getLightYear() { return MeasureUnit(13, 9); } -MeasureUnit *MeasureUnit::createMicrometer(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMeter(UErrorCode &status) { return MeasureUnit::create(13, 10, status); } -MeasureUnit MeasureUnit::getMicrometer() { +MeasureUnit MeasureUnit::getMeter() { return MeasureUnit(13, 10); } -MeasureUnit *MeasureUnit::createMile(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMicrometer(UErrorCode &status) { return MeasureUnit::create(13, 11, status); } -MeasureUnit MeasureUnit::getMile() { +MeasureUnit MeasureUnit::getMicrometer() { return MeasureUnit(13, 11); } -MeasureUnit *MeasureUnit::createMileScandinavian(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMile(UErrorCode &status) { return MeasureUnit::create(13, 12, status); } -MeasureUnit MeasureUnit::getMileScandinavian() { +MeasureUnit MeasureUnit::getMile() { return MeasureUnit(13, 12); } -MeasureUnit *MeasureUnit::createMillimeter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMileScandinavian(UErrorCode &status) { return MeasureUnit::create(13, 13, status); } -MeasureUnit MeasureUnit::getMillimeter() { +MeasureUnit MeasureUnit::getMileScandinavian() { return MeasureUnit(13, 13); } -MeasureUnit *MeasureUnit::createNanometer(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMillimeter(UErrorCode &status) { return MeasureUnit::create(13, 14, status); } -MeasureUnit MeasureUnit::getNanometer() { +MeasureUnit MeasureUnit::getMillimeter() { return MeasureUnit(13, 14); } -MeasureUnit *MeasureUnit::createNauticalMile(UErrorCode &status) { +MeasureUnit *MeasureUnit::createNanometer(UErrorCode &status) { return MeasureUnit::create(13, 15, status); } -MeasureUnit MeasureUnit::getNauticalMile() { +MeasureUnit MeasureUnit::getNanometer() { return MeasureUnit(13, 15); } -MeasureUnit *MeasureUnit::createParsec(UErrorCode &status) { +MeasureUnit *MeasureUnit::createNauticalMile(UErrorCode &status) { return MeasureUnit::create(13, 16, status); } -MeasureUnit MeasureUnit::getParsec() { +MeasureUnit MeasureUnit::getNauticalMile() { return MeasureUnit(13, 16); } -MeasureUnit *MeasureUnit::createPicometer(UErrorCode &status) { +MeasureUnit *MeasureUnit::createParsec(UErrorCode &status) { return MeasureUnit::create(13, 17, status); } -MeasureUnit MeasureUnit::getPicometer() { +MeasureUnit MeasureUnit::getParsec() { return MeasureUnit(13, 17); } -MeasureUnit *MeasureUnit::createPoint(UErrorCode &status) { +MeasureUnit *MeasureUnit::createPicometer(UErrorCode &status) { return MeasureUnit::create(13, 18, status); } -MeasureUnit MeasureUnit::getPoint() { +MeasureUnit MeasureUnit::getPicometer() { return MeasureUnit(13, 18); } -MeasureUnit *MeasureUnit::createSolarRadius(UErrorCode &status) { +MeasureUnit *MeasureUnit::createPoint(UErrorCode &status) { return MeasureUnit::create(13, 19, status); } -MeasureUnit MeasureUnit::getSolarRadius() { +MeasureUnit MeasureUnit::getPoint() { return MeasureUnit(13, 19); } -MeasureUnit *MeasureUnit::createYard(UErrorCode &status) { +MeasureUnit *MeasureUnit::createSolarRadius(UErrorCode &status) { return MeasureUnit::create(13, 20, status); } -MeasureUnit MeasureUnit::getYard() { +MeasureUnit MeasureUnit::getSolarRadius() { return MeasureUnit(13, 20); } -MeasureUnit *MeasureUnit::createLux(UErrorCode &status) { +MeasureUnit *MeasureUnit::createYard(UErrorCode &status) { + return MeasureUnit::create(13, 21, status); +} + +MeasureUnit MeasureUnit::getYard() { + return MeasureUnit(13, 21); +} + +MeasureUnit *MeasureUnit::createCandela(UErrorCode &status) { return MeasureUnit::create(14, 0, status); } -MeasureUnit MeasureUnit::getLux() { +MeasureUnit MeasureUnit::getCandela() { return MeasureUnit(14, 0); } -MeasureUnit *MeasureUnit::createSolarLuminosity(UErrorCode &status) { +MeasureUnit *MeasureUnit::createLumen(UErrorCode &status) { return MeasureUnit::create(14, 1, status); } -MeasureUnit MeasureUnit::getSolarLuminosity() { +MeasureUnit MeasureUnit::getLumen() { return MeasureUnit(14, 1); } +MeasureUnit *MeasureUnit::createLux(UErrorCode &status) { + return MeasureUnit::create(14, 2, status); +} + +MeasureUnit MeasureUnit::getLux() { + return MeasureUnit(14, 2); +} + +MeasureUnit *MeasureUnit::createSolarLuminosity(UErrorCode &status) { + return MeasureUnit::create(14, 3, status); +} + +MeasureUnit MeasureUnit::getSolarLuminosity() { + return MeasureUnit(14, 3); +} + MeasureUnit *MeasureUnit::createCarat(UErrorCode &status) { return MeasureUnit::create(15, 0, status); } @@ -1477,94 +1480,102 @@ MeasureUnit MeasureUnit::getEarthMass() { return MeasureUnit(15, 2); } -MeasureUnit *MeasureUnit::createGram(UErrorCode &status) { +MeasureUnit *MeasureUnit::createGrain(UErrorCode &status) { return MeasureUnit::create(15, 3, status); } -MeasureUnit MeasureUnit::getGram() { +MeasureUnit MeasureUnit::getGrain() { return MeasureUnit(15, 3); } -MeasureUnit *MeasureUnit::createKilogram(UErrorCode &status) { +MeasureUnit *MeasureUnit::createGram(UErrorCode &status) { return MeasureUnit::create(15, 4, status); } -MeasureUnit MeasureUnit::getKilogram() { +MeasureUnit MeasureUnit::getGram() { return MeasureUnit(15, 4); } -MeasureUnit *MeasureUnit::createMetricTon(UErrorCode &status) { +MeasureUnit *MeasureUnit::createKilogram(UErrorCode &status) { return MeasureUnit::create(15, 5, status); } -MeasureUnit MeasureUnit::getMetricTon() { +MeasureUnit MeasureUnit::getKilogram() { return MeasureUnit(15, 5); } -MeasureUnit *MeasureUnit::createMicrogram(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMetricTon(UErrorCode &status) { return MeasureUnit::create(15, 6, status); } -MeasureUnit MeasureUnit::getMicrogram() { +MeasureUnit MeasureUnit::getMetricTon() { return MeasureUnit(15, 6); } -MeasureUnit *MeasureUnit::createMilligram(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMicrogram(UErrorCode &status) { return MeasureUnit::create(15, 7, status); } -MeasureUnit MeasureUnit::getMilligram() { +MeasureUnit MeasureUnit::getMicrogram() { return MeasureUnit(15, 7); } -MeasureUnit *MeasureUnit::createOunce(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMilligram(UErrorCode &status) { return MeasureUnit::create(15, 8, status); } -MeasureUnit MeasureUnit::getOunce() { +MeasureUnit MeasureUnit::getMilligram() { return MeasureUnit(15, 8); } -MeasureUnit *MeasureUnit::createOunceTroy(UErrorCode &status) { +MeasureUnit *MeasureUnit::createOunce(UErrorCode &status) { return MeasureUnit::create(15, 9, status); } -MeasureUnit MeasureUnit::getOunceTroy() { +MeasureUnit MeasureUnit::getOunce() { return MeasureUnit(15, 9); } -MeasureUnit *MeasureUnit::createPound(UErrorCode &status) { +MeasureUnit *MeasureUnit::createOunceTroy(UErrorCode &status) { return MeasureUnit::create(15, 10, status); } -MeasureUnit MeasureUnit::getPound() { +MeasureUnit MeasureUnit::getOunceTroy() { return MeasureUnit(15, 10); } -MeasureUnit *MeasureUnit::createSolarMass(UErrorCode &status) { +MeasureUnit *MeasureUnit::createPound(UErrorCode &status) { return MeasureUnit::create(15, 11, status); } -MeasureUnit MeasureUnit::getSolarMass() { +MeasureUnit MeasureUnit::getPound() { return MeasureUnit(15, 11); } -MeasureUnit *MeasureUnit::createStone(UErrorCode &status) { +MeasureUnit *MeasureUnit::createSolarMass(UErrorCode &status) { return MeasureUnit::create(15, 12, status); } -MeasureUnit MeasureUnit::getStone() { +MeasureUnit MeasureUnit::getSolarMass() { return MeasureUnit(15, 12); } -MeasureUnit *MeasureUnit::createTon(UErrorCode &status) { +MeasureUnit *MeasureUnit::createStone(UErrorCode &status) { return MeasureUnit::create(15, 13, status); } -MeasureUnit MeasureUnit::getTon() { +MeasureUnit MeasureUnit::getStone() { return MeasureUnit(15, 13); } +MeasureUnit *MeasureUnit::createTon(UErrorCode &status) { + return MeasureUnit::create(15, 14, status); +} + +MeasureUnit MeasureUnit::getTon() { + return MeasureUnit(15, 14); +} + MeasureUnit *MeasureUnit::createGigawatt(UErrorCode &status) { return MeasureUnit::create(17, 0, status); } @@ -1885,111 +1896,167 @@ MeasureUnit MeasureUnit::getDeciliter() { return MeasureUnit(22, 13); } -MeasureUnit *MeasureUnit::createFluidOunce(UErrorCode &status) { +MeasureUnit *MeasureUnit::createDessertSpoon(UErrorCode &status) { return MeasureUnit::create(22, 14, status); } -MeasureUnit MeasureUnit::getFluidOunce() { +MeasureUnit MeasureUnit::getDessertSpoon() { return MeasureUnit(22, 14); } -MeasureUnit *MeasureUnit::createFluidOunceImperial(UErrorCode &status) { +MeasureUnit *MeasureUnit::createDessertSpoonImperial(UErrorCode &status) { return MeasureUnit::create(22, 15, status); } -MeasureUnit MeasureUnit::getFluidOunceImperial() { +MeasureUnit MeasureUnit::getDessertSpoonImperial() { return MeasureUnit(22, 15); } -MeasureUnit *MeasureUnit::createGallon(UErrorCode &status) { +MeasureUnit *MeasureUnit::createDram(UErrorCode &status) { return MeasureUnit::create(22, 16, status); } -MeasureUnit MeasureUnit::getGallon() { +MeasureUnit MeasureUnit::getDram() { return MeasureUnit(22, 16); } -MeasureUnit *MeasureUnit::createGallonImperial(UErrorCode &status) { +MeasureUnit *MeasureUnit::createDrop(UErrorCode &status) { return MeasureUnit::create(22, 17, status); } -MeasureUnit MeasureUnit::getGallonImperial() { +MeasureUnit MeasureUnit::getDrop() { return MeasureUnit(22, 17); } -MeasureUnit *MeasureUnit::createHectoliter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createFluidOunce(UErrorCode &status) { return MeasureUnit::create(22, 18, status); } -MeasureUnit MeasureUnit::getHectoliter() { +MeasureUnit MeasureUnit::getFluidOunce() { return MeasureUnit(22, 18); } -MeasureUnit *MeasureUnit::createLiter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createFluidOunceImperial(UErrorCode &status) { return MeasureUnit::create(22, 19, status); } -MeasureUnit MeasureUnit::getLiter() { +MeasureUnit MeasureUnit::getFluidOunceImperial() { return MeasureUnit(22, 19); } -MeasureUnit *MeasureUnit::createMegaliter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createGallon(UErrorCode &status) { return MeasureUnit::create(22, 20, status); } -MeasureUnit MeasureUnit::getMegaliter() { +MeasureUnit MeasureUnit::getGallon() { return MeasureUnit(22, 20); } -MeasureUnit *MeasureUnit::createMilliliter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createGallonImperial(UErrorCode &status) { return MeasureUnit::create(22, 21, status); } -MeasureUnit MeasureUnit::getMilliliter() { +MeasureUnit MeasureUnit::getGallonImperial() { return MeasureUnit(22, 21); } -MeasureUnit *MeasureUnit::createPint(UErrorCode &status) { +MeasureUnit *MeasureUnit::createHectoliter(UErrorCode &status) { return MeasureUnit::create(22, 22, status); } -MeasureUnit MeasureUnit::getPint() { +MeasureUnit MeasureUnit::getHectoliter() { return MeasureUnit(22, 22); } -MeasureUnit *MeasureUnit::createPintMetric(UErrorCode &status) { +MeasureUnit *MeasureUnit::createJigger(UErrorCode &status) { return MeasureUnit::create(22, 23, status); } -MeasureUnit MeasureUnit::getPintMetric() { +MeasureUnit MeasureUnit::getJigger() { return MeasureUnit(22, 23); } -MeasureUnit *MeasureUnit::createQuart(UErrorCode &status) { +MeasureUnit *MeasureUnit::createLiter(UErrorCode &status) { return MeasureUnit::create(22, 24, status); } -MeasureUnit MeasureUnit::getQuart() { +MeasureUnit MeasureUnit::getLiter() { return MeasureUnit(22, 24); } -MeasureUnit *MeasureUnit::createTablespoon(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMegaliter(UErrorCode &status) { return MeasureUnit::create(22, 25, status); } -MeasureUnit MeasureUnit::getTablespoon() { +MeasureUnit MeasureUnit::getMegaliter() { return MeasureUnit(22, 25); } -MeasureUnit *MeasureUnit::createTeaspoon(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMilliliter(UErrorCode &status) { return MeasureUnit::create(22, 26, status); } -MeasureUnit MeasureUnit::getTeaspoon() { +MeasureUnit MeasureUnit::getMilliliter() { return MeasureUnit(22, 26); } -// End generated code +MeasureUnit *MeasureUnit::createPinch(UErrorCode &status) { + return MeasureUnit::create(22, 27, status); +} + +MeasureUnit MeasureUnit::getPinch() { + return MeasureUnit(22, 27); +} + +MeasureUnit *MeasureUnit::createPint(UErrorCode &status) { + return MeasureUnit::create(22, 28, status); +} + +MeasureUnit MeasureUnit::getPint() { + return MeasureUnit(22, 28); +} + +MeasureUnit *MeasureUnit::createPintMetric(UErrorCode &status) { + return MeasureUnit::create(22, 29, status); +} + +MeasureUnit MeasureUnit::getPintMetric() { + return MeasureUnit(22, 29); +} + +MeasureUnit *MeasureUnit::createQuart(UErrorCode &status) { + return MeasureUnit::create(22, 30, status); +} + +MeasureUnit MeasureUnit::getQuart() { + return MeasureUnit(22, 30); +} + +MeasureUnit *MeasureUnit::createQuartImperial(UErrorCode &status) { + return MeasureUnit::create(22, 31, status); +} + +MeasureUnit MeasureUnit::getQuartImperial() { + return MeasureUnit(22, 31); +} + +MeasureUnit *MeasureUnit::createTablespoon(UErrorCode &status) { + return MeasureUnit::create(22, 32, status); +} + +MeasureUnit MeasureUnit::getTablespoon() { + return MeasureUnit(22, 32); +} + +MeasureUnit *MeasureUnit::createTeaspoon(UErrorCode &status) { + return MeasureUnit::create(22, 33, status); +} + +MeasureUnit MeasureUnit::getTeaspoon() { + return MeasureUnit(22, 33); +} + +// End generated code for measunit.cpp static int32_t binarySearch( const char * const * array, int32_t start, int32_t end, StringPiece key) { @@ -2107,10 +2174,6 @@ UBool MeasureUnit::operator==(const UObject& other) const { return uprv_strcmp(getIdentifier(), rhs.getIdentifier()) == 0; } -int32_t MeasureUnit::getIndex() const { - return gIndexes[fTypeId] + fSubTypeId; -} - int32_t MeasureUnit::getAvailable( MeasureUnit *dest, int32_t destCapacity, @@ -2173,26 +2236,14 @@ StringEnumeration* MeasureUnit::getAvailableTypes(UErrorCode &errorCode) { return result; } -int32_t MeasureUnit::getIndexCount() { - return gIndexes[UPRV_LENGTHOF(gIndexes) - 1]; -} - -int32_t MeasureUnit::internalGetIndexForTypeAndSubtype(const char *type, const char *subtype) { - int32_t t = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), type); - if (t < 0) { - return t; - } - int32_t st = binarySearch(gSubTypes, gOffsets[t], gOffsets[t + 1], subtype); - if (st < 0) { - return st; - } - return gIndexes[t] + st - gOffsets[t]; -} - bool MeasureUnit::findBySubType(StringPiece subType, MeasureUnit* output) { + // Sanity checking kCurrencyOffset and final entry in gOffsets + U_ASSERT(uprv_strcmp(gTypes[kCurrencyOffset], "currency") == 0); + U_ASSERT(gOffsets[UPRV_LENGTHOF(gOffsets) - 1] == UPRV_LENGTHOF(gSubTypes)); + for (int32_t t = 0; t < UPRV_LENGTHOF(gOffsets) - 1; t++) { // Skip currency units - if (gIndexes[t] == gIndexes[t + 1]) { + if (t == kCurrencyOffset) { continue; } int32_t st = binarySearch(gSubTypes, gOffsets[t], gOffsets[t + 1], subType); @@ -2204,41 +2255,6 @@ bool MeasureUnit::findBySubType(StringPiece subType, MeasureUnit* output) { return false; } -MeasureUnit MeasureUnit::resolveUnitPerUnit( - const MeasureUnit &unit, const MeasureUnit &perUnit, bool* isResolved) { - int32_t unitOffset = unit.getOffset(); - int32_t perUnitOffset = perUnit.getOffset(); - if (unitOffset == -1 || perUnitOffset == -1) { - *isResolved = false; - return MeasureUnit(); - } - - // binary search for (unitOffset, perUnitOffset) - int32_t start = 0; - int32_t end = UPRV_LENGTHOF(unitPerUnitToSingleUnit); - while (start < end) { - int32_t mid = (start + end) / 2; - int32_t *midRow = unitPerUnitToSingleUnit[mid]; - if (unitOffset < midRow[0]) { - end = mid; - } else if (unitOffset > midRow[0]) { - start = mid + 1; - } else if (perUnitOffset < midRow[1]) { - end = mid; - } else if (perUnitOffset > midRow[1]) { - start = mid + 1; - } else { - // We found a resolution for our unit / per-unit combo - // return it. - *isResolved = true; - return MeasureUnit(midRow[2], midRow[3]); - } - } - - *isResolved = false; - return MeasureUnit(); -} - MeasureUnit *MeasureUnit::create(int typeId, int subTypeId, UErrorCode &status) { if (U_FAILURE(status)) { return NULL; @@ -2279,15 +2295,6 @@ void MeasureUnit::initCurrency(StringPiece isoCurrency) { fSubTypeId = result - gOffsets[fTypeId]; } -void MeasureUnit::initNoUnit(const char *subtype) { - int32_t result = binarySearch(gTypes, 0, UPRV_LENGTHOF(gTypes), "none"); - U_ASSERT(result != -1); - fTypeId = result; - result = binarySearch(gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], subtype); - U_ASSERT(result != -1); - fSubTypeId = result - gOffsets[fTypeId]; -} - void MeasureUnit::setTo(int32_t typeId, int32_t subTypeId) { fTypeId = typeId; fSubTypeId = subTypeId; @@ -2302,6 +2309,20 @@ int32_t MeasureUnit::getOffset() const { return gOffsets[fTypeId] + fSubTypeId; } +MeasureUnitImpl MeasureUnitImpl::copy(UErrorCode &status) const { + MeasureUnitImpl result; + result.complexity = complexity; + result.identifier.append(identifier, status); + for (int32_t i = 0; i < units.length(); i++) { + SingleUnitImpl *item = result.units.emplaceBack(*units[i]); + if (!item) { + status = U_MEMORY_ALLOCATION_ERROR; + return result; + } + } + return result; +} + U_NAMESPACE_END #endif /* !UNCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/measunit_extra.cpp b/deps/icu-small/source/i18n/measunit_extra.cpp index aeb60017a18fce..2eb3f066142967 100644 --- a/deps/icu-small/source/i18n/measunit_extra.cpp +++ b/deps/icu-small/source/i18n/measunit_extra.cpp @@ -12,20 +12,25 @@ // Helpful in toString methods and elsewhere. #define UNISTR_FROM_STRING_EXPLICIT -#include +#include "charstr.h" +#include "cmemory.h" #include "cstring.h" #include "measunit_impl.h" +#include "resource.h" #include "uarrsort.h" #include "uassert.h" #include "ucln_in.h" #include "umutex.h" -#include "unicode/errorcode.h" +#include "unicode/bytestrie.h" +#include "unicode/bytestriebuilder.h" #include "unicode/localpointer.h" #include "unicode/measunit.h" -#include "unicode/ucharstrie.h" -#include "unicode/ucharstriebuilder.h" - -#include "cstr.h" +#include "unicode/stringpiece.h" +#include "unicode/stringtriebuilder.h" +#include "unicode/ures.h" +#include "unicode/ustringtrie.h" +#include "uresimp.h" +#include U_NAMESPACE_BEGIN @@ -60,7 +65,7 @@ enum InitialCompoundPart { INITIAL_COMPOUND_PART_PER = kInitialCompoundPartOffset, }; -// Trie value offset for powers like "square-", "cubic-", "p2-" etc. +// Trie value offset for powers like "square-", "cubic-", "pow2-" etc. constexpr int32_t kPowerPartOffset = 256; enum PowerPart { @@ -110,119 +115,101 @@ const struct SIPrefixStrings { { "yocto", UMEASURE_SI_PREFIX_YOCTO }, }; -// TODO(ICU-21059): Get this list from data -const char16_t* const gSimpleUnits[] = { - u"candela", - u"carat", - u"gram", - u"ounce", - u"ounce-troy", - u"pound", - u"kilogram", - u"stone", - u"ton", - u"metric-ton", - u"earth-mass", - u"solar-mass", - u"point", - u"inch", - u"foot", - u"yard", - u"meter", - u"fathom", - u"furlong", - u"mile", - u"nautical-mile", - u"mile-scandinavian", - u"100-kilometer", - u"earth-radius", - u"solar-radius", - u"astronomical-unit", - u"light-year", - u"parsec", - u"second", - u"minute", - u"hour", - u"day", - u"day-person", - u"week", - u"week-person", - u"month", - u"month-person", - u"year", - u"year-person", - u"decade", - u"century", - u"ampere", - u"fahrenheit", - u"kelvin", - u"celsius", - u"arc-second", - u"arc-minute", - u"degree", - u"radian", - u"revolution", - u"item", - u"mole", - u"permillion", - u"permyriad", - u"permille", - u"percent", - u"karat", - u"portion", - u"bit", - u"byte", - u"dot", - u"pixel", - u"em", - u"hertz", - u"newton", - u"pound-force", - u"pascal", - u"bar", - u"atmosphere", - u"ofhg", - u"electronvolt", - u"dalton", - u"joule", - u"calorie", - u"british-thermal-unit", - u"foodcalorie", - u"therm-us", - u"watt", - u"horsepower", - u"solar-luminosity", - u"volt", - u"ohm", - u"dunam", - u"acre", - u"hectare", - u"teaspoon", - u"tablespoon", - u"fluid-ounce-imperial", - u"fluid-ounce", - u"cup", - u"cup-metric", - u"pint", - u"pint-metric", - u"quart", - u"liter", - u"gallon", - u"gallon-imperial", - u"bushel", - u"barrel", - u"knot", - u"g-force", - u"lux", +/** + * A ResourceSink that collects simple unit identifiers from the keys of the + * convertUnits table into an array, and adds these values to a TrieBuilder, + * with associated values being their index into this array plus a specified + * offset, to a trie. + * + * Example code: + * + * UErrorCode status = U_ZERO_ERROR; + * BytesTrieBuilder b(status); + * const char *unitIdentifiers[200]; + * SimpleUnitIdentifiersSink identifierSink(unitIdentifiers, 200, b, kTrieValueOffset); + * LocalUResourceBundlePointer unitsBundle(ures_openDirect(NULL, "units", &status)); + * ures_getAllItemsWithFallback(unitsBundle.getAlias(), "convertUnits", identifierSink, status); + */ +class SimpleUnitIdentifiersSink : public icu::ResourceSink { + public: + /** + * Constructor. + * @param out Array of char* to which the simple unit identifiers will be + * saved. + * @param outSize The size of `out`. + * @param trieBuilder The trie builder to which the simple unit identifier + * should be added. The trie builder must outlive this resource sink. + * @param trieValueOffset This is added to the index of the identifier in + * the `out` array, before adding to `trieBuilder` as the value + * associated with the identifier. + */ + explicit SimpleUnitIdentifiersSink(const char **out, int32_t outSize, BytesTrieBuilder &trieBuilder, + int32_t trieValueOffset) + : outArray(out), outSize(outSize), trieBuilder(trieBuilder), trieValueOffset(trieValueOffset), + outIndex(0) { + } + + /** + * Adds the table keys found in value to the output vector. + * @param key The key of the resource passed to `value`: the second + * parameter of the ures_getAllItemsWithFallback() call. + * @param value Should be a ResourceTable value, if + * ures_getAllItemsWithFallback() was called correctly for this sink. + * @param noFallback Ignored. + * @param status The standard ICU error code output parameter. + */ + void put(const char * /*key*/, ResourceValue &value, UBool /*noFallback*/, UErrorCode &status) { + ResourceTable table = value.getTable(status); + if (U_FAILURE(status)) return; + + if (outIndex + table.getSize() > outSize) { + status = U_INDEX_OUTOFBOUNDS_ERROR; + return; + } + + // Collect keys from the table resource. + const char *key; + for (int32_t i = 0; table.getKeyAndValue(i, key, value); ++i) { + U_ASSERT(i < table.getSize()); + U_ASSERT(outIndex < outSize); + if (uprv_strcmp(key, "kilogram") == 0) { + // For parsing, we use "gram", the prefixless metric mass unit. We + // thus ignore the SI Base Unit of Mass: it exists due to being the + // mass conversion target unit, but not needed for MeasureUnit + // parsing. + continue; + } + outArray[outIndex] = key; + trieBuilder.add(key, trieValueOffset + outIndex, status); + outIndex++; + } + } + + private: + const char **outArray; + int32_t outSize; + BytesTrieBuilder &trieBuilder; + int32_t trieValueOffset; + + int32_t outIndex; }; icu::UInitOnce gUnitExtrasInitOnce = U_INITONCE_INITIALIZER; -char16_t* kSerializedUnitExtrasStemTrie = nullptr; +// Array of simple unit IDs. +// +// The array memory itself is owned by this pointer, but the individual char* in +// that array point at static memory. (Note that these char* are also returned +// by SingleUnitImpl::getSimpleUnitID().) +const char **gSimpleUnits = nullptr; + +char *gSerializedUnitExtrasStemTrie = nullptr; UBool U_CALLCONV cleanupUnitExtras() { - uprv_free(kSerializedUnitExtrasStemTrie); - kSerializedUnitExtrasStemTrie = nullptr; + uprv_free(gSerializedUnitExtrasStemTrie); + gSerializedUnitExtrasStemTrie = nullptr; + uprv_free(gSimpleUnits); + gSimpleUnits = nullptr; gUnitExtrasInitOnce.reset(); return TRUE; } @@ -230,55 +217,75 @@ UBool U_CALLCONV cleanupUnitExtras() { void U_CALLCONV initUnitExtras(UErrorCode& status) { ucln_i18n_registerCleanup(UCLN_I18N_UNIT_EXTRAS, cleanupUnitExtras); - UCharsTrieBuilder b(status); + BytesTrieBuilder b(status); if (U_FAILURE(status)) { return; } // Add SI prefixes for (const auto& siPrefixInfo : gSIPrefixStrings) { - UnicodeString uSIPrefix(siPrefixInfo.string, -1, US_INV); - b.add(uSIPrefix, siPrefixInfo.value + kSIPrefixOffset, status); + b.add(siPrefixInfo.string, siPrefixInfo.value + kSIPrefixOffset, status); } if (U_FAILURE(status)) { return; } // Add syntax parts (compound, power prefixes) - b.add(u"-per-", COMPOUND_PART_PER, status); - b.add(u"-", COMPOUND_PART_TIMES, status); - b.add(u"-and-", COMPOUND_PART_AND, status); - b.add(u"per-", INITIAL_COMPOUND_PART_PER, status); - b.add(u"square-", POWER_PART_P2, status); - b.add(u"cubic-", POWER_PART_P3, status); - b.add(u"p2-", POWER_PART_P2, status); - b.add(u"p3-", POWER_PART_P3, status); - b.add(u"p4-", POWER_PART_P4, status); - b.add(u"p5-", POWER_PART_P5, status); - b.add(u"p6-", POWER_PART_P6, status); - b.add(u"p7-", POWER_PART_P7, status); - b.add(u"p8-", POWER_PART_P8, status); - b.add(u"p9-", POWER_PART_P9, status); - b.add(u"p10-", POWER_PART_P10, status); - b.add(u"p11-", POWER_PART_P11, status); - b.add(u"p12-", POWER_PART_P12, status); - b.add(u"p13-", POWER_PART_P13, status); - b.add(u"p14-", POWER_PART_P14, status); - b.add(u"p15-", POWER_PART_P15, status); + b.add("-per-", COMPOUND_PART_PER, status); + b.add("-", COMPOUND_PART_TIMES, status); + b.add("-and-", COMPOUND_PART_AND, status); + b.add("per-", INITIAL_COMPOUND_PART_PER, status); + b.add("square-", POWER_PART_P2, status); + b.add("cubic-", POWER_PART_P3, status); + b.add("pow2-", POWER_PART_P2, status); + b.add("pow3-", POWER_PART_P3, status); + b.add("pow4-", POWER_PART_P4, status); + b.add("pow5-", POWER_PART_P5, status); + b.add("pow6-", POWER_PART_P6, status); + b.add("pow7-", POWER_PART_P7, status); + b.add("pow8-", POWER_PART_P8, status); + b.add("pow9-", POWER_PART_P9, status); + b.add("pow10-", POWER_PART_P10, status); + b.add("pow11-", POWER_PART_P11, status); + b.add("pow12-", POWER_PART_P12, status); + b.add("pow13-", POWER_PART_P13, status); + b.add("pow14-", POWER_PART_P14, status); + b.add("pow15-", POWER_PART_P15, status); + if (U_FAILURE(status)) { return; } + + // Add sanctioned simple units by offset: simple units all have entries in + // units/convertUnits resources. + // TODO(ICU-21059): confirm whether this is clean enough, or whether we need to + // filter units' validity list instead. + LocalUResourceBundlePointer unitsBundle(ures_openDirect(NULL, "units", &status)); + LocalUResourceBundlePointer convertUnits( + ures_getByKey(unitsBundle.getAlias(), "convertUnits", NULL, &status)); if (U_FAILURE(status)) { return; } - // Add sanctioned simple units by offset - int32_t simpleUnitOffset = kSimpleUnitOffset; - for (auto simpleUnit : gSimpleUnits) { - b.add(simpleUnit, simpleUnitOffset++, status); + // Allocate enough space: with identifierSink below skipping kilogram, we're + // probably allocating one more than needed. + int32_t simpleUnitsCount = convertUnits.getAlias()->fSize; + int32_t arrayMallocSize = sizeof(char *) * simpleUnitsCount; + gSimpleUnits = static_cast(uprv_malloc(arrayMallocSize)); + if (gSimpleUnits == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; } + uprv_memset(gSimpleUnits, 0, arrayMallocSize); + + // Populate gSimpleUnits and build the associated trie. + SimpleUnitIdentifiersSink identifierSink(gSimpleUnits, simpleUnitsCount, b, kSimpleUnitOffset); + ures_getAllItemsWithFallback(unitsBundle.getAlias(), "convertUnits", identifierSink, status); // Build the CharsTrie // TODO: Use SLOW or FAST here? - UnicodeString result; - b.buildUnicodeString(USTRINGTRIE_BUILD_FAST, result, status); + StringPiece result = b.buildStringPiece(USTRINGTRIE_BUILD_FAST, status); if (U_FAILURE(status)) { return; } // Copy the result into the global constant pointer - size_t numBytes = result.length() * sizeof(char16_t); - kSerializedUnitExtrasStemTrie = static_cast(uprv_malloc(numBytes)); - uprv_memcpy(kSerializedUnitExtrasStemTrie, result.getBuffer(), numBytes); + size_t numBytes = result.length(); + gSerializedUnitExtrasStemTrie = static_cast(uprv_malloc(numBytes)); + if (gSerializedUnitExtrasStemTrie == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + uprv_memcpy(gSerializedUnitExtrasStemTrie, result.data(), numBytes); } class Token { @@ -385,7 +392,7 @@ class Parser { // should live longer than this Parser - and the parser shouldn't return any // references to that string. StringPiece fSource; - UCharsTrie fTrie; + BytesTrie fTrie; // Set to true when we've seen a "-per-" or a "per-", after which all units // are in the denominator. Until we find an "-and-", at which point the @@ -395,7 +402,7 @@ class Parser { Parser() : fSource(""), fTrie(u"") {} Parser(StringPiece source) - : fSource(source), fTrie(kSerializedUnitExtrasStemTrie) {} + : fSource(source), fTrie(gSerializedUnitExtrasStemTrie) {} inline bool hasNext() const { return fIndex < fSource.length(); @@ -640,11 +647,11 @@ void serializeSingle(const SingleUnitImpl& singleUnit, bool first, CharString& o } else if (posPower == 3) { output.append("cubic-", status); } else if (posPower < 10) { - output.append('p', status); + output.append("pow", status); output.append(posPower + '0', status); output.append('-', status); } else if (posPower <= 15) { - output.append("p1", status); + output.append("pow1", status); output.append('0' + (posPower % 10), status); output.append('-', status); } else { @@ -666,7 +673,7 @@ void serializeSingle(const SingleUnitImpl& singleUnit, bool first, CharString& o return; } - output.appendInvariantChars(gSimpleUnits[singleUnit.index], status); + output.append(singleUnit.getSimpleUnitID(), status); } /** @@ -777,6 +784,17 @@ MeasureUnit SingleUnitImpl::build(UErrorCode& status) const { return std::move(temp).build(status); } +const char *SingleUnitImpl::getSimpleUnitID() const { + return gSimpleUnits[index]; +} + +MeasureUnitImpl::MeasureUnitImpl(const MeasureUnitImpl &other, UErrorCode &status) { + *this = other.copy(status); +} + +MeasureUnitImpl::MeasureUnitImpl(const SingleUnitImpl &singleUnit, UErrorCode &status) { + this->append(singleUnit, status); +} MeasureUnitImpl MeasureUnitImpl::forIdentifier(StringPiece identifier, UErrorCode& status) { return Parser::from(identifier, status).parse(status); @@ -813,12 +831,26 @@ bool MeasureUnitImpl::append(const SingleUnitImpl& singleUnit, UErrorCode& statu return appendImpl(*this, singleUnit, status); } +MaybeStackVector MeasureUnitImpl::extractIndividualUnits(UErrorCode &status) const { + MaybeStackVector result; + + if (this->complexity != UMeasureUnitComplexity::UMEASURE_UNIT_MIXED) { + result.emplaceBackAndCheckErrorCode(status, *this, status); + return result; + } + + for (int32_t i = 0; i < units.length(); i++) { + result.emplaceBackAndCheckErrorCode(status, *units[i], status); + } + + return result; +} + MeasureUnit MeasureUnitImpl::build(UErrorCode& status) && { serialize(*this, status); return MeasureUnit(std::move(*this)); } - MeasureUnit MeasureUnit::forIdentifier(StringPiece identifier, UErrorCode& status) { return Parser::from(identifier, status).parse(status).build(status); } @@ -876,11 +908,15 @@ MeasureUnit MeasureUnit::product(const MeasureUnit& other, UErrorCode& status) c return std::move(impl).build(status); } -LocalArray MeasureUnit::splitToSingleUnits(int32_t& outCount, UErrorCode& status) const { +LocalArray MeasureUnit::splitToSingleUnitsImpl(int32_t& outCount, UErrorCode& status) const { MeasureUnitImpl temp; const MeasureUnitImpl& impl = MeasureUnitImpl::forMeasureUnit(*this, temp, status); outCount = impl.units.length(); MeasureUnit* arr = new MeasureUnit[outCount]; + if (arr == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return LocalArray(); + } for (int32_t i = 0; i < outCount; i++) { arr[i] = impl.units[i]->build(status); } diff --git a/deps/icu-small/source/i18n/measunit_impl.h b/deps/icu-small/source/i18n/measunit_impl.h index c886d3c29a38b2..1024cd65547ff1 100644 --- a/deps/icu-small/source/i18n/measunit_impl.h +++ b/deps/icu-small/source/i18n/measunit_impl.h @@ -22,7 +22,7 @@ static const char kDefaultCurrency8[] = "XXX"; /** * A struct representing a single unit (optional SI prefix and dimensionality). */ -struct SingleUnitImpl : public UMemory { +struct U_I18N_API SingleUnitImpl : public UMemory { /** * Gets a single unit from the MeasureUnit. If there are multiple single units, sets an error * code and returns the base dimensionless unit. Parses if necessary. @@ -32,6 +32,16 @@ struct SingleUnitImpl : public UMemory { /** Transform this SingleUnitImpl into a MeasureUnit, simplifying if possible. */ MeasureUnit build(UErrorCode& status) const; + /** + * Returns the "simple unit ID", without SI or dimensionality prefix: this + * instance may represent a square-kilometer, but only "meter" will be + * returned. + * + * The returned pointer points at memory that exists for the duration of the + * program's running. + */ + const char *getSimpleUnitID() const; + /** * Compare this SingleUnitImpl to another SingleUnitImpl for the sake of * sorting and coalescing. @@ -110,12 +120,27 @@ struct SingleUnitImpl : public UMemory { int32_t dimensionality = 1; }; +// Export explicit template instantiations of MaybeStackArray, MemoryPool and +// MaybeStackVector. This is required when building DLLs for Windows. (See +// datefmt.h, collationiterator.h, erarules.h and others for similar examples.) +#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN +template class U_I18N_API MaybeStackArray; +template class U_I18N_API MemoryPool; +template class U_I18N_API MaybeStackVector; +#endif /** * Internal representation of measurement units. Capable of representing all complexities of units, * including mixed and compound units. */ -struct MeasureUnitImpl : public UMemory { +struct U_I18N_API MeasureUnitImpl : public UMemory { + MeasureUnitImpl() = default; + MeasureUnitImpl(MeasureUnitImpl &&other) = default; + MeasureUnitImpl(const MeasureUnitImpl &other, UErrorCode &status); + MeasureUnitImpl(const SingleUnitImpl &singleUnit, UErrorCode &status); + + MeasureUnitImpl &operator=(MeasureUnitImpl &&other) noexcept = default; + /** Extract the MeasureUnitImpl from a MeasureUnit. */ static inline const MeasureUnitImpl* get(const MeasureUnit& measureUnit) { return measureUnit.fImpl; @@ -169,13 +194,17 @@ struct MeasureUnitImpl : public UMemory { /** * Create a copy of this MeasureUnitImpl. Don't use copy constructor to make this explicit. */ - inline MeasureUnitImpl copy(UErrorCode& status) const { - MeasureUnitImpl result; - result.complexity = complexity; - result.units.appendAll(units, status); - result.identifier.append(identifier, status); - return result; - } + MeasureUnitImpl copy(UErrorCode& status) const; + + /** + * Extracts the list of all the individual units inside the `MeasureUnitImpl`. + * For example: + * - if the `MeasureUnitImpl` is `foot-per-hour` + * it will return a list of 1 {`foot-per-hour`} + * - if the `MeasureUnitImpl` is `foot-and-inch` + * it will return a list of 2 { `foot`, `inch`} + */ + MaybeStackVector extractIndividualUnits(UErrorCode &status) const; /** Mutates this MeasureUnitImpl to take the reciprocal. */ void takeReciprocal(UErrorCode& status); @@ -206,7 +235,6 @@ struct MeasureUnitImpl : public UMemory { CharString identifier; }; - U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/measure.cpp b/deps/icu-small/source/i18n/measure.cpp index bffa44215e3cde..23adba100707aa 100644 --- a/deps/icu-small/source/i18n/measure.cpp +++ b/deps/icu-small/source/i18n/measure.cpp @@ -23,7 +23,7 @@ U_NAMESPACE_BEGIN UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure) -Measure::Measure() {} +Measure::Measure() : unit(nullptr) {} Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit, UErrorCode& ec) : @@ -35,7 +35,7 @@ Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit, } Measure::Measure(const Measure& other) : - UObject(other), unit(0) { + UObject(other), unit(nullptr) { *this = other; } @@ -43,7 +43,11 @@ Measure& Measure::operator=(const Measure& other) { if (this != &other) { delete unit; number = other.number; - unit = other.unit->clone(); + if (other.unit != nullptr) { + unit = other.unit->clone(); + } else { + unit = nullptr; + } } return *this; } diff --git a/deps/icu-small/source/i18n/nfrs.cpp b/deps/icu-small/source/i18n/nfrs.cpp index 659cfcbbf5a857..dd91d7833db111 100644 --- a/deps/icu-small/source/i18n/nfrs.cpp +++ b/deps/icu-small/source/i18n/nfrs.cpp @@ -37,7 +37,7 @@ enum { /** 0.x */ PROPER_FRACTION_RULE_INDEX = 2, /** x.0 */ - MASTER_RULE_INDEX = 3, + DEFAULT_RULE_INDEX = 3, /** Inf */ INFINITY_RULE_INDEX = 4, /** NaN */ @@ -278,8 +278,8 @@ void NFRuleSet::setNonNumericalRule(NFRule *rule) { else if (baseValue == NFRule::kProperFractionRule) { setBestFractionRule(PROPER_FRACTION_RULE_INDEX, rule, TRUE); } - else if (baseValue == NFRule::kMasterRule) { - setBestFractionRule(MASTER_RULE_INDEX, rule, TRUE); + else if (baseValue == NFRule::kDefaultRule) { + setBestFractionRule(DEFAULT_RULE_INDEX, rule, TRUE); } else if (baseValue == NFRule::kInfinityRule) { delete nonNumericalRules[INFINITY_RULE_INDEX]; @@ -323,7 +323,7 @@ NFRuleSet::~NFRuleSet() for (int i = 0; i < NON_NUMERICAL_RULE_LENGTH; i++) { if (i != IMPROPER_FRACTION_RULE_INDEX && i != PROPER_FRACTION_RULE_INDEX - && i != MASTER_RULE_INDEX) + && i != DEFAULT_RULE_INDEX) { delete nonNumericalRules[i]; } @@ -375,7 +375,7 @@ NFRuleSet::setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErro rules[i]->setDecimalFormatSymbols(newSymbols, status); } // Switch the fraction rules to mirror the DecimalFormatSymbols. - for (int32_t nonNumericalIdx = IMPROPER_FRACTION_RULE_INDEX; nonNumericalIdx <= MASTER_RULE_INDEX; nonNumericalIdx++) { + for (int32_t nonNumericalIdx = IMPROPER_FRACTION_RULE_INDEX; nonNumericalIdx <= DEFAULT_RULE_INDEX; nonNumericalIdx++) { if (nonNumericalRules[nonNumericalIdx]) { for (uint32_t fIdx = 0; fIdx < fractionRules.size(); fIdx++) { NFRule *fractionRule = fractionRules[fIdx]; @@ -472,9 +472,9 @@ NFRuleSet::findDoubleRule(double number) const } } - // if there's a master rule, use it to format the number - if (nonNumericalRules[MASTER_RULE_INDEX]) { - return nonNumericalRules[MASTER_RULE_INDEX]; + // if there's a default rule, use it to format the number + if (nonNumericalRules[DEFAULT_RULE_INDEX]) { + return nonNumericalRules[DEFAULT_RULE_INDEX]; } // and if we haven't yet returned a rule, use findNormalRule() @@ -507,13 +507,13 @@ NFRuleSet::findNormalRule(int64_t number) const // do them in findRule(), because the version of format() that // takes a long bypasses findRule() and goes straight to this // function. This function does skip the fraction rules since - // we know the value is an integer (it also skips the master + // we know the value is an integer (it also skips the default // rule, since it's considered a fraction rule. Skipping the - // master rule in this function is also how we avoid infinite + // default rule in this function is also how we avoid infinite // recursion) // {dlf} unfortunately this fails if there are no rules except - // special rules. If there are no rules, use the master rule. + // special rules. If there are no rules, use the default rule. // binary-search the rule list for the applicable rule // (a rule is used for all values from its base value to @@ -553,8 +553,8 @@ NFRuleSet::findNormalRule(int64_t number) const } return result; } - // else use the master rule - return nonNumericalRules[MASTER_RULE_INDEX]; + // else use the default rule + return nonNumericalRules[DEFAULT_RULE_INDEX]; } /** @@ -792,7 +792,7 @@ NFRuleSet::appendRules(UnicodeString& result) const if (nonNumericalRules[i]) { if (rule->getBaseValue() == NFRule::kImproperFractionRule || rule->getBaseValue() == NFRule::kProperFractionRule - || rule->getBaseValue() == NFRule::kMasterRule) + || rule->getBaseValue() == NFRule::kDefaultRule) { for (uint32_t fIdx = 0; fIdx < fractionRules.size(); fIdx++) { NFRule *fractionRule = fractionRules[fIdx]; diff --git a/deps/icu-small/source/i18n/nfrs.h b/deps/icu-small/source/i18n/nfrs.h index c56fc0707851a7..e9b955ddff142d 100644 --- a/deps/icu-small/source/i18n/nfrs.h +++ b/deps/icu-small/source/i18n/nfrs.h @@ -36,7 +36,7 @@ class NFRuleSet : public UMemory { void parseRules(UnicodeString& rules, UErrorCode& status); void setNonNumericalRule(NFRule *rule); void setBestFractionRule(int32_t originalIndex, NFRule *newRule, UBool rememberRule); - void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; } + void makeIntoFractionRuleSet() { fIsFractionRuleSet = true; } ~NFRuleSet(); @@ -93,11 +93,11 @@ int64_t util64_fromDouble(double d); uint64_t util64_pow(uint32_t radix, uint16_t exponent); // convert n to digit string in buffer, return length of string -uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE); +uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = false); #ifdef RBNF_DEBUG int64_t util64_utoi(const UChar* str, uint32_t radix = 10); -uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE); +uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = false); int64_t util64_atoi(const char* str, uint32_t radix); #endif diff --git a/deps/icu-small/source/i18n/nfrule.cpp b/deps/icu-small/source/i18n/nfrule.cpp index b5e7892d5e68cb..cba41d14bb1fa8 100644 --- a/deps/icu-small/source/i18n/nfrule.cpp +++ b/deps/icu-small/source/i18n/nfrule.cpp @@ -153,7 +153,7 @@ NFRule::makeRules(UnicodeString& description, if ((rule1->baseValue > 0 && (rule1->baseValue % util64_pow(rule1->radix, rule1->exponent)) == 0) || rule1->getType() == kImproperFractionRule - || rule1->getType() == kMasterRule) { + || rule1->getType() == kDefaultRule) { // if it passes that test, new up the second rule. If the // rule set both rules will belong to is a fraction rule @@ -181,9 +181,9 @@ NFRule::makeRules(UnicodeString& description, } // if the description began with "x.0" and contains bracketed - // text, it describes both the master rule and the + // text, it describes both the default rule and the // improper fraction rule - else if (rule1->getType() == kMasterRule) { + else if (rule1->getType() == kDefaultRule) { rule2->baseValue = rule1->baseValue; rule1->setType(kImproperFractionRule); } @@ -376,7 +376,7 @@ NFRule::parseRuleDescriptor(UnicodeString& description, UErrorCode& status) decimalPoint = descriptor.charAt(1); } else if (firstChar == gX && lastChar == gZero) { - setBaseValue(kMasterRule, status); + setBaseValue(kDefaultRule, status); decimalPoint = descriptor.charAt(1); } else if (descriptor.compare(gNaN, 3) == 0) { @@ -663,7 +663,7 @@ NFRule::_appendRuleText(UnicodeString& result) const case kNegativeNumberRule: result.append(gMinusX, 2); break; case kImproperFractionRule: result.append(gX).append(decimalPoint == 0 ? gDot : decimalPoint).append(gX); break; case kProperFractionRule: result.append(gZero).append(decimalPoint == 0 ? gDot : decimalPoint).append(gX); break; - case kMasterRule: result.append(gX).append(decimalPoint == 0 ? gDot : decimalPoint).append(gZero); break; + case kDefaultRule: result.append(gX).append(decimalPoint == 0 ? gDot : decimalPoint).append(gZero); break; case kInfinityRule: result.append(gInf, 3); break; case kNaNRule: result.append(gNaN, 3); break; default: @@ -1297,6 +1297,10 @@ NFRule::prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErr #if !UCONFIG_NO_COLLATION // go through all this grief if we're in lenient-parse mode if (formatter->isLenient()) { + // Check if non-lenient rule finds the text before call lenient parsing + if (str.startsWith(prefix)) { + return prefix.length(); + } // get the formatter's collator and use it to create two // collation element iterators, one over the target string // and another over the prefix (right now, we'll throw an @@ -1505,9 +1509,15 @@ NFRule::findText(const UnicodeString& str, return str.indexOf(key, startingAt); } else { - // but if lenient parsing is turned ON, we've got some work - // ahead of us - return findTextLenient(str, key, startingAt, length); + // Check if non-lenient rule finds the text before call lenient parsing + *length = key.length(); + int32_t pos = str.indexOf(key, startingAt); + if(pos >= 0) { + return pos; + } else { + // but if lenient parsing is turned ON, we've got some work ahead of us + return findTextLenient(str, key, startingAt, length); + } } } diff --git a/deps/icu-small/source/i18n/nfrule.h b/deps/icu-small/source/i18n/nfrule.h index 2b030390ea7dcb..12431c0dba33e8 100644 --- a/deps/icu-small/source/i18n/nfrule.h +++ b/deps/icu-small/source/i18n/nfrule.h @@ -38,7 +38,7 @@ class NFRule : public UMemory { kNegativeNumberRule = -1, kImproperFractionRule = -2, kProperFractionRule = -3, - kMasterRule = -4, + kDefaultRule = -4, kInfinityRule = -5, kNaNRule = -6, kOtherRule = -7 diff --git a/deps/icu-small/source/i18n/nfsubs.cpp b/deps/icu-small/source/i18n/nfsubs.cpp index 3733f0ca74d3e3..e3ea3938835ea3 100644 --- a/deps/icu-small/source/i18n/nfsubs.cpp +++ b/deps/icu-small/source/i18n/nfsubs.cpp @@ -342,7 +342,7 @@ NFSubstitution::makeSubstitution(int32_t pos, // IntegralPartSubstitution else if (rule->getBaseValue() == NFRule::kImproperFractionRule || rule->getBaseValue() == NFRule::kProperFractionRule - || rule->getBaseValue() == NFRule::kMasterRule) { + || rule->getBaseValue() == NFRule::kDefaultRule) { return new IntegralPartSubstitution(pos, ruleSet, description, status); } @@ -371,7 +371,7 @@ NFSubstitution::makeSubstitution(int32_t pos, // FractionalPartSubstitution else if (rule->getBaseValue() == NFRule::kImproperFractionRule || rule->getBaseValue() == NFRule::kProperFractionRule - || rule->getBaseValue() == NFRule::kMasterRule) { + || rule->getBaseValue() == NFRule::kDefaultRule) { return new FractionalPartSubstitution(pos, ruleSet, description, status); } diff --git a/deps/icu-small/source/i18n/nounit.cpp b/deps/icu-small/source/i18n/nounit.cpp deleted file mode 100644 index 1d4aa05506e98d..00000000000000 --- a/deps/icu-small/source/i18n/nounit.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// © 2017 and later: Unicode, Inc. and others. -// License & terms of use: http://www.unicode.org/copyright.html - -#include "unicode/nounit.h" -#include "uassert.h" - -#if !UCONFIG_NO_FORMATTING - -U_NAMESPACE_BEGIN - -UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NoUnit) - -NoUnit U_EXPORT2 NoUnit::base() { - return NoUnit(""); -} - -NoUnit U_EXPORT2 NoUnit::percent() { - return NoUnit("percent"); -} - -NoUnit U_EXPORT2 NoUnit::permille() { - return NoUnit("permille"); -} - -NoUnit::NoUnit(const char* subtype) { - initNoUnit(subtype); -} - -NoUnit::NoUnit(const NoUnit& other) : MeasureUnit(other) { -} - -NoUnit* NoUnit::clone() const { - return new NoUnit(*this); -} - -NoUnit::~NoUnit() { -} - - -U_NAMESPACE_END - -#endif diff --git a/deps/icu-small/source/i18n/number_asformat.h b/deps/icu-small/source/i18n/number_asformat.h index 7b0a1dee6f438b..3a2fe3185bee1c 100644 --- a/deps/icu-small/source/i18n/number_asformat.h +++ b/deps/icu-small/source/i18n/number_asformat.h @@ -25,7 +25,6 @@ namespace impl { * A wrapper around LocalizedNumberFormatter implementing the Format interface, enabling improved * compatibility with other APIs. * - * @draft ICU 62 * @see NumberFormatter */ class U_I18N_API LocalizedNumberFormatterAsFormat : public Format { diff --git a/deps/icu-small/source/i18n/number_capi.cpp b/deps/icu-small/source/i18n/number_capi.cpp index d61440d081e9fb..ef5f0a41ff07a4 100644 --- a/deps/icu-small/source/i18n/number_capi.cpp +++ b/deps/icu-small/source/i18n/number_capi.cpp @@ -13,6 +13,7 @@ #include "number_utypes.h" #include "numparse_types.h" #include "formattedval_impl.h" +#include "number_decnum.h" #include "unicode/numberformatter.h" #include "unicode/unumberformatter.h" @@ -196,6 +197,23 @@ unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPosition result->fData.getAllFieldPositions(fpih, *ec); } +U_CAPI int32_t U_EXPORT2 +unumf_resultToDecimalNumber( + const UFormattedNumber* uresult, + char* dest, + int32_t destCapacity, + UErrorCode* ec) { + const auto* result = UFormattedNumberApiHelper::validate(uresult, *ec); + if (U_FAILURE(*ec)) { + return 0; + } + DecNum decnum; + return result->fData.quantity + .toDecNum(decnum, *ec) + .toCharString(*ec) + .extract(dest, destCapacity, *ec); +} + U_CAPI void U_EXPORT2 unumf_close(UNumberFormatter* f) { UErrorCode localStatus = U_ZERO_ERROR; diff --git a/deps/icu-small/source/i18n/number_compact.cpp b/deps/icu-small/source/i18n/number_compact.cpp index e1fef8feb52298..d781b6fada234c 100644 --- a/deps/icu-small/source/i18n/number_compact.cpp +++ b/deps/icu-small/source/i18n/number_compact.cpp @@ -167,6 +167,11 @@ void CompactData::CompactDataSink::put(const char *key, ResourceValue &value, UB if (U_FAILURE(status)) { return; } for (int i4 = 0; pluralVariantsTable.getKeyAndValue(i4, key, value); ++i4) { + if (uprv_strcmp(key, "0") == 0 || uprv_strcmp(key, "1") == 0) { + // TODO(ICU-21258): Handle this case. For now, skip. + continue; + } + // Skip this magnitude/plural if we already have it from a child locale. // Note: This also skips USE_FALLBACK entries. StandardPlural::Form plural = StandardPlural::fromString(key, status); diff --git a/deps/icu-small/source/i18n/number_currencysymbols.cpp b/deps/icu-small/source/i18n/number_currencysymbols.cpp index 4d6fb2cb1d8dec..9208427904cceb 100644 --- a/deps/icu-small/source/i18n/number_currencysymbols.cpp +++ b/deps/icu-small/source/i18n/number_currencysymbols.cpp @@ -44,6 +44,16 @@ UnicodeString CurrencySymbols::getNarrowCurrencySymbol(UErrorCode& status) const return loadSymbol(UCURR_NARROW_SYMBOL_NAME, status); } +UnicodeString CurrencySymbols::getFormalCurrencySymbol(UErrorCode& status) const { + // Note: currently no override is available for formal currency symbol + return loadSymbol(UCURR_FORMAL_SYMBOL_NAME, status); +} + +UnicodeString CurrencySymbols::getVariantCurrencySymbol(UErrorCode& status) const { + // Note: currently no override is available for variant currency symbol + return loadSymbol(UCURR_VARIANT_SYMBOL_NAME, status); +} + UnicodeString CurrencySymbols::getCurrencySymbol(UErrorCode& status) const { if (!fCurrencySymbol.isBogus()) { return fCurrencySymbol; diff --git a/deps/icu-small/source/i18n/number_currencysymbols.h b/deps/icu-small/source/i18n/number_currencysymbols.h index 9996bf96ae08a1..7e38fdf8287e14 100644 --- a/deps/icu-small/source/i18n/number_currencysymbols.h +++ b/deps/icu-small/source/i18n/number_currencysymbols.h @@ -31,6 +31,10 @@ class U_I18N_API CurrencySymbols : public UMemory { UnicodeString getNarrowCurrencySymbol(UErrorCode& status) const; + UnicodeString getFormalCurrencySymbol(UErrorCode& status) const; + + UnicodeString getVariantCurrencySymbol(UErrorCode& status) const; + UnicodeString getCurrencySymbol(UErrorCode& status) const; UnicodeString getIntlCurrencySymbol(UErrorCode& status) const; diff --git a/deps/icu-small/source/i18n/number_decimalquantity.cpp b/deps/icu-small/source/i18n/number_decimalquantity.cpp index 5ce9c27cbf4a76..75af5e9974fc65 100644 --- a/deps/icu-small/source/i18n/number_decimalquantity.cpp +++ b/deps/icu-small/source/i18n/number_decimalquantity.cpp @@ -20,6 +20,7 @@ #include "charstr.h" #include "number_utils.h" #include "uassert.h" +#include "util.h" using namespace icu; using namespace icu::number; @@ -626,7 +627,7 @@ double DecimalQuantity::toDouble() const { &count); } -void DecimalQuantity::toDecNum(DecNum& output, UErrorCode& status) const { +DecNum& DecimalQuantity::toDecNum(DecNum& output, UErrorCode& status) const { // Special handling for zero if (precision == 0) { output.setTo("0", status); @@ -634,11 +635,15 @@ void DecimalQuantity::toDecNum(DecNum& output, UErrorCode& status) const { // Use the BCD constructor. We need to do a little bit of work to convert, though. // The decNumber constructor expects most-significant first, but we store least-significant first. - MaybeStackArray ubcd(precision); + MaybeStackArray ubcd(precision, status); + if (U_FAILURE(status)) { + return output; + } for (int32_t m = 0; m < precision; m++) { ubcd[precision - m - 1] = static_cast(getDigitPos(m)); } output.setTo(ubcd.getAlias(), precision, scale, isNegative(), status); + return output; } void DecimalQuantity::truncate() { @@ -1004,13 +1009,8 @@ void DecimalQuantity::shiftLeft(int32_t numDigits) { } if (usingBytes) { ensureCapacity(precision + numDigits); - int i = precision + numDigits - 1; - for (; i >= numDigits; i--) { - fBCD.bcdBytes.ptr[i] = fBCD.bcdBytes.ptr[i - numDigits]; - } - for (; i >= 0; i--) { - fBCD.bcdBytes.ptr[i] = 0; - } + uprv_memmove(fBCD.bcdBytes.ptr + numDigits, fBCD.bcdBytes.ptr, precision); + uprv_memset(fBCD.bcdBytes.ptr, 0, numDigits); } else { fBCD.bcdLong <<= (numDigits * 4); } @@ -1324,7 +1324,11 @@ bool DecimalQuantity::operator==(const DecimalQuantity& other) const { } UnicodeString DecimalQuantity::toString() const { - MaybeStackArray digits(precision + 1); + UErrorCode localStatus = U_ZERO_ERROR; + MaybeStackArray digits(precision + 1, localStatus); + if (U_FAILURE(localStatus)) { + return ICU_Utility::makeBogusString(); + } for (int32_t i = 0; i < precision; i++) { digits[i] = getDigitPos(precision - i - 1) + '0'; } diff --git a/deps/icu-small/source/i18n/number_decimalquantity.h b/deps/icu-small/source/i18n/number_decimalquantity.h index 53a9eb33b26caf..839424775a0d8d 100644 --- a/deps/icu-small/source/i18n/number_decimalquantity.h +++ b/deps/icu-small/source/i18n/number_decimalquantity.h @@ -20,7 +20,7 @@ namespace impl { class DecNum; /** - * An class for representing a number to be processed by the decimal formatting pipeline. Includes + * A class for representing a number to be processed by the decimal formatting pipeline. Includes * methods for rounding, plural rules, and decimal digit extraction. * *

    By design, this is NOT IMMUTABLE and NOT THREAD SAFE. It is intended to be an intermediate @@ -209,7 +209,7 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory { double toDouble() const; /** Computes a DecNum representation of this DecimalQuantity, saving it to the output parameter. */ - void toDecNum(DecNum& output, UErrorCode& status) const; + DecNum& toDecNum(DecNum& output, UErrorCode& status) const; DecimalQuantity &setToInt(int32_t n); @@ -217,7 +217,13 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory { DecimalQuantity &setToDouble(double n); - /** decNumber is similar to BigDecimal in Java. */ + /** + * Produces a DecimalQuantity that was parsed from a string by the decNumber + * C Library. + * + * decNumber is similar to BigDecimal in Java, and supports parsing strings + * such as "123.456621E+40". + */ DecimalQuantity &setToDecNumber(StringPiece n, UErrorCode& status); /** Internal method if the caller already has a DecNum. */ diff --git a/deps/icu-small/source/i18n/number_decnum.h b/deps/icu-small/source/i18n/number_decnum.h index 0c7399dbddd43b..3bb8d107807967 100644 --- a/deps/icu-small/source/i18n/number_decnum.h +++ b/deps/icu-small/source/i18n/number_decnum.h @@ -9,6 +9,7 @@ #include "decNumber.h" #include "charstr.h" +#include "bytesinkutil.h" U_NAMESPACE_BEGIN @@ -57,6 +58,13 @@ class U_I18N_API DecNum : public UMemory { void toString(ByteSink& output, UErrorCode& status) const; + inline CharString toCharString(UErrorCode& status) const { + CharString cstr; + CharStringByteSink sink(&cstr); + toString(sink, status); + return cstr; + } + inline const decNumber* getRawDecNumber() const { return fData.getAlias(); } diff --git a/deps/icu-small/source/i18n/number_fluent.cpp b/deps/icu-small/source/i18n/number_fluent.cpp index 9cdb8b7156e614..8569a36e5b260b 100644 --- a/deps/icu-small/source/i18n/number_fluent.cpp +++ b/deps/icu-small/source/i18n/number_fluent.cpp @@ -13,6 +13,7 @@ #include "number_asformat.h" #include "number_utils.h" #include "number_utypes.h" +#include "number_mapper.h" #include "util.h" #include "fphdlimp.h" @@ -273,6 +274,20 @@ Derived NumberFormatterSettings::scale(const Scale& scale)&& { return move; } +template +Derived NumberFormatterSettings::usage(const StringPiece usage) const& { + Derived copy(*this); + copy.fMacros.usage.set(usage); + return copy; +} + +template +Derived NumberFormatterSettings::usage(const StringPiece usage)&& { + Derived move(std::move(*this)); + move.fMacros.usage.set(usage); + return move; +} + template Derived NumberFormatterSettings::padding(const Padder& padder) const& { Derived copy(*this); @@ -400,7 +415,8 @@ LocalizedNumberFormatter::LocalizedNumberFormatter(const LNF& other) LocalizedNumberFormatter::LocalizedNumberFormatter(const NFS& other) : NFS(other) { - // No additional fields to assign (let call count and compiled formatter reset to defaults) + UErrorCode localStatus = U_ZERO_ERROR; // Can't bubble up the error + lnfCopyHelper(static_cast(other), localStatus); } LocalizedNumberFormatter::LocalizedNumberFormatter(LocalizedNumberFormatter&& src) U_NOEXCEPT @@ -408,38 +424,25 @@ LocalizedNumberFormatter::LocalizedNumberFormatter(LocalizedNumberFormatter&& sr LocalizedNumberFormatter::LocalizedNumberFormatter(NFS&& src) U_NOEXCEPT : NFS(std::move(src)) { - // For the move operators, copy over the compiled formatter. - // Note: if the formatter is not compiled, call count information is lost. - if (static_cast(src).fCompiled != nullptr) { - lnfMoveHelper(static_cast(src)); - } + lnfMoveHelper(std::move(static_cast(src))); } LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(const LNF& other) { NFS::operator=(static_cast&>(other)); - // Reset to default values. - clear(); + UErrorCode localStatus = U_ZERO_ERROR; // Can't bubble up the error + lnfCopyHelper(other, localStatus); return *this; } LocalizedNumberFormatter& LocalizedNumberFormatter::operator=(LNF&& src) U_NOEXCEPT { NFS::operator=(static_cast&&>(src)); - // For the move operators, copy over the compiled formatter. - // Note: if the formatter is not compiled, call count information is lost. - if (static_cast(src).fCompiled != nullptr) { - // Formatter is compiled - lnfMoveHelper(static_cast(src)); - } else { - clear(); - } + lnfMoveHelper(std::move(src)); return *this; } -void LocalizedNumberFormatter::clear() { - // Reset to default values. +void LocalizedNumberFormatter::resetCompiled() { auto* callCount = reinterpret_cast(fUnsafeCallCount); umtx_storeRelease(*callCount, 0); - delete fCompiled; fCompiled = nullptr; } @@ -447,19 +450,56 @@ void LocalizedNumberFormatter::lnfMoveHelper(LNF&& src) { // Copy over the compiled formatter and set call count to INT32_MIN as in computeCompiled(). // Don't copy the call count directly because doing so requires a loadAcquire/storeRelease. // The bits themselves appear to be platform-dependent, so copying them might not be safe. - auto* callCount = reinterpret_cast(fUnsafeCallCount); - umtx_storeRelease(*callCount, INT32_MIN); delete fCompiled; - fCompiled = src.fCompiled; - // Reset the source object to leave it in a safe state. - auto* srcCallCount = reinterpret_cast(src.fUnsafeCallCount); - umtx_storeRelease(*srcCallCount, 0); - src.fCompiled = nullptr; + if (src.fCompiled != nullptr) { + auto* callCount = reinterpret_cast(fUnsafeCallCount); + umtx_storeRelease(*callCount, INT32_MIN); + fCompiled = src.fCompiled; + // Reset the source object to leave it in a safe state. + src.resetCompiled(); + } else { + resetCompiled(); + } + + // Unconditionally move the warehouse + delete fWarehouse; + fWarehouse = src.fWarehouse; + src.fWarehouse = nullptr; +} + +void LocalizedNumberFormatter::lnfCopyHelper(const LNF&, UErrorCode& status) { + // When copying, always reset the compiled formatter. + delete fCompiled; + resetCompiled(); + + // If MacroProps has a reference to AffixPatternProvider, we need to copy it. + // If MacroProps has a reference to PluralRules, copy that one, too. + delete fWarehouse; + if (fMacros.affixProvider || fMacros.rules) { + LocalPointer warehouse(new DecimalFormatWarehouse(), status); + if (U_FAILURE(status)) { + fWarehouse = nullptr; + return; + } + if (fMacros.affixProvider) { + warehouse->affixProvider.setTo(fMacros.affixProvider, status); + fMacros.affixProvider = &warehouse->affixProvider.get(); + } + if (fMacros.rules) { + warehouse->rules.adoptInsteadAndCheckErrorCode( + new PluralRules(*fMacros.rules), status); + fMacros.rules = warehouse->rules.getAlias(); + } + fWarehouse = warehouse.orphan(); + } else { + fWarehouse = nullptr; + } } LocalizedNumberFormatter::~LocalizedNumberFormatter() { delete fCompiled; + delete fWarehouse; } LocalizedNumberFormatter::LocalizedNumberFormatter(const MacroProps& macros, const Locale& locale) { @@ -480,123 +520,6 @@ LocalizedNumberFormatter UnlocalizedNumberFormatter::locale(const Locale& locale return LocalizedNumberFormatter(std::move(fMacros), locale); } -SymbolsWrapper::SymbolsWrapper(const SymbolsWrapper& other) { - doCopyFrom(other); -} - -SymbolsWrapper::SymbolsWrapper(SymbolsWrapper&& src) U_NOEXCEPT { - doMoveFrom(std::move(src)); -} - -SymbolsWrapper& SymbolsWrapper::operator=(const SymbolsWrapper& other) { - if (this == &other) { - return *this; - } - doCleanup(); - doCopyFrom(other); - return *this; -} - -SymbolsWrapper& SymbolsWrapper::operator=(SymbolsWrapper&& src) U_NOEXCEPT { - if (this == &src) { - return *this; - } - doCleanup(); - doMoveFrom(std::move(src)); - return *this; -} - -SymbolsWrapper::~SymbolsWrapper() { - doCleanup(); -} - -void SymbolsWrapper::setTo(const DecimalFormatSymbols& dfs) { - doCleanup(); - fType = SYMPTR_DFS; - fPtr.dfs = new DecimalFormatSymbols(dfs); -} - -void SymbolsWrapper::setTo(const NumberingSystem* ns) { - doCleanup(); - fType = SYMPTR_NS; - fPtr.ns = ns; -} - -void SymbolsWrapper::doCopyFrom(const SymbolsWrapper& other) { - fType = other.fType; - switch (fType) { - case SYMPTR_NONE: - // No action necessary - break; - case SYMPTR_DFS: - // Memory allocation failures are exposed in copyErrorTo() - if (other.fPtr.dfs != nullptr) { - fPtr.dfs = new DecimalFormatSymbols(*other.fPtr.dfs); - } else { - fPtr.dfs = nullptr; - } - break; - case SYMPTR_NS: - // Memory allocation failures are exposed in copyErrorTo() - if (other.fPtr.ns != nullptr) { - fPtr.ns = new NumberingSystem(*other.fPtr.ns); - } else { - fPtr.ns = nullptr; - } - break; - } -} - -void SymbolsWrapper::doMoveFrom(SymbolsWrapper&& src) { - fType = src.fType; - switch (fType) { - case SYMPTR_NONE: - // No action necessary - break; - case SYMPTR_DFS: - fPtr.dfs = src.fPtr.dfs; - src.fPtr.dfs = nullptr; - break; - case SYMPTR_NS: - fPtr.ns = src.fPtr.ns; - src.fPtr.ns = nullptr; - break; - } -} - -void SymbolsWrapper::doCleanup() { - switch (fType) { - case SYMPTR_NONE: - // No action necessary - break; - case SYMPTR_DFS: - delete fPtr.dfs; - break; - case SYMPTR_NS: - delete fPtr.ns; - break; - } -} - -bool SymbolsWrapper::isDecimalFormatSymbols() const { - return fType == SYMPTR_DFS; -} - -bool SymbolsWrapper::isNumberingSystem() const { - return fType == SYMPTR_NS; -} - -const DecimalFormatSymbols* SymbolsWrapper::getDecimalFormatSymbols() const { - U_ASSERT(fType == SYMPTR_DFS); - return fPtr.dfs; -} - -const NumberingSystem* SymbolsWrapper::getNumberingSystem() const { - U_ASSERT(fType == SYMPTR_NS); - return fPtr.ns; -} - - FormattedNumber LocalizedNumberFormatter::formatInt(int64_t value, UErrorCode& status) const { if (U_FAILURE(status)) { return FormattedNumber(U_ILLEGAL_ARGUMENT_ERROR); } auto results = new UFormattedNumberData(); @@ -676,9 +599,9 @@ LocalizedNumberFormatter::formatDecimalQuantity(const DecimalQuantity& dq, UErro void LocalizedNumberFormatter::formatImpl(impl::UFormattedNumberData* results, UErrorCode& status) const { if (computeCompiled(status)) { - fCompiled->format(results->quantity, results->getStringRef(), status); + fCompiled->format(results, status); } else { - NumberFormatterImpl::formatStatic(fMacros, results->quantity, results->getStringRef(), status); + NumberFormatterImpl::formatStatic(fMacros, results, status); } if (U_FAILURE(status)) { return; diff --git a/deps/icu-small/source/i18n/number_formatimpl.cpp b/deps/icu-small/source/i18n/number_formatimpl.cpp index 5bba09cfb5293e..9a9f3c8b71e01c 100644 --- a/deps/icu-small/source/i18n/number_formatimpl.cpp +++ b/deps/icu-small/source/i18n/number_formatimpl.cpp @@ -25,20 +25,20 @@ using namespace icu::number; using namespace icu::number::impl; -MicroPropsGenerator::~MicroPropsGenerator() = default; - - NumberFormatterImpl::NumberFormatterImpl(const MacroProps& macros, UErrorCode& status) : NumberFormatterImpl(macros, true, status) { } -int32_t NumberFormatterImpl::formatStatic(const MacroProps& macros, DecimalQuantity& inValue, - FormattedStringBuilder& outString, UErrorCode& status) { +int32_t NumberFormatterImpl::formatStatic(const MacroProps ¯os, UFormattedNumberData *results, + UErrorCode &status) { + DecimalQuantity &inValue = results->quantity; + FormattedStringBuilder &outString = results->getStringRef(); NumberFormatterImpl impl(macros, false, status); MicroProps& micros = impl.preProcessUnsafe(inValue, status); if (U_FAILURE(status)) { return 0; } int32_t length = writeNumber(micros, inValue, outString, 0, status); length += writeAffixes(micros, outString, 0, length, status); + results->outputUnit = std::move(micros.outputUnit); return length; } @@ -54,13 +54,15 @@ int32_t NumberFormatterImpl::getPrefixSuffixStatic(const MacroProps& macros, Sig // The "unsafe" method simply re-uses fMicros, eliminating the extra copy operation. // See MicroProps::processQuantity() for details. -int32_t NumberFormatterImpl::format(DecimalQuantity& inValue, FormattedStringBuilder& outString, - UErrorCode& status) const { +int32_t NumberFormatterImpl::format(UFormattedNumberData *results, UErrorCode &status) const { + DecimalQuantity &inValue = results->quantity; + FormattedStringBuilder &outString = results->getStringRef(); MicroProps micros; preProcess(inValue, micros, status); if (U_FAILURE(status)) { return 0; } int32_t length = writeNumber(micros, inValue, outString, 0, status); length += writeAffixes(micros, outString, 0, length, status); + results->outputUnit = std::move(micros.outputUnit); return length; } @@ -130,9 +132,10 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, // Pre-compute a few values for efficiency. bool isCurrency = utils::unitIsCurrency(macros.unit); - bool isNoUnit = utils::unitIsNoUnit(macros.unit); + bool isBaseUnit = utils::unitIsBaseUnit(macros.unit); bool isPercent = utils::unitIsPercent(macros.unit); bool isPermille = utils::unitIsPermille(macros.unit); + bool isCompactNotation = macros.notation.fType == Notation::NTN_COMPACT; bool isAccounting = macros.sign == UNUM_SIGN_ACCOUNTING || macros.sign == UNUM_SIGN_ACCOUNTING_ALWAYS || macros.sign == UNUM_SIGN_ACCOUNTING_EXCEPT_ZERO; @@ -144,8 +147,20 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, if (macros.unitWidth != UNUM_UNIT_WIDTH_COUNT) { unitWidth = macros.unitWidth; } - bool isCldrUnit = !isCurrency && !isNoUnit && - (unitWidth == UNUM_UNIT_WIDTH_FULL_NAME || !(isPercent || isPermille)); + // Use CLDR unit data for all MeasureUnits (not currency and not + // no-unit), except use the dedicated percent pattern for percent and + // permille. However, use the CLDR unit data for percent/permille if a + // long name was requested OR if compact notation is being used, since + // compact notation overrides the middle modifier (micros.modMiddle) + // normally used for the percent pattern. + bool isCldrUnit = !isCurrency + && !isBaseUnit + && (unitWidth == UNUM_UNIT_WIDTH_FULL_NAME + || !(isPercent || isPermille) + || isCompactNotation + ); + bool isMixedUnit = isCldrUnit && (uprv_strcmp(macros.unit.getType(), "") == 0) && + macros.unit.getComplexity(status) == UMEASURE_UNIT_MIXED; // Select the numbering system. LocalPointer nsLocal; @@ -222,6 +237,27 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, /// START POPULATING THE DEFAULT MICROPROPS AND BUILDING THE MICROPROPS GENERATOR /// ///////////////////////////////////////////////////////////////////////////////////// + // Unit Preferences and Conversions as our first step + if (macros.usage.isSet()) { + if (!isCldrUnit) { + // We only support "usage" when the input unit is specified, and is + // a CLDR Unit. + status = U_ILLEGAL_ARGUMENT_ERROR; + return nullptr; + } + auto usagePrefsHandler = + new UsagePrefsHandler(macros.locale, macros.unit, macros.usage.fUsage, chain, status); + fUsagePrefsHandler.adoptInsteadAndCheckErrorCode(usagePrefsHandler, status); + chain = fUsagePrefsHandler.getAlias(); + } else if (isMixedUnit) { + MeasureUnitImpl temp; + const MeasureUnitImpl &outputUnit = MeasureUnitImpl::forMeasureUnit(macros.unit, temp, status); + auto unitConversionHandler = + new UnitConversionHandler(outputUnit.units[0]->build(status), macros.unit, chain, status); + fUnitConversionHandler.adoptInsteadAndCheckErrorCode(unitConversionHandler, status); + chain = fUnitConversionHandler.getAlias(); + } + // Multiplier if (macros.scale.isValid()) { fMicros.helpers.multiplier.setAndChain(macros.scale, chain); @@ -232,20 +268,18 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, Precision precision; if (!macros.precision.isBogus()) { precision = macros.precision; - } else if (macros.notation.fType == Notation::NTN_COMPACT) { + } else if (isCompactNotation) { precision = Precision::integer().withMinDigits(2); } else if (isCurrency) { precision = Precision::currency(UCURR_USAGE_STANDARD); + } else if (macros.usage.isSet()) { + // Bogus Precision - it will get set in the UsagePrefsHandler instead + precision = Precision(); } else { precision = Precision::maxFraction(6); } UNumberFormatRoundingMode roundingMode; - if (macros.roundingMode != kDefaultMode) { - roundingMode = macros.roundingMode; - } else { - // Temporary until ICU 64 - roundingMode = precision.fRoundingMode; - } + roundingMode = macros.roundingMode; fMicros.rounder = {precision, roundingMode, currency, status}; if (U_FAILURE(status)) { return nullptr; @@ -254,7 +288,7 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, // Grouping strategy if (!macros.grouper.isBogus()) { fMicros.grouping = macros.grouper; - } else if (macros.notation.fType == Notation::NTN_COMPACT) { + } else if (isCompactNotation) { // Compact notation uses minGrouping by default since ICU 59 fMicros.grouping = Grouper::forStrategy(UNUM_GROUPING_MIN2); } else { @@ -330,7 +364,8 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, patternModifier->setSymbols(fMicros.symbols, currency, unitWidth, nullptr, status); } if (safe) { - fImmutablePatternModifier.adoptInstead(patternModifier->createImmutable(status)); + fImmutablePatternModifier.adoptInsteadAndCheckErrorCode(patternModifier->createImmutable(status), + status); } if (U_FAILURE(status)) { return nullptr; @@ -338,24 +373,34 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, // Outer modifier (CLDR units and currency long names) if (isCldrUnit) { - fLongNameHandler.adoptInstead( - LongNameHandler::forMeasureUnit( - macros.locale, - macros.unit, - macros.perUnit, - unitWidth, - resolvePluralRules(macros.rules, macros.locale, status), - chain, - status)); - chain = fLongNameHandler.getAlias(); + if (macros.usage.isSet()) { + fLongNameMultiplexer.adoptInsteadAndCheckErrorCode( + LongNameMultiplexer::forMeasureUnits( + macros.locale, *fUsagePrefsHandler->getOutputUnits(), unitWidth, + resolvePluralRules(macros.rules, macros.locale, status), chain, status), + status); + chain = fLongNameMultiplexer.getAlias(); + } else if (isMixedUnit) { + fMixedUnitLongNameHandler.adoptInsteadAndCheckErrorCode(new MixedUnitLongNameHandler(), + status); + MixedUnitLongNameHandler::forMeasureUnit( + macros.locale, macros.unit, unitWidth, + resolvePluralRules(macros.rules, macros.locale, status), chain, + fMixedUnitLongNameHandler.getAlias(), status); + chain = fMixedUnitLongNameHandler.getAlias(); + } else { + fLongNameHandler.adoptInsteadAndCheckErrorCode(new LongNameHandler(), status); + LongNameHandler::forMeasureUnit(macros.locale, macros.unit, macros.perUnit, unitWidth, + resolvePluralRules(macros.rules, macros.locale, status), + chain, fLongNameHandler.getAlias(), status); + chain = fLongNameHandler.getAlias(); + } } else if (isCurrency && unitWidth == UNUM_UNIT_WIDTH_FULL_NAME) { - fLongNameHandler.adoptInstead( - LongNameHandler::forCurrencyLongNames( - macros.locale, - currency, - resolvePluralRules(macros.rules, macros.locale, status), - chain, - status)); + fLongNameHandler.adoptInsteadAndCheckErrorCode( + LongNameHandler::forCurrencyLongNames( + macros.locale, currency, resolvePluralRules(macros.rules, macros.locale, status), chain, + status), + status); chain = fLongNameHandler.getAlias(); } else { // No outer modifier required @@ -366,7 +411,7 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, } // Compact notation - if (macros.notation.fType == Notation::NTN_COMPACT) { + if (isCompactNotation) { CompactType compactType = (isCurrency && unitWidth != UNUM_UNIT_WIDTH_FULL_NAME) ? CompactType::TYPE_CURRENCY : CompactType::TYPE_DECIMAL; auto newCompactHandler = new CompactHandler( @@ -379,6 +424,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe, safe, chain, status); + if (U_FAILURE(status)) { + return nullptr; + } if (newCompactHandler == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return nullptr; @@ -417,6 +465,7 @@ NumberFormatterImpl::resolvePluralRules(const PluralRules* rulesPtr, const Local int32_t NumberFormatterImpl::writeAffixes(const MicroProps& micros, FormattedStringBuilder& string, int32_t start, int32_t end, UErrorCode& status) { + U_ASSERT(micros.modOuter != nullptr); // Always apply the inner modifier (which is "strong"). int32_t length = micros.modInner->apply(string, start, end, status); if (micros.padding.isValid()) { diff --git a/deps/icu-small/source/i18n/number_formatimpl.h b/deps/icu-small/source/i18n/number_formatimpl.h index 084bc4a9d0b209..5cd549e54a363f 100644 --- a/deps/icu-small/source/i18n/number_formatimpl.h +++ b/deps/icu-small/source/i18n/number_formatimpl.h @@ -10,11 +10,13 @@ #include "number_types.h" #include "formatted_string_builder.h" #include "number_patternstring.h" +#include "number_usageprefs.h" #include "number_utils.h" #include "number_patternmodifier.h" #include "number_longnames.h" #include "number_compact.h" #include "number_microprops.h" +#include "number_utypes.h" U_NAMESPACE_BEGIN namespace number { namespace impl { @@ -34,9 +36,8 @@ class NumberFormatterImpl : public UMemory { /** * Builds and evaluates an "unsafe" MicroPropsGenerator, which is cheaper but can be used only once. */ - static int32_t - formatStatic(const MacroProps ¯os, DecimalQuantity &inValue, FormattedStringBuilder &outString, - UErrorCode &status); + static int32_t formatStatic(const MacroProps ¯os, UFormattedNumberData *results, + UErrorCode &status); /** * Prints only the prefix and suffix; used for DecimalFormat getters. @@ -51,7 +52,7 @@ class NumberFormatterImpl : public UMemory { /** * Evaluates the "safe" MicroPropsGenerator created by "fromMacros". */ - int32_t format(DecimalQuantity& inValue, FormattedStringBuilder& outString, UErrorCode& status) const; + int32_t format(UFormattedNumberData *results, UErrorCode &status) const; /** * Like format(), but saves the result into an output MicroProps without additional processing. @@ -82,7 +83,9 @@ class NumberFormatterImpl : public UMemory { int32_t end, UErrorCode& status); private: - // Head of the MicroPropsGenerator linked list: + // Head of the MicroPropsGenerator linked list. Subclasses' processQuantity + // methods process this list in a parent-first order, such that the last + // item added, which this points to, typically has its logic executed last. const MicroPropsGenerator *fMicroPropsGenerator = nullptr; // Tail of the list: @@ -90,13 +93,20 @@ class NumberFormatterImpl : public UMemory { // Other fields possibly used by the number formatting pipeline: // TODO: Convert more of these LocalPointers to value objects to reduce the number of news? + LocalPointer fUsagePrefsHandler; + LocalPointer fUnitConversionHandler; LocalPointer fSymbols; LocalPointer fRules; LocalPointer fPatternInfo; LocalPointer fScientificHandler; LocalPointer fPatternModifier; LocalPointer fImmutablePatternModifier; - LocalPointer fLongNameHandler; + LocalPointer fLongNameHandler; + // TODO: use a common base class that enables fLongNameHandler, + // fLongNameMultiplexer, and fMixedUnitLongNameHandler to be merged into one + // member? + LocalPointer fMixedUnitLongNameHandler; + LocalPointer fLongNameMultiplexer; LocalPointer fCompactHandler; // Value objects possibly used by the number formatting pipeline: diff --git a/deps/icu-small/source/i18n/number_grouping.cpp b/deps/icu-small/source/i18n/number_grouping.cpp index 41f727a458f943..6b1642cfd34abd 100644 --- a/deps/icu-small/source/i18n/number_grouping.cpp +++ b/deps/icu-small/source/i18n/number_grouping.cpp @@ -64,6 +64,13 @@ Grouper Grouper::forProperties(const DecimalFormatProperties& properties) { } void Grouper::setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale) { + if (fMinGrouping == -2) { + fMinGrouping = getMinGroupingForLocale(locale); + } else if (fMinGrouping == -3) { + fMinGrouping = static_cast(uprv_max(2, getMinGroupingForLocale(locale))); + } else { + // leave fMinGrouping alone + } if (fGrouping1 != -2 && fGrouping2 != -4) { return; } @@ -76,13 +83,6 @@ void Grouper::setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Lo if (grouping3 == -1) { grouping2 = grouping1; } - if (fMinGrouping == -2) { - fMinGrouping = getMinGroupingForLocale(locale); - } else if (fMinGrouping == -3) { - fMinGrouping = static_cast(uprv_max(2, getMinGroupingForLocale(locale))); - } else { - // leave fMinGrouping alone - } fGrouping1 = grouping1; fGrouping2 = grouping2; } diff --git a/deps/icu-small/source/i18n/number_integerwidth.cpp b/deps/icu-small/source/i18n/number_integerwidth.cpp index d62aef444dca96..10b853423c847a 100644 --- a/deps/icu-small/source/i18n/number_integerwidth.cpp +++ b/deps/icu-small/source/i18n/number_integerwidth.cpp @@ -40,6 +40,9 @@ IntegerWidth IntegerWidth::truncateAt(int32_t maxInt) { } void IntegerWidth::apply(impl::DecimalQuantity& quantity, UErrorCode& status) const { + if (U_FAILURE(status)) { + return; + } if (fHasError) { status = U_ILLEGAL_ARGUMENT_ERROR; } else if (fUnion.minMaxInt.fMaxInt == -1) { diff --git a/deps/icu-small/source/i18n/number_longnames.cpp b/deps/icu-small/source/i18n/number_longnames.cpp index bb32d0381a507e..3891d532dea851 100644 --- a/deps/icu-small/source/i18n/number_longnames.cpp +++ b/deps/icu-small/source/i18n/number_longnames.cpp @@ -10,6 +10,7 @@ #include "ureslocs.h" #include "charstr.h" #include "uresimp.h" +#include "measunit_impl.h" #include "number_longnames.h" #include "number_microprops.h" #include @@ -22,8 +23,23 @@ using namespace icu::number::impl; namespace { +/** + * Display Name (this format has no placeholder). + * + * Used as an index into the LongNameHandler::simpleFormats array. Units + * resources cover the normal set of PluralRules keys, as well as `dnam` and + * `per` forms. + */ constexpr int32_t DNAM_INDEX = StandardPlural::Form::COUNT; +/** + * "per" form (e.g. "{0} per day" is day's "per" form). + * + * Used as an index into the LongNameHandler::simpleFormats array. Units + * resources cover the normal set of PluralRules keys, as well as `dnam` and + * `per` forms. + */ constexpr int32_t PER_INDEX = StandardPlural::Form::COUNT + 1; +// Number of keys in the array populated by PluralTableSink. constexpr int32_t ARRAY_LENGTH = StandardPlural::Form::COUNT + 2; static int32_t getIndex(const char* pluralKeyword, UErrorCode& status) { @@ -38,6 +54,11 @@ static int32_t getIndex(const char* pluralKeyword, UErrorCode& status) { } } +// Selects a string out of the `strings` array which corresponds to the +// specified plural form, with fallback to the OTHER form. +// +// The `strings` array must have ARRAY_LENGTH items: one corresponding to each +// of the plural forms, plus a display name ("dnam") and a "per" form. static UnicodeString getWithPlural( const UnicodeString* strings, StandardPlural::Form plural, @@ -87,6 +108,18 @@ class PluralTableSink : public ResourceSink { // NOTE: outArray MUST have room for all StandardPlural values. No bounds checking is performed. +/** + * Populates outArray with `locale`-specific values for `unit` through use of + * PluralTableSink. Only the set of basic units are supported! + * + * Reading from resources *unitsNarrow* and *unitsShort* (for width + * UNUM_UNIT_WIDTH_NARROW), or just *unitsShort* (for width + * UNUM_UNIT_WIDTH_SHORT). For other widths, it reads just "units". + * + * @param unit must have a type and subtype (i.e. it must be a unit listed in + * gTypes and gSubTypes in measunit.cpp). + * @param outArray must be of fixed length ARRAY_LENGTH. + */ void getMeasureData(const Locale &locale, const MeasureUnit &unit, const UNumberUnitWidth &width, UnicodeString *outArray, UErrorCode &status) { PluralTableSink sink(outArray); @@ -184,78 +217,107 @@ UnicodeString getPerUnitFormat(const Locale& locale, const UNumberUnitWidth &wid } // namespace -LongNameHandler* -LongNameHandler::forMeasureUnit(const Locale &loc, const MeasureUnit &unitRef, const MeasureUnit &perUnit, - const UNumberUnitWidth &width, const PluralRules *rules, - const MicroPropsGenerator *parent, UErrorCode &status) { - if (uprv_strlen(unitRef.getType()) == 0 || uprv_strlen(perUnit.getType()) == 0) { - // TODO(ICU-20941): Unsanctioned unit. Not yet fully supported. Set an error code. - status = U_UNSUPPORTED_ERROR; - return nullptr; - } +void LongNameHandler::forMeasureUnit(const Locale &loc, const MeasureUnit &unitRef, + const MeasureUnit &perUnit, const UNumberUnitWidth &width, + const PluralRules *rules, const MicroPropsGenerator *parent, + LongNameHandler *fillIn, UErrorCode &status) { + // Not valid for mixed units that aren't built-in units, and there should + // not be any built-in mixed units! + U_ASSERT(uprv_strcmp(unitRef.getType(), "") != 0 || + unitRef.getComplexity(status) != UMEASURE_UNIT_MIXED); + U_ASSERT(fillIn != nullptr); MeasureUnit unit = unitRef; if (uprv_strcmp(perUnit.getType(), "none") != 0) { // Compound unit: first try to simplify (e.g., meters per second is its own unit). - bool isResolved = false; - MeasureUnit resolved = MeasureUnit::resolveUnitPerUnit(unit, perUnit, &isResolved); - if (isResolved) { - unit = resolved; + MeasureUnit simplified = unit.product(perUnit.reciprocal(status), status); + if (uprv_strcmp(simplified.getType(), "") != 0) { + unit = simplified; } else { // No simplified form is available. - return forCompoundUnit(loc, unit, perUnit, width, rules, parent, status); + forCompoundUnit(loc, unit, perUnit, width, rules, parent, fillIn, status); + return; } } - auto* result = new LongNameHandler(rules, parent); - if (result == nullptr) { - status = U_MEMORY_ALLOCATION_ERROR; - return nullptr; + if (uprv_strcmp(unit.getType(), "") == 0) { + // TODO(ICU-20941): Unsanctioned unit. Not yet fully supported. Set an + // error code. Once we support not-built-in units here, unitRef may be + // anything, but if not built-in, perUnit has to be "none". + status = U_UNSUPPORTED_ERROR; + return; } + UnicodeString simpleFormats[ARRAY_LENGTH]; getMeasureData(loc, unit, width, simpleFormats, status); - if (U_FAILURE(status)) { return result; } - result->simpleFormatsToModifiers(simpleFormats, {UFIELD_CATEGORY_NUMBER, UNUM_MEASURE_UNIT_FIELD}, status); - return result; + if (U_FAILURE(status)) { + return; + } + fillIn->rules = rules; + fillIn->parent = parent; + fillIn->simpleFormatsToModifiers(simpleFormats, {UFIELD_CATEGORY_NUMBER, UNUM_MEASURE_UNIT_FIELD}, + status); } -LongNameHandler* -LongNameHandler::forCompoundUnit(const Locale &loc, const MeasureUnit &unit, const MeasureUnit &perUnit, - const UNumberUnitWidth &width, const PluralRules *rules, - const MicroPropsGenerator *parent, UErrorCode &status) { - auto* result = new LongNameHandler(rules, parent); - if (result == nullptr) { - status = U_MEMORY_ALLOCATION_ERROR; - return nullptr; +void LongNameHandler::forCompoundUnit(const Locale &loc, const MeasureUnit &unit, + const MeasureUnit &perUnit, const UNumberUnitWidth &width, + const PluralRules *rules, const MicroPropsGenerator *parent, + LongNameHandler *fillIn, UErrorCode &status) { + if (uprv_strcmp(unit.getType(), "") == 0 || uprv_strcmp(perUnit.getType(), "") == 0) { + // TODO(ICU-20941): Unsanctioned unit. Not yet fully supported. Set an + // error code. Once we support not-built-in units here, unitRef may be + // anything, but if not built-in, perUnit has to be "none". + status = U_UNSUPPORTED_ERROR; + return; + } + if (fillIn == nullptr) { + status = U_INTERNAL_PROGRAM_ERROR; + return; } UnicodeString primaryData[ARRAY_LENGTH]; getMeasureData(loc, unit, width, primaryData, status); - if (U_FAILURE(status)) { return result; } + if (U_FAILURE(status)) { + return; + } UnicodeString secondaryData[ARRAY_LENGTH]; getMeasureData(loc, perUnit, width, secondaryData, status); - if (U_FAILURE(status)) { return result; } + if (U_FAILURE(status)) { + return; + } UnicodeString perUnitFormat; if (!secondaryData[PER_INDEX].isBogus()) { perUnitFormat = secondaryData[PER_INDEX]; } else { UnicodeString rawPerUnitFormat = getPerUnitFormat(loc, width, status); - if (U_FAILURE(status)) { return result; } + if (U_FAILURE(status)) { + return; + } // rawPerUnitFormat is something like "{0}/{1}"; we need to substitute in the secondary unit. SimpleFormatter compiled(rawPerUnitFormat, 2, 2, status); - if (U_FAILURE(status)) { return result; } + if (U_FAILURE(status)) { + return; + } UnicodeString secondaryFormat = getWithPlural(secondaryData, StandardPlural::Form::ONE, status); - if (U_FAILURE(status)) { return result; } + if (U_FAILURE(status)) { + return; + } // Some "one" pattern may not contain "{0}". For example in "ar" or "ne" locale. SimpleFormatter secondaryCompiled(secondaryFormat, 0, 1, status); - if (U_FAILURE(status)) { return result; } + if (U_FAILURE(status)) { + return; + } UnicodeString secondaryString = secondaryCompiled.getTextWithNoArguments().trim(); // TODO: Why does UnicodeString need to be explicit in the following line? compiled.format(UnicodeString(u"{0}"), secondaryString, perUnitFormat, status); - if (U_FAILURE(status)) { return result; } + if (U_FAILURE(status)) { + return; + } } - result->multiSimpleFormatsToModifiers(primaryData, perUnitFormat, {UFIELD_CATEGORY_NUMBER, UNUM_MEASURE_UNIT_FIELD}, status); - return result; + fillIn->rules = rules; + fillIn->parent = parent; + fillIn->multiSimpleFormatsToModifiers(primaryData, perUnitFormat, + {UFIELD_CATEGORY_NUMBER, UNUM_MEASURE_UNIT_FIELD}, status); } UnicodeString LongNameHandler::getUnitDisplayName( @@ -338,7 +400,9 @@ void LongNameHandler::multiSimpleFormatsToModifiers(const UnicodeString *leadFor void LongNameHandler::processQuantity(DecimalQuantity &quantity, MicroProps µs, UErrorCode &status) const { - parent->processQuantity(quantity, micros, status); + if (parent != NULL) { + parent->processQuantity(quantity, micros, status); + } StandardPlural::Form pluralForm = utils::getPluralSafe(micros.rounder, rules, quantity, status); micros.modOuter = &fModifiers[pluralForm]; } @@ -347,4 +411,199 @@ const Modifier* LongNameHandler::getModifier(Signum /*signum*/, StandardPlural:: return &fModifiers[plural]; } +void MixedUnitLongNameHandler::forMeasureUnit(const Locale &loc, const MeasureUnit &mixedUnit, + const UNumberUnitWidth &width, const PluralRules *rules, + const MicroPropsGenerator *parent, + MixedUnitLongNameHandler *fillIn, UErrorCode &status) { + U_ASSERT(mixedUnit.getComplexity(status) == UMEASURE_UNIT_MIXED); + U_ASSERT(fillIn != nullptr); + + MeasureUnitImpl temp; + const MeasureUnitImpl& impl = MeasureUnitImpl::forMeasureUnit(mixedUnit, temp, status); + fillIn->fMixedUnitCount = impl.units.length(); + fillIn->fMixedUnitData.adoptInstead(new UnicodeString[fillIn->fMixedUnitCount * ARRAY_LENGTH]); + for (int32_t i = 0; i < fillIn->fMixedUnitCount; i++) { + // Grab data for each of the components. + UnicodeString *unitData = &fillIn->fMixedUnitData[i * ARRAY_LENGTH]; + getMeasureData(loc, impl.units[i]->build(status), width, unitData, status); + } + + UListFormatterWidth listWidth = ULISTFMT_WIDTH_SHORT; + if (width == UNUM_UNIT_WIDTH_NARROW) { + listWidth = ULISTFMT_WIDTH_NARROW; + } else if (width == UNUM_UNIT_WIDTH_FULL_NAME) { + // This might be the same as SHORT in most languages: + listWidth = ULISTFMT_WIDTH_WIDE; + } + fillIn->fListFormatter.adoptInsteadAndCheckErrorCode( + ListFormatter::createInstance(loc, ULISTFMT_TYPE_UNITS, listWidth, status), status); + fillIn->rules = rules; + fillIn->parent = parent; + + // We need a localised NumberFormatter for the integers of the bigger units + // (providing Arabic numerals, for example). + fillIn->fIntegerFormatter = NumberFormatter::withLocale(loc); +} + +void MixedUnitLongNameHandler::processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const { + U_ASSERT(fMixedUnitCount > 1); + if (parent != nullptr) { + parent->processQuantity(quantity, micros, status); + } + micros.modOuter = getMixedUnitModifier(quantity, micros, status); +} + +const Modifier *MixedUnitLongNameHandler::getMixedUnitModifier(DecimalQuantity &quantity, + MicroProps µs, + UErrorCode &status) const { + if (micros.mixedMeasuresCount == 0) { + U_ASSERT(micros.mixedMeasuresCount > 0); // Mixed unit: we must have more than one unit value + status = U_UNSUPPORTED_ERROR; + return µs.helpers.emptyWeakModifier; + } + // If we don't have at least one mixedMeasure, the LongNameHandler would be + // sufficient and we shouldn't be running MixedUnitLongNameHandler code: + U_ASSERT(micros.mixedMeasuresCount > 0); + // mixedMeasures does not contain the last value: + U_ASSERT(fMixedUnitCount == micros.mixedMeasuresCount + 1); + U_ASSERT(fListFormatter.isValid()); + + // Algorithm: + // + // For the mixed-units measurement of: "3 yard, 1 foot, 2.6 inch", we should + // find "3 yard" and "1 foot" in micros.mixedMeasures. + // + // Obtain long-names with plural forms corresponding to measure values: + // * {0} yards, {0} foot, {0} inches + // + // Format the integer values appropriately and modify with the format + // strings: + // - 3 yards, 1 foot + // + // Use ListFormatter to combine, with one placeholder: + // - 3 yards, 1 foot and {0} inches + // + // Return a SimpleModifier for this pattern, letting the rest of the + // pipeline take care of the remaining inches. + + LocalArray outputMeasuresList(new UnicodeString[fMixedUnitCount], status); + if (U_FAILURE(status)) { + return µs.helpers.emptyWeakModifier; + } + + for (int32_t i = 0; i < micros.mixedMeasuresCount; i++) { + DecimalQuantity fdec; + fdec.setToLong(micros.mixedMeasures[i]); + if (i > 0 && fdec.isNegative()) { + // If numbers are negative, only the first number needs to have its + // negative sign formatted. + fdec.negate(); + } + StandardPlural::Form pluralForm = utils::getStandardPlural(rules, fdec); + + UnicodeString simpleFormat = + getWithPlural(&fMixedUnitData[i * ARRAY_LENGTH], pluralForm, status); + SimpleFormatter compiledFormatter(simpleFormat, 0, 1, status); + + UnicodeString num; + auto appendable = UnicodeStringAppendable(num); + fIntegerFormatter.formatDecimalQuantity(fdec, status).appendTo(appendable, status); + compiledFormatter.format(num, outputMeasuresList[i], status); + // TODO(icu-units#67): fix field positions + } + + // Reiterated: we have at least one mixedMeasure: + U_ASSERT(micros.mixedMeasuresCount > 0); + // Thus if negative, a negative has already been formatted: + if (quantity.isNegative()) { + quantity.negate(); + } + + UnicodeString *finalSimpleFormats = &fMixedUnitData[(fMixedUnitCount - 1) * ARRAY_LENGTH]; + StandardPlural::Form finalPlural = utils::getPluralSafe(micros.rounder, rules, quantity, status); + UnicodeString finalSimpleFormat = getWithPlural(finalSimpleFormats, finalPlural, status); + SimpleFormatter finalFormatter(finalSimpleFormat, 0, 1, status); + finalFormatter.format(UnicodeString(u"{0}"), outputMeasuresList[fMixedUnitCount - 1], status); + + // Combine list into a "premixed" pattern + UnicodeString premixedFormatPattern; + fListFormatter->format(outputMeasuresList.getAlias(), fMixedUnitCount, premixedFormatPattern, + status); + SimpleFormatter premixedCompiled(premixedFormatPattern, 0, 1, status); + if (U_FAILURE(status)) { + return µs.helpers.emptyWeakModifier; + } + + // TODO(icu-units#67): fix field positions + // Return a SimpleModifier for the "premixed" pattern + micros.helpers.mixedUnitModifier = + SimpleModifier(premixedCompiled, kUndefinedField, false, {this, SIGNUM_POS_ZERO, finalPlural}); + return µs.helpers.mixedUnitModifier; +} + +const Modifier *MixedUnitLongNameHandler::getModifier(Signum /*signum*/, + StandardPlural::Form /*plural*/) const { + // TODO(units): investigate this method when investigating where + // LongNameHandler::getModifier() gets used. To be sure it remains + // unreachable: + UPRV_UNREACHABLE; + return nullptr; +} + +LongNameMultiplexer * +LongNameMultiplexer::forMeasureUnits(const Locale &loc, const MaybeStackVector &units, + const UNumberUnitWidth &width, const PluralRules *rules, + const MicroPropsGenerator *parent, UErrorCode &status) { + LocalPointer result(new LongNameMultiplexer(parent), status); + if (U_FAILURE(status)) { + return nullptr; + } + U_ASSERT(units.length() > 0); + if (result->fHandlers.resize(units.length()) == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return nullptr; + } + result->fMeasureUnits.adoptInstead(new MeasureUnit[units.length()]); + for (int32_t i = 0, length = units.length(); i < length; i++) { + const MeasureUnit& unit = *units[i]; + result->fMeasureUnits[i] = unit; + if (unit.getComplexity(status) == UMEASURE_UNIT_MIXED) { + MixedUnitLongNameHandler *mlnh = result->fMixedUnitHandlers.createAndCheckErrorCode(status); + MixedUnitLongNameHandler::forMeasureUnit(loc, unit, width, rules, NULL, mlnh, status); + result->fHandlers[i] = mlnh; + } else { + LongNameHandler *lnh = result->fLongNameHandlers.createAndCheckErrorCode(status); + LongNameHandler::forMeasureUnit(loc, unit, MeasureUnit(), width, rules, NULL, lnh, status); + result->fHandlers[i] = lnh; + } + if (U_FAILURE(status)) { + return nullptr; + } + } + return result.orphan(); +} + +void LongNameMultiplexer::processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const { + // We call parent->processQuantity() from the Multiplexer, instead of + // letting LongNameHandler handle it: we don't know which LongNameHandler to + // call until we've called the parent! + fParent->processQuantity(quantity, micros, status); + + // Call the correct LongNameHandler based on outputUnit + for (int i = 0; i < fHandlers.getCapacity(); i++) { + if (fMeasureUnits[i] == micros.outputUnit) { + fHandlers[i]->processQuantity(quantity, micros, status); + return; + } + } + if (U_FAILURE(status)) { + return; + } + // We shouldn't receive any outputUnit for which we haven't already got a + // LongNameHandler: + status = U_INTERNAL_PROGRAM_ERROR; +} + #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/number_longnames.h b/deps/icu-small/source/i18n/number_longnames.h index a19425aa268af6..67f2316a9cd4bd 100644 --- a/deps/icu-small/source/i18n/number_longnames.h +++ b/deps/icu-small/source/i18n/number_longnames.h @@ -7,6 +7,8 @@ #ifndef __NUMBER_LONGNAMES_H__ #define __NUMBER_LONGNAMES_H__ +#include "cmemory.h" +#include "unicode/listformatter.h" #include "unicode/uversion.h" #include "number_utils.h" #include "number_modifiers.h" @@ -33,34 +35,206 @@ class LongNameHandler : public MicroPropsGenerator, public ModifierStore, public forCurrencyLongNames(const Locale &loc, const CurrencyUnit ¤cy, const PluralRules *rules, const MicroPropsGenerator *parent, UErrorCode &status); - static LongNameHandler* - forMeasureUnit(const Locale &loc, const MeasureUnit &unit, const MeasureUnit &perUnit, - const UNumberUnitWidth &width, const PluralRules *rules, - const MicroPropsGenerator *parent, UErrorCode &status); - + /** + * Construct a localized LongNameHandler for the specified MeasureUnit. + * + * Compound units can be constructed via `unit` and `perUnit`. Both of these + * must then be built-in units. + * + * Mixed units are not supported, use MixedUnitLongNameHandler::forMeasureUnit. + * + * This function uses a fillIn intead of returning a pointer, because we + * want to fill in instances in a MemoryPool (which cannot adopt pointers it + * didn't create itself). + * + * @param loc The desired locale. + * @param unit The measure unit to construct a LongNameHandler for. If + * `perUnit` is also defined, `unit` must not be a mixed unit. + * @param perUnit If `unit` is a mixed unit, `perUnit` must be "none". + * @param width Specifies the desired unit rendering. + * @param rules Does not take ownership. + * @param parent Does not take ownership. + * @param fillIn Required. + */ + static void forMeasureUnit(const Locale &loc, const MeasureUnit &unit, const MeasureUnit &perUnit, + const UNumberUnitWidth &width, const PluralRules *rules, + const MicroPropsGenerator *parent, LongNameHandler *fillIn, + UErrorCode &status); + + /** + * Selects the plural-appropriate Modifier from the set of fModifiers based + * on the plural form. + */ void processQuantity(DecimalQuantity &quantity, MicroProps µs, UErrorCode &status) const U_OVERRIDE; + // TODO(units): investigate whether we might run into Mixed Unit trouble + // with this. This override for ModifierStore::getModifier does not support + // mixed units: investigate under which circumstances it gets called (check + // both ImmutablePatternModifier and in NumberRangeFormatterImpl). const Modifier* getModifier(Signum signum, StandardPlural::Form plural) const U_OVERRIDE; private: + // A set of pre-computed modifiers, one for each plural form. SimpleModifier fModifiers[StandardPlural::Form::COUNT]; + // Not owned const PluralRules *rules; + // Not owned const MicroPropsGenerator *parent; LongNameHandler(const PluralRules *rules, const MicroPropsGenerator *parent) - : rules(rules), parent(parent) {} + : rules(rules), parent(parent) { + } - static LongNameHandler* - forCompoundUnit(const Locale &loc, const MeasureUnit &unit, const MeasureUnit &perUnit, - const UNumberUnitWidth &width, const PluralRules *rules, - const MicroPropsGenerator *parent, UErrorCode &status); + LongNameHandler() : rules(nullptr), parent(nullptr) { + } + + // Enables MemoryPool::emplaceBack(): requires access to + // the private constructors. + friend class MemoryPool; + + // Allow macrosToMicroGenerator to call the private default constructor. + friend class NumberFormatterImpl; + // Fills in LongNameHandler fields for formatting compound units identified + // via `unit` and `perUnit`. Both `unit` and `perUnit` need to be built-in + // units (for which data exists). + static void forCompoundUnit(const Locale &loc, const MeasureUnit &unit, const MeasureUnit &perUnit, + const UNumberUnitWidth &width, const PluralRules *rules, + const MicroPropsGenerator *parent, LongNameHandler *fillIn, + UErrorCode &status); + + // Sets fModifiers to use the patterns from `simpleFormats`. void simpleFormatsToModifiers(const UnicodeString *simpleFormats, Field field, UErrorCode &status); + + // Sets fModifiers to a combination of `leadFormats` (one per plural form) + // and `trailFormat` appended to each. + // + // With a leadFormat of "{0}m" and a trailFormat of "{0}/s", it produces a + // pattern of "{0}m/s" by inserting the leadFormat pattern into trailFormat. void multiSimpleFormatsToModifiers(const UnicodeString *leadFormats, UnicodeString trailFormat, Field field, UErrorCode &status); }; +// Similar to LongNameHandler, but only for MIXED units. +class MixedUnitLongNameHandler : public MicroPropsGenerator, public ModifierStore, public UMemory { + public: + /** + * Construct a localized MixedUnitLongNameHandler for the specified + * MeasureUnit. It must be a MIXED unit. + * + * This function uses a fillIn intead of returning a pointer, because we + * want to fill in instances in a MemoryPool (which cannot adopt pointers it + * didn't create itself). + * + * @param loc The desired locale. + * @param mixedUnit The mixed measure unit to construct a + * MixedUnitLongNameHandler for. + * @param width Specifies the desired unit rendering. + * @param rules Does not take ownership. + * @param parent Does not take ownership. + * @param fillIn Required. + */ + static void forMeasureUnit(const Locale &loc, const MeasureUnit &mixedUnit, + const UNumberUnitWidth &width, const PluralRules *rules, + const MicroPropsGenerator *parent, MixedUnitLongNameHandler *fillIn, + UErrorCode &status); + + /** + * Produces a plural-appropriate Modifier for a mixed unit: `quantity` is + * taken as the final smallest unit, while the larger unit values must be + * provided via `micros.mixedMeasures`. + */ + void processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const U_OVERRIDE; + + // Required for ModifierStore. And ModifierStore is required by + // SimpleModifier constructor's last parameter. We assert his will never get + // called though. + const Modifier *getModifier(Signum signum, StandardPlural::Form plural) const U_OVERRIDE; + + private: + // Not owned + const PluralRules *rules; + // Not owned + const MicroPropsGenerator *parent; + + // Total number of units in the MeasureUnit this handler was configured for: + // for "foot-and-inch", this will be 2. + int32_t fMixedUnitCount = 1; + // Stores unit data for each of the individual units. For each unit, it + // stores ARRAY_LENGTH strings, as returned by getMeasureData. (Each unit + // with index `i` has ARRAY_LENGTH strings starting at index + // `i*ARRAY_LENGTH` in this array.) + LocalArray fMixedUnitData; + // A localized NumberFormatter used to format the integer-valued bigger + // units of Mixed Unit measurements. + LocalizedNumberFormatter fIntegerFormatter; + // A localised list formatter for joining mixed units together. + LocalPointer fListFormatter; + + MixedUnitLongNameHandler(const PluralRules *rules, const MicroPropsGenerator *parent) + : rules(rules), parent(parent) { + } + + MixedUnitLongNameHandler() : rules(nullptr), parent(nullptr) { + } + + // Allow macrosToMicroGenerator to call the private default constructor. + friend class NumberFormatterImpl; + + // Enables MemoryPool::emplaceBack(): requires access to + // the private constructors. + friend class MemoryPool; + + // For a mixed unit, returns a Modifier that takes only one parameter: the + // smallest and final unit of the set. The bigger units' values and labels + // get baked into this Modifier, together with the unit label of the final + // unit. + const Modifier *getMixedUnitModifier(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const; +}; + +/** + * A MicroPropsGenerator that multiplexes between different LongNameHandlers, + * depending on the outputUnit. + * + * See processQuantity() for the input requirements. + */ +class LongNameMultiplexer : public MicroPropsGenerator, public UMemory { + public: + // Produces a multiplexer for LongNameHandlers, one for each unit in + // `units`. An individual unit might be a mixed unit. + static LongNameMultiplexer *forMeasureUnits(const Locale &loc, + const MaybeStackVector &units, + const UNumberUnitWidth &width, const PluralRules *rules, + const MicroPropsGenerator *parent, UErrorCode &status); + + // The output unit must be provided via `micros.outputUnit`, it must match + // one of the units provided to the factory function. + void processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const U_OVERRIDE; + + private: + /** + * Because we only know which LongNameHandler we wish to call after calling + * earlier MicroPropsGenerators in the chain, LongNameMultiplexer keeps the + * parent link, while the LongNameHandlers are given no parents. + */ + MemoryPool fLongNameHandlers; + MemoryPool fMixedUnitHandlers; + // Unowned pointers to instances owned by MaybeStackVectors. + MaybeStackArray fHandlers; + // Each MeasureUnit corresponds to the same-index MicroPropsGenerator + // pointed to in fHandlers. + LocalArray fMeasureUnits; + + const MicroPropsGenerator *fParent; + + LongNameMultiplexer(const MicroPropsGenerator *parent) : fParent(parent) { + } +}; + } // namespace impl } // namespace number U_NAMESPACE_END diff --git a/deps/icu-small/source/i18n/number_mapper.cpp b/deps/icu-small/source/i18n/number_mapper.cpp index ec617438c9a9e3..e2a0d284b7cf5d 100644 --- a/deps/icu-small/source/i18n/number_mapper.cpp +++ b/deps/icu-small/source/i18n/number_mapper.cpp @@ -92,6 +92,8 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert int32_t minSig = properties.minimumSignificantDigits; int32_t maxSig = properties.maximumSignificantDigits; double roundingIncrement = properties.roundingIncrement; + // Not assigning directly to macros.roundingMode here: we change + // roundingMode if and when we also change macros.precision. RoundingMode roundingMode = properties.roundingMode.getOrDefault(UNUM_ROUND_HALFEVEN); bool explicitMinMaxFrac = minFrac != -1 || maxFrac != -1; bool explicitMinMaxSig = minSig != -1 || maxSig != -1; @@ -145,7 +147,7 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert precision = Precision::constructCurrency(currencyUsage); } if (!precision.isBogus()) { - precision.fRoundingMode = roundingMode; + macros.roundingMode = roundingMode; macros.precision = precision; } @@ -239,7 +241,7 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert // TODO: Reset maxSig_ = 1 + minFrac_ to follow the spec. macros.precision = Precision::constructSignificant(minSig_, maxSig_); } - macros.precision.fRoundingMode = roundingMode; + macros.roundingMode = roundingMode; } } diff --git a/deps/icu-small/source/i18n/number_mapper.h b/deps/icu-small/source/i18n/number_mapper.h index d18b8b3c438cf4..9ecd776b3b4795 100644 --- a/deps/icu-small/source/i18n/number_mapper.h +++ b/deps/icu-small/source/i18n/number_mapper.h @@ -136,6 +136,16 @@ class AutoAffixPatternProvider { } } + inline void setTo(const AffixPatternProvider* provider, UErrorCode& status) { + if (auto ptr = dynamic_cast(provider)) { + propertiesAPP = *ptr; + } else if (auto ptr = dynamic_cast(provider)) { + currencyPluralInfoAPP = *ptr; + } else { + status = U_INTERNAL_PROGRAM_ERROR; + } + } + inline const AffixPatternProvider& get() const { if (!currencyPluralInfoAPP.isBogus()) { return currencyPluralInfoAPP; @@ -153,9 +163,9 @@ class AutoAffixPatternProvider { /** * A struct for ownership of a few objects needed for formatting. */ -struct DecimalFormatWarehouse { +struct DecimalFormatWarehouse : public UMemory { AutoAffixPatternProvider affixProvider; - + LocalPointer rules; }; diff --git a/deps/icu-small/source/i18n/number_microprops.h b/deps/icu-small/source/i18n/number_microprops.h index 56512f5e6f94ac..058c5923b4567b 100644 --- a/deps/icu-small/source/i18n/number_microprops.h +++ b/deps/icu-small/source/i18n/number_microprops.h @@ -22,6 +22,56 @@ U_NAMESPACE_BEGIN namespace number { namespace impl { +/** + * A copyable container for the integer values of mixed unit measurements. + * + * If memory allocation fails during copying, no values are copied and status is + * set to U_MEMORY_ALLOCATION_ERROR. + */ +class IntMeasures : public MaybeStackArray { + public: + /** + * Default constructor initializes with internal T[stackCapacity] buffer. + * + * Stack Capacity: most mixed units are expected to consist of two or three + * subunits, so one or two integer measures should be enough. + */ + IntMeasures() : MaybeStackArray() { + } + + /** + * Copy constructor. + * + * If memory allocation fails during copying, no values are copied and + * status is set to U_MEMORY_ALLOCATION_ERROR. + */ + IntMeasures(const IntMeasures &other) : MaybeStackArray() { + this->operator=(other); + } + + // Assignment operator + IntMeasures &operator=(const IntMeasures &rhs) { + if (this == &rhs) { + return *this; + } + copyFrom(rhs, status); + return *this; + } + + /** Move constructor */ + IntMeasures(IntMeasures &&src) = default; + + /** Move assignment */ + IntMeasures &operator=(IntMeasures &&src) = default; + + UErrorCode status = U_ZERO_ERROR; +}; + +/** + * MicroProps is the first MicroPropsGenerator that should be should be called, + * producing an initialized MicroProps instance that will be passed on and + * modified throughout the rest of the chain of MicroPropsGenerator instances. + */ struct MicroProps : public MicroPropsGenerator { // NOTE: All of these fields are properly initialized in NumberFormatterImpl. @@ -36,19 +86,47 @@ struct MicroProps : public MicroPropsGenerator { // Note: This struct has no direct ownership of the following pointers. const DecimalFormatSymbols* symbols; + + // Pointers to Modifiers provided by the number formatting pipeline (when + // the value is known): + + // A Modifier provided by LongNameHandler, used for currency long names and + // units. If there is no LongNameHandler needed, this should be an + // EmptyModifier. (This is typically the third modifier applied.) const Modifier* modOuter; + // A Modifier for short currencies and compact notation. (This is typically + // the second modifier applied.) const Modifier* modMiddle = nullptr; + // A Modifier provided by ScientificHandler, used for scientific notation. + // This is typically the first modifier applied. const Modifier* modInner; // The following "helper" fields may optionally be used during the MicroPropsGenerator. // They live here to retain memory. struct { + // The ScientificModifier for which ScientificHandler is responsible. + // ScientificHandler::processQuantity() modifies this Modifier. ScientificModifier scientificModifier; + // EmptyModifier used for modOuter EmptyModifier emptyWeakModifier{false}; + // EmptyModifier used for modInner EmptyModifier emptyStrongModifier{true}; MultiplierFormatHandler multiplier; + // A Modifier used for Mixed Units. When formatting mixed units, + // LongNameHandler assigns this Modifier. + SimpleModifier mixedUnitModifier; } helpers; + // The MeasureUnit with which the output is represented. May also have + // UMEASURE_UNIT_MIXED complexity, in which case mixedMeasures comes into + // play. + MeasureUnit outputUnit; + + // In the case of mixed units, this is the set of integer-only units + // *preceding* the final unit. + IntMeasures mixedMeasures; + // Number of mixedMeasures that have been populated + int32_t mixedMeasuresCount = 0; MicroProps() = default; @@ -56,7 +134,23 @@ struct MicroProps : public MicroPropsGenerator { MicroProps& operator=(const MicroProps& other) = default; - void processQuantity(DecimalQuantity&, MicroProps& micros, UErrorCode& status) const U_OVERRIDE { + /** + * As MicroProps is the "base instance", this implementation of + * MicroPropsGenerator::processQuantity() just ensures that the output + * `micros` is correctly initialized. + * + * For the "safe" invocation of this function, micros must not be *this, + * such that a copy of the base instance is made. For the "unsafe" path, + * this function can be used only once, because the base MicroProps instance + * will be modified and thus not be available for re-use. + * + * @param quantity The quantity for consideration and optional mutation. + * @param micros The MicroProps instance to populate. If this parameter is + * not already `*this`, it will be overwritten with a copy of `*this`. + */ + void processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const U_OVERRIDE { + (void) quantity; (void) status; if (this == µs) { // Unsafe path: no need to perform a copy. @@ -65,6 +159,7 @@ struct MicroProps : public MicroPropsGenerator { U_ASSERT(exhausted); } else { // Safe path: copy self into the output micros. + U_ASSERT(!exhausted); micros = *this; } } diff --git a/deps/icu-small/source/i18n/number_modifiers.cpp b/deps/icu-small/source/i18n/number_modifiers.cpp index 3becb7ba852336..b7d825f499e4d2 100644 --- a/deps/icu-small/source/i18n/number_modifiers.cpp +++ b/deps/icu-small/source/i18n/number_modifiers.cpp @@ -25,13 +25,13 @@ const int32_t ARG_NUM_LIMIT = 0x100; icu::UInitOnce gDefaultCurrencySpacingInitOnce = U_INITONCE_INITIALIZER; UnicodeSet *UNISET_DIGIT = nullptr; -UnicodeSet *UNISET_NOTS = nullptr; +UnicodeSet *UNISET_NOTSZ = nullptr; UBool U_CALLCONV cleanupDefaultCurrencySpacing() { delete UNISET_DIGIT; UNISET_DIGIT = nullptr; - delete UNISET_NOTS; - UNISET_NOTS = nullptr; + delete UNISET_NOTSZ; + UNISET_NOTSZ = nullptr; gDefaultCurrencySpacingInitOnce.reset(); return TRUE; } @@ -39,13 +39,13 @@ UBool U_CALLCONV cleanupDefaultCurrencySpacing() { void U_CALLCONV initDefaultCurrencySpacing(UErrorCode &status) { ucln_i18n_registerCleanup(UCLN_I18N_CURRENCY_SPACING, cleanupDefaultCurrencySpacing); UNISET_DIGIT = new UnicodeSet(UnicodeString(u"[:digit:]"), status); - UNISET_NOTS = new UnicodeSet(UnicodeString(u"[:^S:]"), status); - if (UNISET_DIGIT == nullptr || UNISET_NOTS == nullptr) { + UNISET_NOTSZ = new UnicodeSet(UnicodeString(u"[[:^S:]&[:^Z:]]"), status); + if (UNISET_DIGIT == nullptr || UNISET_NOTSZ == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return; } UNISET_DIGIT->freeze(); - UNISET_NOTS->freeze(); + UNISET_NOTSZ->freeze(); } } // namespace @@ -469,8 +469,8 @@ CurrencySpacingEnabledModifier::getUnicodeSet(const DecimalFormatSymbols &symbol status); if (pattern.compare(u"[:digit:]", -1) == 0) { return *UNISET_DIGIT; - } else if (pattern.compare(u"[:^S:]", -1) == 0) { - return *UNISET_NOTS; + } else if (pattern.compare(u"[[:^S:]&[:^Z:]]", -1) == 0) { + return *UNISET_NOTSZ; } else { return UnicodeSet(pattern, status); } diff --git a/deps/icu-small/source/i18n/number_output.cpp b/deps/icu-small/source/i18n/number_output.cpp index 40192a9225b9de..7129b94e0f86e4 100644 --- a/deps/icu-small/source/i18n/number_output.cpp +++ b/deps/icu-small/source/i18n/number_output.cpp @@ -5,11 +5,13 @@ #if !UCONFIG_NO_FORMATTING +#include "unicode/measunit.h" #include "unicode/numberformatter.h" #include "number_utypes.h" #include "util.h" #include "number_decimalquantity.h" #include "number_decnum.h" +#include "numrange_impl.h" U_NAMESPACE_BEGIN namespace number { @@ -32,6 +34,11 @@ void FormattedNumber::getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpi fData->getAllFieldPositions(fpih, status); } +MeasureUnit FormattedNumber::getOutputUnit(UErrorCode& status) const { + UPRV_FORMATTED_VALUE_METHOD_GUARD(MeasureUnit()) + return fData->outputUnit; +} + void FormattedNumber::getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const { UPRV_FORMATTED_VALUE_METHOD_GUARD(UPRV_NOARG) output = fData->quantity; @@ -41,6 +48,42 @@ void FormattedNumber::getDecimalQuantity(impl::DecimalQuantity& output, UErrorCo impl::UFormattedNumberData::~UFormattedNumberData() = default; +UPRV_FORMATTED_VALUE_SUBCLASS_AUTO_IMPL(FormattedNumberRange) + +#define UPRV_NOARG + +UnicodeString FormattedNumberRange::getFirstDecimal(UErrorCode& status) const { + UPRV_FORMATTED_VALUE_METHOD_GUARD(ICU_Utility::makeBogusString()) + return fData->quantity1.toScientificString(); +} + +UnicodeString FormattedNumberRange::getSecondDecimal(UErrorCode& status) const { + UPRV_FORMATTED_VALUE_METHOD_GUARD(ICU_Utility::makeBogusString()) + return fData->quantity2.toScientificString(); +} + +void FormattedNumberRange::getDecimalNumbers(ByteSink& sink1, ByteSink& sink2, UErrorCode& status) const { + UPRV_FORMATTED_VALUE_METHOD_GUARD(UPRV_NOARG) + impl::DecNum decnum1; + impl::DecNum decnum2; + fData->quantity1.toDecNum(decnum1, status).toString(sink1, status); + fData->quantity2.toDecNum(decnum2, status).toString(sink2, status); +} + +UNumberRangeIdentityResult FormattedNumberRange::getIdentityResult(UErrorCode& status) const { + UPRV_FORMATTED_VALUE_METHOD_GUARD(UNUM_IDENTITY_RESULT_NOT_EQUAL) + return fData->identityResult; +} + +const impl::UFormattedNumberRangeData* FormattedNumberRange::getData(UErrorCode& status) const { + UPRV_FORMATTED_VALUE_METHOD_GUARD(nullptr) + return fData; +} + + +impl::UFormattedNumberRangeData::~UFormattedNumberRangeData() = default; + + } // namespace number U_NAMESPACE_END diff --git a/deps/icu-small/source/i18n/number_patternmodifier.cpp b/deps/icu-small/source/i18n/number_patternmodifier.cpp index 45602942aefe8e..314e7cb75ee169 100644 --- a/deps/icu-small/source/i18n/number_patternmodifier.cpp +++ b/deps/icu-small/source/i18n/number_patternmodifier.cpp @@ -294,14 +294,20 @@ UnicodeString MutablePatternModifier::getSymbol(AffixPatternType type) const { case AffixPatternType::TYPE_PERMILLE: return fSymbols->getSymbol(DecimalFormatSymbols::ENumberFormatSymbol::kPerMillSymbol); case AffixPatternType::TYPE_CURRENCY_SINGLE: { - // UnitWidth ISO and HIDDEN overrides the singular currency symbol. - if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE) { + switch (fUnitWidth) { + case UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW: + return fCurrencySymbols.getNarrowCurrencySymbol(localStatus); + case UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT: + return fCurrencySymbols.getCurrencySymbol(localStatus); + case UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE: return fCurrencySymbols.getIntlCurrencySymbol(localStatus); - } else if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_HIDDEN) { + case UNumberUnitWidth::UNUM_UNIT_WIDTH_FORMAL: + return fCurrencySymbols.getFormalCurrencySymbol(localStatus); + case UNumberUnitWidth::UNUM_UNIT_WIDTH_VARIANT: + return fCurrencySymbols.getVariantCurrencySymbol(localStatus); + case UNumberUnitWidth::UNUM_UNIT_WIDTH_HIDDEN: return UnicodeString(); - } else if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW) { - return fCurrencySymbols.getNarrowCurrencySymbol(localStatus); - } else { + default: return fCurrencySymbols.getCurrencySymbol(localStatus); } } diff --git a/deps/icu-small/source/i18n/number_rounding.cpp b/deps/icu-small/source/i18n/number_rounding.cpp index 3ffce673ad0885..a8fd6bc892a8a5 100644 --- a/deps/icu-small/source/i18n/number_rounding.cpp +++ b/deps/icu-small/source/i18n/number_rounding.cpp @@ -5,13 +5,16 @@ #if !UCONFIG_NO_FORMATTING +#include "charstr.h" #include "uassert.h" #include "unicode/numberformatter.h" #include "number_types.h" #include "number_decimalquantity.h" #include "double-conversion.h" #include "number_roundingutils.h" +#include "number_skeletons.h" #include "putilimp.h" +#include "string_segment.h" using namespace icu; using namespace icu::number; @@ -19,6 +22,39 @@ using namespace icu::number::impl; using double_conversion::DoubleToStringConverter; +using icu::StringSegment; + +void number::impl::parseIncrementOption(const StringSegment &segment, + Precision &outPrecision, + UErrorCode &status) { + // Need to do char <-> UChar conversion... + U_ASSERT(U_SUCCESS(status)); + CharString buffer; + SKELETON_UCHAR_TO_CHAR(buffer, segment.toTempUnicodeString(), 0, segment.length(), status); + + // Utilize DecimalQuantity/decNumber to parse this for us. + DecimalQuantity dq; + UErrorCode localStatus = U_ZERO_ERROR; + dq.setToDecNumber({buffer.data(), buffer.length()}, localStatus); + if (U_FAILURE(localStatus)) { + // throw new SkeletonSyntaxException("Invalid rounding increment", segment, e); + status = U_NUMBER_SKELETON_SYNTAX_ERROR; + return; + } + double increment = dq.toDouble(); + + // We also need to figure out how many digits. Do a brute force string operation. + int decimalOffset = 0; + while (decimalOffset < segment.length() && segment.charAt(decimalOffset) != '.') { + decimalOffset++; + } + if (decimalOffset == segment.length()) { + outPrecision = Precision::increment(increment); + } else { + int32_t fractionLength = segment.length() - decimalOffset - 1; + outPrecision = Precision::increment(increment).withMinFraction(fractionLength); + } +} namespace { @@ -84,7 +120,7 @@ digits_t roundingutils::doubleFractionLength(double input, int8_t* singleDigit) Precision Precision::unlimited() { - return Precision(RND_NONE, {}, kDefaultMode); + return Precision(RND_NONE, {}); } FractionPrecision Precision::integer() { @@ -229,7 +265,7 @@ FractionPrecision Precision::constructFraction(int32_t minFrac, int32_t maxFrac) settings.fMaxSig = -1; PrecisionUnion union_; union_.fracSig = settings; - return {RND_FRACTION, union_, kDefaultMode}; + return {RND_FRACTION, union_}; } Precision Precision::constructSignificant(int32_t minSig, int32_t maxSig) { @@ -240,7 +276,7 @@ Precision Precision::constructSignificant(int32_t minSig, int32_t maxSig) { settings.fMaxSig = static_cast(maxSig); PrecisionUnion union_; union_.fracSig = settings; - return {RND_SIGNIFICANT, union_, kDefaultMode}; + return {RND_SIGNIFICANT, union_}; } Precision @@ -250,7 +286,7 @@ Precision::constructFractionSignificant(const FractionPrecision &base, int32_t m settings.fMaxSig = static_cast(maxSig); PrecisionUnion union_; union_.fracSig = settings; - return {RND_FRACTION_SIGNIFICANT, union_, kDefaultMode}; + return {RND_FRACTION_SIGNIFICANT, union_}; } IncrementPrecision Precision::constructIncrement(double increment, int32_t minFrac) { @@ -270,18 +306,18 @@ IncrementPrecision Precision::constructIncrement(double increment, int32_t minFr // NOTE: In C++, we must return the correct value type with the correct union. // It would be invalid to return a RND_FRACTION here because the methods on the // IncrementPrecision type assume that the union is backed by increment data. - return {RND_INCREMENT_ONE, union_, kDefaultMode}; + return {RND_INCREMENT_ONE, union_}; } else if (singleDigit == 5) { - return {RND_INCREMENT_FIVE, union_, kDefaultMode}; + return {RND_INCREMENT_FIVE, union_}; } else { - return {RND_INCREMENT, union_, kDefaultMode}; + return {RND_INCREMENT, union_}; } } CurrencyPrecision Precision::constructCurrency(UCurrencyUsage usage) { PrecisionUnion union_; union_.currencyUsage = usage; - return {RND_CURRENCY, union_, kDefaultMode}; + return {RND_CURRENCY, union_}; } @@ -341,6 +377,9 @@ RoundingImpl::chooseMultiplierAndApply(impl::DecimalQuantity &input, const impl: /** This is the method that contains the actual rounding logic. */ void RoundingImpl::apply(impl::DecimalQuantity &value, UErrorCode& status) const { + if (U_FAILURE(status)) { + return; + } if (fPassThrough) { return; } diff --git a/deps/icu-small/source/i18n/number_roundingutils.h b/deps/icu-small/source/i18n/number_roundingutils.h index 3e37f3195408fe..e85cbae9fdd2ea 100644 --- a/deps/icu-small/source/i18n/number_roundingutils.h +++ b/deps/icu-small/source/i18n/number_roundingutils.h @@ -8,6 +8,7 @@ #define __NUMBER_ROUNDINGUTILS_H__ #include "number_types.h" +#include "string_segment.h" U_NAMESPACE_BEGIN namespace number { @@ -44,6 +45,9 @@ enum Section { inline bool getRoundingDirection(bool isEven, bool isNegative, Section section, RoundingMode roundingMode, UErrorCode &status) { + if (U_FAILURE(status)) { + return false; + } switch (roundingMode) { case RoundingMode::UNUM_ROUND_UP: // round away from zero @@ -187,8 +191,22 @@ class RoundingImpl { Precision fPrecision; UNumberFormatRoundingMode fRoundingMode; bool fPassThrough = true; // default value + + // Permits access to fPrecision. + friend class units::UnitsRouter; + + // Permits access to fPrecision. + friend class UnitConversionHandler; }; +/** + * Parses Precision-related skeleton strings without knowledge of MacroProps + * - see blueprint_helpers::parseIncrementOption(). + * + * Referencing MacroProps means needing to pull in the .o files that have the + * destructors for the SymbolsWrapper, Usage, and Scale classes. + */ +void parseIncrementOption(const StringSegment &segment, Precision &outPrecision, UErrorCode &status); } // namespace impl } // namespace number diff --git a/deps/icu-small/source/i18n/number_skeletons.cpp b/deps/icu-small/source/i18n/number_skeletons.cpp index 4ba2647986c755..e6d94d27b2ba5b 100644 --- a/deps/icu-small/source/i18n/number_skeletons.cpp +++ b/deps/icu-small/source/i18n/number_skeletons.cpp @@ -10,6 +10,7 @@ #define UNISTR_FROM_STRING_EXPLICIT #include "number_decnum.h" +#include "number_roundingutils.h" #include "number_skeletons.h" #include "umutex.h" #include "ucln_in.h" @@ -80,6 +81,8 @@ void U_CALLCONV initNumberSkeletons(UErrorCode& status) { b.add(u"unit-width-short", STEM_UNIT_WIDTH_SHORT, status); b.add(u"unit-width-full-name", STEM_UNIT_WIDTH_FULL_NAME, status); b.add(u"unit-width-iso-code", STEM_UNIT_WIDTH_ISO_CODE, status); + b.add(u"unit-width-formal", STEM_UNIT_WIDTH_FORMAL, status); + b.add(u"unit-width-variant", STEM_UNIT_WIDTH_VARIANT, status); b.add(u"unit-width-hidden", STEM_UNIT_WIDTH_HIDDEN, status); b.add(u"sign-auto", STEM_SIGN_AUTO, status); b.add(u"sign-always", STEM_SIGN_ALWAYS, status); @@ -97,6 +100,7 @@ void U_CALLCONV initNumberSkeletons(UErrorCode& status) { b.add(u"measure-unit", STEM_MEASURE_UNIT, status); b.add(u"per-measure-unit", STEM_PER_MEASURE_UNIT, status); b.add(u"unit", STEM_UNIT, status); + b.add(u"usage", STEM_UNIT_USAGE, status); b.add(u"currency", STEM_CURRENCY, status); b.add(u"integer-width", STEM_INTEGER_WIDTH, status); b.add(u"numbering-system", STEM_NUMBERING_SYSTEM, status); @@ -149,21 +153,6 @@ UPRV_BLOCK_MACRO_BEGIN { \ } UPRV_BLOCK_MACRO_END -#define SKELETON_UCHAR_TO_CHAR(dest, src, start, end, status) (void)(dest); \ -UPRV_BLOCK_MACRO_BEGIN { \ - UErrorCode conversionStatus = U_ZERO_ERROR; \ - (dest).appendInvariantChars({FALSE, (src).getBuffer() + (start), (end) - (start)}, conversionStatus); \ - if (conversionStatus == U_INVARIANT_CONVERSION_ERROR) { \ - /* Don't propagate the invariant conversion error; it is a skeleton syntax error */ \ - (status) = U_NUMBER_SKELETON_SYNTAX_ERROR; \ - return; \ - } else if (U_FAILURE(conversionStatus)) { \ - (status) = conversionStatus; \ - return; \ - } \ -} UPRV_BLOCK_MACRO_END - - } // anonymous namespace @@ -187,14 +176,11 @@ Notation stem_to_object::notation(skeleton::StemEnum stem) { MeasureUnit stem_to_object::unit(skeleton::StemEnum stem) { switch (stem) { case STEM_BASE_UNIT: - // Slicing is okay - return NoUnit::base(); // NOLINT + return MeasureUnit(); case STEM_PERCENT: - // Slicing is okay - return NoUnit::percent(); // NOLINT + return MeasureUnit::getPercent(); case STEM_PERMILLE: - // Slicing is okay - return NoUnit::permille(); // NOLINT + return MeasureUnit::getPermille(); default: UPRV_UNREACHABLE; } @@ -265,6 +251,10 @@ UNumberUnitWidth stem_to_object::unitWidth(skeleton::StemEnum stem) { return UNUM_UNIT_WIDTH_FULL_NAME; case STEM_UNIT_WIDTH_ISO_CODE: return UNUM_UNIT_WIDTH_ISO_CODE; + case STEM_UNIT_WIDTH_FORMAL: + return UNUM_UNIT_WIDTH_FORMAL; + case STEM_UNIT_WIDTH_VARIANT: + return UNUM_UNIT_WIDTH_VARIANT; case STEM_UNIT_WIDTH_HIDDEN: return UNUM_UNIT_WIDTH_HIDDEN; default: @@ -372,6 +362,12 @@ void enum_to_stem_string::unitWidth(UNumberUnitWidth value, UnicodeString& sb) { case UNUM_UNIT_WIDTH_ISO_CODE: sb.append(u"unit-width-iso-code", -1); break; + case UNUM_UNIT_WIDTH_FORMAL: + sb.append(u"unit-width-formal", -1); + break; + case UNUM_UNIT_WIDTH_VARIANT: + sb.append(u"unit-width-variant", -1); + break; case UNUM_UNIT_WIDTH_HIDDEN: sb.append(u"unit-width-hidden", -1); break; @@ -470,6 +466,7 @@ UnicodeString skeleton::generate(const MacroProps& macros, UErrorCode& status) { MacroProps skeleton::parseSkeleton( const UnicodeString& skeletonString, int32_t& errOffset, UErrorCode& status) { U_ASSERT(U_SUCCESS(status)); + U_ASSERT(kSerializedStemTrie != nullptr); // Add a trailing whitespace to the end of the skeleton string to make code cleaner. UnicodeString tempSkeletonString(skeletonString); @@ -550,6 +547,7 @@ MacroProps skeleton::parseSkeleton( case STATE_MEASURE_UNIT: case STATE_PER_MEASURE_UNIT: case STATE_IDENTIFIER_UNIT: + case STATE_UNIT_USAGE: case STATE_CURRENCY_UNIT: case STATE_INTEGER_WIDTH: case STATE_NUMBERING_SYSTEM: @@ -575,6 +573,8 @@ MacroProps skeleton::parseSkeleton( ParseState skeleton::parseStem(const StringSegment& segment, const UCharsTrie& stemTrie, SeenMacroProps& seen, MacroProps& macros, UErrorCode& status) { + U_ASSERT(U_SUCCESS(status)); + // First check for "blueprint" stems, which start with a "signal char" switch (segment.charAt(0)) { case u'.': @@ -683,6 +683,8 @@ skeleton::parseStem(const StringSegment& segment, const UCharsTrie& stemTrie, Se case STEM_UNIT_WIDTH_SHORT: case STEM_UNIT_WIDTH_FULL_NAME: case STEM_UNIT_WIDTH_ISO_CODE: + case STEM_UNIT_WIDTH_FORMAL: + case STEM_UNIT_WIDTH_VARIANT: case STEM_UNIT_WIDTH_HIDDEN: CHECK_NULL(seen, unitWidth, status); macros.unitWidth = stem_to_object::unitWidth(stem); @@ -705,7 +707,7 @@ skeleton::parseStem(const StringSegment& segment, const UCharsTrie& stemTrie, Se macros.decimal = stem_to_object::decimalSeparatorDisplay(stem); return STATE_NULL; - // Stems requiring an option: + // Stems requiring an option: case STEM_PRECISION_INCREMENT: CHECK_NULL(seen, precision, status); @@ -724,6 +726,10 @@ skeleton::parseStem(const StringSegment& segment, const UCharsTrie& stemTrie, Se CHECK_NULL(seen, perUnit, status); return STATE_IDENTIFIER_UNIT; + case STEM_UNIT_USAGE: + CHECK_NULL(seen, usage, status); + return STATE_UNIT_USAGE; + case STEM_CURRENCY: CHECK_NULL(seen, unit, status); return STATE_CURRENCY_UNIT; @@ -747,6 +753,7 @@ skeleton::parseStem(const StringSegment& segment, const UCharsTrie& stemTrie, Se ParseState skeleton::parseOption(ParseState stem, const StringSegment& segment, MacroProps& macros, UErrorCode& status) { + U_ASSERT(U_SUCCESS(status)); ///// Required options: ///// @@ -763,6 +770,9 @@ ParseState skeleton::parseOption(ParseState stem, const StringSegment& segment, case STATE_IDENTIFIER_UNIT: blueprint_helpers::parseIdentifierUnitOption(segment, macros, status); return STATE_NULL; + case STATE_UNIT_USAGE: + blueprint_helpers::parseUnitUsageOption(segment, macros, status); + return STATE_NULL; case STATE_INCREMENT_PRECISION: blueprint_helpers::parseIncrementOption(segment, macros, status); return STATE_NULL; @@ -833,7 +843,7 @@ void GeneratorHelpers::generateSkeleton(const MacroProps& macros, UnicodeString& sb.append(u' '); } if (U_FAILURE(status)) { return; } - if (GeneratorHelpers::perUnit(macros, sb, status)) { + if (GeneratorHelpers::usage(macros, sb, status)) { sb.append(u' '); } if (U_FAILURE(status)) { return; } @@ -968,6 +978,7 @@ blueprint_helpers::generateCurrencyOption(const CurrencyUnit& currency, UnicodeS void blueprint_helpers::parseMeasureUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status) { + U_ASSERT(U_SUCCESS(status)); const UnicodeString stemString = segment.toTempUnicodeString(); // NOTE: The category (type) of the unit is guaranteed to be a valid subtag (alphanumeric) @@ -983,14 +994,13 @@ void blueprint_helpers::parseMeasureUnitOption(const StringSegment& segment, Mac } // Need to do char <-> UChar conversion... - U_ASSERT(U_SUCCESS(status)); CharString type; SKELETON_UCHAR_TO_CHAR(type, stemString, 0, firstHyphen, status); CharString subType; SKELETON_UCHAR_TO_CHAR(subType, stemString, firstHyphen + 1, stemString.length(), status); - // Note: the largest type as of this writing (March 2018) is "volume", which has 24 units. - static constexpr int32_t CAPACITY = 30; + // Note: the largest type as of this writing (Aug 2020) is "volume", which has 33 units. + static constexpr int32_t CAPACITY = 40; MeasureUnit units[CAPACITY]; UErrorCode localStatus = U_ZERO_ERROR; int32_t numUnits = MeasureUnit::getAvailable(type.data(), units, CAPACITY, localStatus); @@ -1011,14 +1021,6 @@ void blueprint_helpers::parseMeasureUnitOption(const StringSegment& segment, Mac status = U_NUMBER_SKELETON_SYNTAX_ERROR; } -void blueprint_helpers::generateMeasureUnitOption(const MeasureUnit& measureUnit, UnicodeString& sb, - UErrorCode&) { - // Need to do char <-> UChar conversion... - sb.append(UnicodeString(measureUnit.getType(), -1, US_INV)); - sb.append(u'-'); - sb.append(UnicodeString(measureUnit.getSubtype(), -1, US_INV)); -} - void blueprint_helpers::parseMeasurePerUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status) { // A little bit of a hack: save the current unit (numerator), call the main measure unit @@ -1045,6 +1047,20 @@ void blueprint_helpers::parseIdentifierUnitOption(const StringSegment& segment, return; } + // Mixed units can only be represented by full MeasureUnit instances, so we + // don't split the denominator into macros.perUnit. + if (fullUnit.complexity == UMEASURE_UNIT_MIXED) { + macros.unit = std::move(fullUnit).build(status); + return; + } + + // When we have a built-in unit (e.g. meter-per-second), we don't split it up + MeasureUnit testBuiltin = fullUnit.copy(status).build(status); + if (uprv_strcmp(testBuiltin.getType(), "") != 0) { + macros.unit = std::move(testBuiltin); + return; + } + // TODO(ICU-20941): Clean this up. for (int32_t i = 0; i < fullUnit.units.length(); i++) { SingleUnitImpl* subUnit = fullUnit.units[i]; @@ -1057,6 +1073,17 @@ void blueprint_helpers::parseIdentifierUnitOption(const StringSegment& segment, } } +void blueprint_helpers::parseUnitUsageOption(const StringSegment &segment, MacroProps ¯os, + UErrorCode &status) { + // Need to do char <-> UChar conversion... + U_ASSERT(U_SUCCESS(status)); + CharString buffer; + SKELETON_UCHAR_TO_CHAR(buffer, segment.toTempUnicodeString(), 0, segment.length(), status); + macros.usage.set(buffer.toStringPiece()); + // We do not do any validation of the usage string: it depends on the + // unitPreferenceData in the units resources. +} + void blueprint_helpers::parseFractionStem(const StringSegment& segment, MacroProps& macros, UErrorCode& status) { U_ASSERT(segment.charAt(0) == u'.'); @@ -1301,35 +1328,9 @@ bool blueprint_helpers::parseFracSigOption(const StringSegment& segment, MacroPr return true; } -void blueprint_helpers::parseIncrementOption(const StringSegment& segment, MacroProps& macros, - UErrorCode& status) { - // Need to do char <-> UChar conversion... - U_ASSERT(U_SUCCESS(status)); - CharString buffer; - SKELETON_UCHAR_TO_CHAR(buffer, segment.toTempUnicodeString(), 0, segment.length(), status); - - // Utilize DecimalQuantity/decNumber to parse this for us. - DecimalQuantity dq; - UErrorCode localStatus = U_ZERO_ERROR; - dq.setToDecNumber({buffer.data(), buffer.length()}, localStatus); - if (U_FAILURE(localStatus)) { - // throw new SkeletonSyntaxException("Invalid rounding increment", segment, e); - status = U_NUMBER_SKELETON_SYNTAX_ERROR; - return; - } - double increment = dq.toDouble(); - - // We also need to figure out how many digits. Do a brute force string operation. - int decimalOffset = 0; - while (decimalOffset < segment.length() && segment.charAt(decimalOffset) != '.') { - decimalOffset++; - } - if (decimalOffset == segment.length()) { - macros.precision = Precision::increment(increment); - } else { - int32_t fractionLength = segment.length() - decimalOffset - 1; - macros.precision = Precision::increment(increment).withMinFraction(fractionLength); - } +void blueprint_helpers::parseIncrementOption(const StringSegment &segment, MacroProps ¯os, + UErrorCode &status) { + number::impl::parseIncrementOption(segment, macros.precision, status); } void blueprint_helpers::generateIncrementOption(double increment, int32_t trailingZeros, UnicodeString& sb, @@ -1507,42 +1508,37 @@ bool GeneratorHelpers::unit(const MacroProps& macros, UnicodeString& sb, UErrorC } blueprint_helpers::generateCurrencyOption(currency, sb, status); return true; - } else if (utils::unitIsNoUnit(macros.unit)) { - if (utils::unitIsPercent(macros.unit)) { - sb.append(u"percent", -1); - return true; - } else if (utils::unitIsPermille(macros.unit)) { - sb.append(u"permille", -1); - return true; - } else { - // Default value is not shown in normalized form + } else if (utils::unitIsBaseUnit(macros.unit)) { + // Default value is not shown in normalized form + return false; + } else if (utils::unitIsPercent(macros.unit)) { + sb.append(u"percent", -1); + return true; + } else if (utils::unitIsPermille(macros.unit)) { + sb.append(u"permille", -1); + return true; + } else { + MeasureUnit unit = macros.unit; + if (utils::unitIsCurrency(macros.perUnit)) { + status = U_UNSUPPORTED_ERROR; return false; } - } else { - sb.append(u"measure-unit/", -1); - blueprint_helpers::generateMeasureUnitOption(macros.unit, sb, status); + if (!utils::unitIsBaseUnit(macros.perUnit)) { + unit = unit.product(macros.perUnit.reciprocal(status), status); + } + sb.append(u"unit/", -1); + sb.append(unit.getIdentifier()); return true; } } -bool GeneratorHelpers::perUnit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) { - // Per-units are currently expected to be only MeasureUnits. - if (utils::unitIsNoUnit(macros.perUnit)) { - if (utils::unitIsPercent(macros.perUnit) || utils::unitIsPermille(macros.perUnit)) { - status = U_UNSUPPORTED_ERROR; - return false; - } else { - // Default value: ok to ignore - return false; - } - } else if (utils::unitIsCurrency(macros.perUnit)) { - status = U_UNSUPPORTED_ERROR; - return false; - } else { - sb.append(u"per-measure-unit/", -1); - blueprint_helpers::generateMeasureUnitOption(macros.perUnit, sb, status); +bool GeneratorHelpers::usage(const MacroProps& macros, UnicodeString& sb, UErrorCode& /* status */) { + if (macros.usage.isSet()) { + sb.append(u"usage/", -1); + sb.append(UnicodeString(macros.usage.fUsage, -1, US_INV)); return true; } + return false; } bool GeneratorHelpers::precision(const MacroProps& macros, UnicodeString& sb, UErrorCode& status) { diff --git a/deps/icu-small/source/i18n/number_skeletons.h b/deps/icu-small/source/i18n/number_skeletons.h index d9b2c0ee0b19ab..201267e635cd6a 100644 --- a/deps/icu-small/source/i18n/number_skeletons.h +++ b/deps/icu-small/source/i18n/number_skeletons.h @@ -22,10 +22,12 @@ struct SeenMacroProps; // namespace for enums and entrypoint functions namespace skeleton { -/////////////////////////////////////////////////////////////////////////////////////// -// NOTE: For an example of how to add a new stem to the number skeleton parser, see: // -// http://bugs.icu-project.org/trac/changeset/41193 // -/////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////// +// NOTE: For examples of how to add a new stem to the number skeleton parser, see: // +// https://github.com/unicode-org/icu/commit/a2a7982216b2348070dc71093775ac7195793d73 // +// and // +// https://github.com/unicode-org/icu/commit/6fe86f3934a8a5701034f648a8f7c5087e84aa28 // +//////////////////////////////////////////////////////////////////////////////////////// /** * While parsing a skeleton, this enum records what type of option we expect to find next. @@ -47,6 +49,7 @@ enum ParseState { STATE_MEASURE_UNIT, STATE_PER_MEASURE_UNIT, STATE_IDENTIFIER_UNIT, + STATE_UNIT_USAGE, STATE_CURRENCY_UNIT, STATE_INTEGER_WIDTH, STATE_NUMBERING_SYSTEM, @@ -95,6 +98,8 @@ enum StemEnum { STEM_UNIT_WIDTH_SHORT, STEM_UNIT_WIDTH_FULL_NAME, STEM_UNIT_WIDTH_ISO_CODE, + STEM_UNIT_WIDTH_FORMAL, + STEM_UNIT_WIDTH_VARIANT, STEM_UNIT_WIDTH_HIDDEN, STEM_SIGN_AUTO, STEM_SIGN_ALWAYS, @@ -112,6 +117,7 @@ enum StemEnum { STEM_MEASURE_UNIT, STEM_PER_MEASURE_UNIT, STEM_UNIT, + STEM_UNIT_USAGE, STEM_CURRENCY, STEM_INTEGER_WIDTH, STEM_NUMBERING_SYSTEM, @@ -234,14 +240,20 @@ void parseCurrencyOption(const StringSegment& segment, MacroProps& macros, UErro void generateCurrencyOption(const CurrencyUnit& currency, UnicodeString& sb, UErrorCode& status); +// "measure-unit/" is deprecated in favour of "unit/". void parseMeasureUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status); -void generateMeasureUnitOption(const MeasureUnit& measureUnit, UnicodeString& sb, UErrorCode& status); - +// "per-measure-unit/" is deprecated in favour of "unit/". void parseMeasurePerUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status); +/** + * Parses unit identifiers like "meter-per-second" and "foot-and-inch", as + * specified via a "unit/" concise skeleton. + */ void parseIdentifierUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status); +void parseUnitUsageOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status); + void parseFractionStem(const StringSegment& segment, MacroProps& macros, UErrorCode& status); void generateFractionStem(int32_t minFrac, int32_t maxFrac, UnicodeString& sb, UErrorCode& status); @@ -302,7 +314,7 @@ class GeneratorHelpers { static bool unit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status); - static bool perUnit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status); + static bool usage(const MacroProps& macros, UnicodeString& sb, UErrorCode& status); static bool precision(const MacroProps& macros, UnicodeString& sb, UErrorCode& status); @@ -332,6 +344,7 @@ struct SeenMacroProps { bool notation = false; bool unit = false; bool perUnit = false; + bool usage = false; bool precision = false; bool roundingMode = false; bool grouper = false; @@ -344,6 +357,24 @@ struct SeenMacroProps { bool scale = false; }; +namespace { + +#define SKELETON_UCHAR_TO_CHAR(dest, src, start, end, status) (void)(dest); \ +UPRV_BLOCK_MACRO_BEGIN { \ + UErrorCode conversionStatus = U_ZERO_ERROR; \ + (dest).appendInvariantChars({false, (src).getBuffer() + (start), (end) - (start)}, conversionStatus); \ + if (conversionStatus == U_INVARIANT_CONVERSION_ERROR) { \ + /* Don't propagate the invariant conversion error; it is a skeleton syntax error */ \ + (status) = U_NUMBER_SKELETON_SYNTAX_ERROR; \ + return; \ + } else if (U_FAILURE(conversionStatus)) { \ + (status) = conversionStatus; \ + return; \ + } \ +} UPRV_BLOCK_MACRO_END + +} // namespace + } // namespace impl } // namespace number U_NAMESPACE_END diff --git a/deps/icu-small/source/i18n/number_symbolswrapper.cpp b/deps/icu-small/source/i18n/number_symbolswrapper.cpp new file mode 100644 index 00000000000000..ac3043d1ca11c2 --- /dev/null +++ b/deps/icu-small/source/i18n/number_symbolswrapper.cpp @@ -0,0 +1,131 @@ +// © 2020 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING + +#include "number_microprops.h" +#include "unicode/numberformatter.h" + +using namespace icu; +using namespace icu::number; +using namespace icu::number::impl; + +SymbolsWrapper::SymbolsWrapper(const SymbolsWrapper &other) { + doCopyFrom(other); +} + +SymbolsWrapper::SymbolsWrapper(SymbolsWrapper &&src) U_NOEXCEPT { + doMoveFrom(std::move(src)); +} + +SymbolsWrapper &SymbolsWrapper::operator=(const SymbolsWrapper &other) { + if (this == &other) { + return *this; + } + doCleanup(); + doCopyFrom(other); + return *this; +} + +SymbolsWrapper &SymbolsWrapper::operator=(SymbolsWrapper &&src) U_NOEXCEPT { + if (this == &src) { + return *this; + } + doCleanup(); + doMoveFrom(std::move(src)); + return *this; +} + +SymbolsWrapper::~SymbolsWrapper() { + doCleanup(); +} + +void SymbolsWrapper::setTo(const DecimalFormatSymbols &dfs) { + doCleanup(); + fType = SYMPTR_DFS; + fPtr.dfs = new DecimalFormatSymbols(dfs); +} + +void SymbolsWrapper::setTo(const NumberingSystem *ns) { + doCleanup(); + fType = SYMPTR_NS; + fPtr.ns = ns; +} + +void SymbolsWrapper::doCopyFrom(const SymbolsWrapper &other) { + fType = other.fType; + switch (fType) { + case SYMPTR_NONE: + // No action necessary + break; + case SYMPTR_DFS: + // Memory allocation failures are exposed in copyErrorTo() + if (other.fPtr.dfs != nullptr) { + fPtr.dfs = new DecimalFormatSymbols(*other.fPtr.dfs); + } else { + fPtr.dfs = nullptr; + } + break; + case SYMPTR_NS: + // Memory allocation failures are exposed in copyErrorTo() + if (other.fPtr.ns != nullptr) { + fPtr.ns = new NumberingSystem(*other.fPtr.ns); + } else { + fPtr.ns = nullptr; + } + break; + } +} + +void SymbolsWrapper::doMoveFrom(SymbolsWrapper &&src) { + fType = src.fType; + switch (fType) { + case SYMPTR_NONE: + // No action necessary + break; + case SYMPTR_DFS: + fPtr.dfs = src.fPtr.dfs; + src.fPtr.dfs = nullptr; + break; + case SYMPTR_NS: + fPtr.ns = src.fPtr.ns; + src.fPtr.ns = nullptr; + break; + } +} + +void SymbolsWrapper::doCleanup() { + switch (fType) { + case SYMPTR_NONE: + // No action necessary + break; + case SYMPTR_DFS: + delete fPtr.dfs; + break; + case SYMPTR_NS: + delete fPtr.ns; + break; + } +} + +bool SymbolsWrapper::isDecimalFormatSymbols() const { + return fType == SYMPTR_DFS; +} + +bool SymbolsWrapper::isNumberingSystem() const { + return fType == SYMPTR_NS; +} + +const DecimalFormatSymbols *SymbolsWrapper::getDecimalFormatSymbols() const { + U_ASSERT(fType == SYMPTR_DFS); + return fPtr.dfs; +} + +const NumberingSystem *SymbolsWrapper::getNumberingSystem() const { + U_ASSERT(fType == SYMPTR_NS); + return fPtr.ns; +} + +#endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/number_types.h b/deps/icu-small/source/i18n/number_types.h index 5c2b8cf8b5d19c..8078851ba3fdb3 100644 --- a/deps/icu-small/source/i18n/number_types.h +++ b/deps/icu-small/source/i18n/number_types.h @@ -246,31 +246,31 @@ class U_I18N_API ModifierStore { * itself. The {@link #processQuantity} method performs the final step in the number processing pipeline: it uses the * quantity to generate a finalized {@link MicroProps}, which can be used to render the number to output. * - *

    * In other words, this interface is used for the parts of number processing that are quantity-dependent. * - *

    * In order to allow for multiple different objects to all mutate the same MicroProps, a "chain" of MicroPropsGenerators * are linked together, and each one is responsible for manipulating a certain quantity-dependent part of the * MicroProps. At the tail of the linked list is a base instance of {@link MicroProps} with properties that are not * quantity-dependent. Each element in the linked list calls {@link #processQuantity} on its "parent", then does its * work, and then returns the result. * + * This chain of MicroPropsGenerators is typically constructed by NumberFormatterImpl::macrosToMicroGenerator() when + * constructing a NumberFormatter. + * * Exported as U_I18N_API because it is a base class for other exported types * */ class U_I18N_API MicroPropsGenerator { public: - virtual ~MicroPropsGenerator(); + virtual ~MicroPropsGenerator() = default; /** - * Considers the given {@link DecimalQuantity}, optionally mutates it, and returns a {@link MicroProps}. + * Considers the given {@link DecimalQuantity}, optionally mutates it, and + * populates a {@link MicroProps} instance. * - * @param quantity - * The quantity for consideration and optional mutation. - * @param micros - * The MicroProps instance to populate. - * @return A MicroProps instance resolved for the quantity. + * @param quantity The quantity for consideration and optional mutation. + * @param micros The MicroProps instance to populate. It will be modified as + * needed for the given quantity. */ virtual void processQuantity(DecimalQuantity& quantity, MicroProps& micros, UErrorCode& status) const = 0; diff --git a/deps/icu-small/source/i18n/number_usageprefs.cpp b/deps/icu-small/source/i18n/number_usageprefs.cpp new file mode 100644 index 00000000000000..0d9cb06c50a2ab --- /dev/null +++ b/deps/icu-small/source/i18n/number_usageprefs.cpp @@ -0,0 +1,208 @@ +// © 2020 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING + +#include "number_usageprefs.h" +#include "cstring.h" +#include "number_decimalquantity.h" +#include "number_microprops.h" +#include "number_roundingutils.h" +#include "number_skeletons.h" +#include "unicode/char16ptr.h" +#include "unicode/currunit.h" +#include "unicode/fmtable.h" +#include "unicode/measure.h" +#include "unicode/numberformatter.h" +#include "unicode/platform.h" +#include "unicode/unum.h" +#include "unicode/urename.h" +#include "units_data.h" + +using namespace icu; +using namespace icu::number; +using namespace icu::number::impl; +using icu::StringSegment; +using icu::units::ConversionRates; + +// Copy constructor +Usage::Usage(const Usage &other) : Usage() { + this->operator=(other); +} + +// Copy assignment operator +Usage &Usage::operator=(const Usage &other) { + fLength = 0; + fError = other.fError; + if (fUsage != nullptr) { + uprv_free(fUsage); + fUsage = nullptr; + } + if (other.fUsage == nullptr) { + return *this; + } + if (U_FAILURE(other.fError)) { + // We don't bother trying to allocating memory if we're in any case busy + // copying an errored Usage. + return *this; + } + fUsage = (char *)uprv_malloc(other.fLength + 1); + if (fUsage == nullptr) { + fError = U_MEMORY_ALLOCATION_ERROR; + return *this; + } + fLength = other.fLength; + uprv_strncpy(fUsage, other.fUsage, fLength + 1); + return *this; +} + +// Move constructor +Usage::Usage(Usage &&src) U_NOEXCEPT : fUsage(src.fUsage), fLength(src.fLength), fError(src.fError) { + // Take ownership away from src if necessary + src.fUsage = nullptr; +} + +// Move assignment operator +Usage &Usage::operator=(Usage &&src) U_NOEXCEPT { + if (this == &src) { + return *this; + } + if (fUsage != nullptr) { + uprv_free(fUsage); + } + fUsage = src.fUsage; + fLength = src.fLength; + fError = src.fError; + // Take ownership away from src if necessary + src.fUsage = nullptr; + return *this; +} + +Usage::~Usage() { + if (fUsage != nullptr) { + uprv_free(fUsage); + fUsage = nullptr; + } +} + +void Usage::set(StringPiece value) { + if (fUsage != nullptr) { + uprv_free(fUsage); + fUsage = nullptr; + } + fLength = value.length(); + fUsage = (char *)uprv_malloc(fLength + 1); + if (fUsage == nullptr) { + fLength = 0; + fError = U_MEMORY_ALLOCATION_ERROR; + return; + } + uprv_strncpy(fUsage, value.data(), fLength); + fUsage[fLength] = 0; +} + +// Populates micros.mixedMeasures and modifies quantity, based on the values in +// measures. +void mixedMeasuresToMicros(const MaybeStackVector &measures, DecimalQuantity *quantity, + MicroProps *micros, UErrorCode status) { + micros->mixedMeasuresCount = measures.length() - 1; + if (micros->mixedMeasuresCount > 0) { +#ifdef U_DEBUG + U_ASSERT(micros->outputUnit.getComplexity(status) == UMEASURE_UNIT_MIXED); + U_ASSERT(U_SUCCESS(status)); + // Check that we received measurements with the expected MeasureUnits: + MeasureUnitImpl temp; + const MeasureUnitImpl& impl = MeasureUnitImpl::forMeasureUnit(micros->outputUnit, temp, status); + U_ASSERT(U_SUCCESS(status)); + U_ASSERT(measures.length() == impl.units.length()); + for (int32_t i = 0; i < measures.length(); i++) { + U_ASSERT(measures[i]->getUnit() == impl.units[i]->build(status)); + } + (void)impl; +#endif + // Mixed units: except for the last value, we pass all values to the + // LongNameHandler via micros->mixedMeasures. + if (micros->mixedMeasures.getCapacity() < micros->mixedMeasuresCount) { + if (micros->mixedMeasures.resize(micros->mixedMeasuresCount) == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + } + for (int32_t i = 0; i < micros->mixedMeasuresCount; i++) { + micros->mixedMeasures[i] = measures[i]->getNumber().getInt64(); + } + } else { + micros->mixedMeasuresCount = 0; + } + // The last value (potentially the only value) gets passed on via quantity. + quantity->setToDouble(measures[measures.length() - 1]->getNumber().getDouble()); +} + +UsagePrefsHandler::UsagePrefsHandler(const Locale &locale, + const MeasureUnit &inputUnit, + const StringPiece usage, + const MicroPropsGenerator *parent, + UErrorCode &status) + : fUnitsRouter(inputUnit, StringPiece(locale.getCountry()), usage, status), + fParent(parent) { +} + +void UsagePrefsHandler::processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const { + fParent->processQuantity(quantity, micros, status); + if (U_FAILURE(status)) { + return; + } + + quantity.roundToInfinity(); // Enables toDouble + const units::RouteResult routed = fUnitsRouter.route(quantity.toDouble(), µs.rounder, status); + if (U_FAILURE(status)) { + return; + } + const MaybeStackVector& routedMeasures = routed.measures; + micros.outputUnit = routed.outputUnit.copy(status).build(status); + if (U_FAILURE(status)) { + return; + } + + mixedMeasuresToMicros(routedMeasures, &quantity, µs, status); +} + +UnitConversionHandler::UnitConversionHandler(const MeasureUnit &inputUnit, const MeasureUnit &outputUnit, + const MicroPropsGenerator *parent, UErrorCode &status) + : fOutputUnit(outputUnit), fParent(parent) { + MeasureUnitImpl tempInput, tempOutput; + const MeasureUnitImpl &inputUnitImpl = MeasureUnitImpl::forMeasureUnit(inputUnit, tempInput, status); + const MeasureUnitImpl &outputUnitImpl = + MeasureUnitImpl::forMeasureUnit(outputUnit, tempOutput, status); + + // TODO: this should become an initOnce thing? Review with other + // ConversionRates usages. + ConversionRates conversionRates(status); + if (U_FAILURE(status)) { + return; + } + fUnitConverter.adoptInsteadAndCheckErrorCode( + new ComplexUnitsConverter(inputUnitImpl, outputUnitImpl, conversionRates, status), status); +} + +void UnitConversionHandler::processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const { + fParent->processQuantity(quantity, micros, status); + if (U_FAILURE(status)) { + return; + } + quantity.roundToInfinity(); // Enables toDouble + MaybeStackVector measures = + fUnitConverter->convert(quantity.toDouble(), µs.rounder, status); + micros.outputUnit = fOutputUnit; + if (U_FAILURE(status)) { + return; + } + + mixedMeasuresToMicros(measures, &quantity, µs, status); +} + +#endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/number_usageprefs.h b/deps/icu-small/source/i18n/number_usageprefs.h new file mode 100644 index 00000000000000..9e8bd936bd7248 --- /dev/null +++ b/deps/icu-small/source/i18n/number_usageprefs.h @@ -0,0 +1,125 @@ +// © 2020 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING +#ifndef __NUMBER_USAGEPREFS_H__ +#define __NUMBER_USAGEPREFS_H__ + +#include "cmemory.h" +#include "number_types.h" +#include "unicode/listformatter.h" +#include "unicode/localpointer.h" +#include "unicode/locid.h" +#include "unicode/measunit.h" +#include "unicode/stringpiece.h" +#include "unicode/uobject.h" +#include "units_converter.h" +#include "units_router.h" + +U_NAMESPACE_BEGIN + +using ::icu::units::ComplexUnitsConverter; +using ::icu::units::UnitsRouter; + +namespace number { +namespace impl { + +/** + * A MicroPropsGenerator which uses UnitsRouter to produce output converted to a + * MeasureUnit appropriate for a particular localized usage: see + * NumberFormatterSettings::usage(). + */ +class U_I18N_API UsagePrefsHandler : public MicroPropsGenerator, public UMemory { + public: + UsagePrefsHandler(const Locale &locale, const MeasureUnit &inputUnit, const StringPiece usage, + const MicroPropsGenerator *parent, UErrorCode &status); + + /** + * Obtains the appropriate output value, MeasureUnit and + * rounding/precision behaviour from the UnitsRouter. + * + * The output unit is passed on to the LongNameHandler via + * micros.outputUnit. + */ + void processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const U_OVERRIDE; + + /** + * Returns the list of possible output units, i.e. the full set of + * preferences, for the localized, usage-specific unit preferences. + * + * The returned pointer should be valid for the lifetime of the + * UsagePrefsHandler instance. + */ + const MaybeStackVector *getOutputUnits() const { + return fUnitsRouter.getOutputUnits(); + } + + private: + UnitsRouter fUnitsRouter; + const MicroPropsGenerator *fParent; +}; + +} // namespace impl +} // namespace number + +// Export explicit template instantiations of LocalPointerBase and LocalPointer. +// This is required when building DLLs for Windows. (See datefmt.h, +// collationiterator.h, erarules.h and others for similar examples.) +// +// Note: These need to be outside of the number::impl namespace, or Clang will +// generate a compile error. +#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN +#if defined(_MSC_VER) +// Ignore warning 4661 as LocalPointerBase does not use operator== or operator!= +#pragma warning(push) +#pragma warning(disable: 4661) +#endif +template class U_I18N_API LocalPointerBase; +template class U_I18N_API LocalPointer; +#if defined(_MSC_VER) +#pragma warning(pop) +#endif +#endif + +namespace number { +namespace impl { + +/** + * A MicroPropsGenerator which converts a measurement from one MeasureUnit to + * another. In particular, the output MeasureUnit may be a mixed unit. (The + * input unit may not be a mixed unit.) + */ +class U_I18N_API UnitConversionHandler : public MicroPropsGenerator, public UMemory { + public: + /** + * Constructor. + * + * @param inputUnit Specifies the input MeasureUnit. Mixed units are not + * supported as input (because input is just a single decimal quantity). + * @param outputUnit Specifies the output MeasureUnit. + * @param parent The parent MicroPropsGenerator. + * @param status Receives status. + */ + UnitConversionHandler(const MeasureUnit &inputUnit, const MeasureUnit &outputUnit, + const MicroPropsGenerator *parent, UErrorCode &status); + + /** + * Obtains the appropriate output values from the Unit Converter. + */ + void processQuantity(DecimalQuantity &quantity, MicroProps µs, + UErrorCode &status) const U_OVERRIDE; + private: + MeasureUnit fOutputUnit; + LocalPointer fUnitConverter; + const MicroPropsGenerator *fParent; +}; + +} // namespace impl +} // namespace number +U_NAMESPACE_END + +#endif // __NUMBER_USAGEPREFS_H__ +#endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/number_utils.cpp b/deps/icu-small/source/i18n/number_utils.cpp index 91d7f335cd82d3..bef7ea6c61f30b 100644 --- a/deps/icu-small/source/i18n/number_utils.cpp +++ b/deps/icu-small/source/i18n/number_utils.cpp @@ -258,7 +258,10 @@ void DecNum::toString(ByteSink& output, UErrorCode& status) const { } // "string must be at least dn->digits+14 characters long" int32_t minCapacity = fData.getAlias()->digits + 14; - MaybeStackArray buffer(minCapacity); + MaybeStackArray buffer(minCapacity, status); + if (U_FAILURE(status)) { + return; + } uprv_decNumberToString(fData, buffer.getAlias()); output.Append(buffer.getAlias(), static_cast(uprv_strlen(buffer.getAlias()))); } diff --git a/deps/icu-small/source/i18n/number_utils.h b/deps/icu-small/source/i18n/number_utils.h index 93195f080b2787..bc369c940f7962 100644 --- a/deps/icu-small/source/i18n/number_utils.h +++ b/deps/icu-small/source/i18n/number_utils.h @@ -49,8 +49,8 @@ inline bool unitIsCurrency(const MeasureUnit& unit) { return uprv_strcmp("currency", unit.getType()) == 0; } -inline bool unitIsNoUnit(const MeasureUnit& unit) { - return uprv_strcmp("none", unit.getType()) == 0; +inline bool unitIsBaseUnit(const MeasureUnit& unit) { + return unit == MeasureUnit(); } inline bool unitIsPercent(const MeasureUnit& unit) { diff --git a/deps/icu-small/source/i18n/number_utypes.h b/deps/icu-small/source/i18n/number_utypes.h index 7a1b7a4e80ac31..d97eadc5cdb96e 100644 --- a/deps/icu-small/source/i18n/number_utypes.h +++ b/deps/icu-small/source/i18n/number_utypes.h @@ -28,9 +28,6 @@ const DecimalQuantity* validateUFormattedNumberToDecimalQuantity( * This struct is held internally by the C++ version FormattedNumber since the member types are not * declared in the public header file. * - * The DecimalQuantity is not currently being used by FormattedNumber, but at some point it could be used - * to add a toDecNumber() or similar method. - * * Exported as U_I18N_API for tests */ class U_I18N_API UFormattedNumberData : public FormattedValueStringBuilderImpl { @@ -38,7 +35,13 @@ class U_I18N_API UFormattedNumberData : public FormattedValueStringBuilderImpl { UFormattedNumberData() : FormattedValueStringBuilderImpl(kUndefinedField) {} virtual ~UFormattedNumberData(); + // The formatted quantity. DecimalQuantity quantity; + + // The output unit for the formatted quantity. + // TODO(units,hugovdm): populate this correctly for the general case - it's + // currently only implemented for the .usage() use case. + MeasureUnit outputUnit; }; diff --git a/deps/icu-small/source/i18n/numparse_affixes.cpp b/deps/icu-small/source/i18n/numparse_affixes.cpp index 187830fb6fc0df..cef1685d03cd85 100644 --- a/deps/icu-small/source/i18n/numparse_affixes.cpp +++ b/deps/icu-small/source/i18n/numparse_affixes.cpp @@ -127,8 +127,8 @@ void AffixPatternMatcherBuilder::addMatcher(NumberParseMatcher& matcher) { fMatchers[fMatchersLen++] = &matcher; } -AffixPatternMatcher AffixPatternMatcherBuilder::build() { - return AffixPatternMatcher(fMatchers, fMatchersLen, fPattern); +AffixPatternMatcher AffixPatternMatcherBuilder::build(UErrorCode& status) { + return AffixPatternMatcher(fMatchers, fMatchersLen, fPattern, status); } AffixTokenMatcherWarehouse::AffixTokenMatcherWarehouse(const AffixTokenMatcherSetupData* setupData) @@ -209,12 +209,13 @@ AffixPatternMatcher AffixPatternMatcher::fromAffixPattern(const UnicodeString& a AffixPatternMatcherBuilder builder(affixPattern, tokenWarehouse, ignorables); AffixUtils::iterateWithConsumer(affixPattern, builder, status); - return builder.build(); + return builder.build(status); } AffixPatternMatcher::AffixPatternMatcher(MatcherArray& matchers, int32_t matchersLen, - const UnicodeString& pattern) - : ArraySeriesMatcher(matchers, matchersLen), fPattern(pattern) {} + const UnicodeString& pattern, UErrorCode& status) + : ArraySeriesMatcher(matchers, matchersLen), fPattern(pattern, status) { +} UnicodeString AffixPatternMatcher::getPattern() const { return fPattern.toAliasedUnicodeString(); diff --git a/deps/icu-small/source/i18n/numparse_affixes.h b/deps/icu-small/source/i18n/numparse_affixes.h index 2ac69df109519e..511c73c745380d 100644 --- a/deps/icu-small/source/i18n/numparse_affixes.h +++ b/deps/icu-small/source/i18n/numparse_affixes.h @@ -128,7 +128,7 @@ class AffixPatternMatcherBuilder : public TokenConsumer, public MutableMatcherCo void consumeToken(::icu::number::impl::AffixPatternType type, UChar32 cp, UErrorCode& status) override; /** NOTE: You can build only once! */ - AffixPatternMatcher build(); + AffixPatternMatcher build(UErrorCode& status); private: ArraySeriesMatcher::MatcherArray fMatchers; @@ -160,7 +160,8 @@ class U_I18N_API AffixPatternMatcher : public ArraySeriesMatcher { private: CompactUnicodeString<4> fPattern; - AffixPatternMatcher(MatcherArray& matchers, int32_t matchersLen, const UnicodeString& pattern); + AffixPatternMatcher(MatcherArray& matchers, int32_t matchersLen, const UnicodeString& pattern, + UErrorCode& status); friend class AffixPatternMatcherBuilder; }; diff --git a/deps/icu-small/source/i18n/numparse_types.h b/deps/icu-small/source/i18n/numparse_types.h index b4007c2ff5b52c..623f0e80f1668a 100644 --- a/deps/icu-small/source/i18n/numparse_types.h +++ b/deps/icu-small/source/i18n/numparse_types.h @@ -64,14 +64,15 @@ class CompactUnicodeString { fBuffer[0] = 0; } - CompactUnicodeString(const UnicodeString& text) - : fBuffer(text.length() + 1) { + CompactUnicodeString(const UnicodeString& text, UErrorCode& status) + : fBuffer(text.length() + 1, status) { + if (U_FAILURE(status)) { return; } uprv_memcpy(fBuffer.getAlias(), text.getBuffer(), sizeof(UChar) * text.length()); fBuffer[text.length()] = 0; } inline UnicodeString toAliasedUnicodeString() const { - return UnicodeString(TRUE, fBuffer.getAlias(), -1); + return UnicodeString(true, fBuffer.getAlias(), -1); } bool operator==(const CompactUnicodeString& other) const { diff --git a/deps/icu-small/source/i18n/numrange_capi.cpp b/deps/icu-small/source/i18n/numrange_capi.cpp new file mode 100644 index 00000000000000..a440a53fe6b173 --- /dev/null +++ b/deps/icu-small/source/i18n/numrange_capi.cpp @@ -0,0 +1,193 @@ +// © 2018 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING + +// Allow implicit conversion from char16_t* to UnicodeString for this file: +// Helpful in toString methods and elsewhere. +#define UNISTR_FROM_STRING_EXPLICIT + +#include "fphdlimp.h" +#include "number_utypes.h" +#include "numparse_types.h" +#include "formattedval_impl.h" +#include "numrange_impl.h" +#include "number_decnum.h" +#include "unicode/numberrangeformatter.h" +#include "unicode/unumberrangeformatter.h" + +using namespace icu; +using namespace icu::number; +using namespace icu::number::impl; + + +U_NAMESPACE_BEGIN +namespace number { +namespace impl { + +/** + * Implementation class for UNumberRangeFormatter. Wraps a LocalizedRangeNumberFormatter. + */ +struct UNumberRangeFormatterData : public UMemory, + // Magic number as ASCII == "NRF" (NumberRangeFormatter) + public IcuCApiHelper { + LocalizedNumberRangeFormatter fFormatter; +}; + +struct UFormattedNumberRangeImpl; + +// Magic number as ASCII == "FDN" (FormatteDNumber) +typedef IcuCApiHelper UFormattedNumberRangeApiHelper; + +struct UFormattedNumberRangeImpl : public UFormattedValueImpl, public UFormattedNumberRangeApiHelper { + UFormattedNumberRangeImpl(); + ~UFormattedNumberRangeImpl(); + + FormattedNumberRange fImpl; + UFormattedNumberRangeData fData; +}; + +UFormattedNumberRangeImpl::UFormattedNumberRangeImpl() + : fImpl(&fData) { + fFormattedValue = &fImpl; +} + +UFormattedNumberRangeImpl::~UFormattedNumberRangeImpl() { + // Disown the data from fImpl so it doesn't get deleted twice + fImpl.fData = nullptr; +} + +} // namespace impl +} // namespace number +U_NAMESPACE_END + + +UPRV_FORMATTED_VALUE_CAPI_NO_IMPLTYPE_AUTO_IMPL( + UFormattedNumberRange, + UFormattedNumberRangeImpl, + UFormattedNumberRangeApiHelper, + unumrf) + + +const UFormattedNumberRangeData* number::impl::validateUFormattedNumberRange( + const UFormattedNumberRange* uresult, UErrorCode& status) { + auto* result = UFormattedNumberRangeApiHelper::validate(uresult, status); + if (U_FAILURE(status)) { + return nullptr; + } + return &result->fData; +} + + +U_CAPI UNumberRangeFormatter* U_EXPORT2 +unumrf_openForSkeletonWithCollapseAndIdentityFallback( + const UChar* skeleton, + int32_t skeletonLen, + UNumberRangeCollapse collapse, + UNumberRangeIdentityFallback identityFallback, + const char* locale, + UParseError* perror, + UErrorCode* ec) { + auto* impl = new UNumberRangeFormatterData(); + if (impl == nullptr) { + *ec = U_MEMORY_ALLOCATION_ERROR; + return nullptr; + } + // Readonly-alias constructor (first argument is whether we are NUL-terminated) + UnicodeString skeletonString(skeletonLen == -1, skeleton, skeletonLen); + impl->fFormatter = NumberRangeFormatter::withLocale(locale) + .numberFormatterBoth(NumberFormatter::forSkeleton(skeletonString, *perror, *ec)) + .collapse(collapse) + .identityFallback(identityFallback); + return impl->exportForC(); +} + +U_CAPI void U_EXPORT2 +unumrf_formatDoubleRange( + const UNumberRangeFormatter* uformatter, + double first, + double second, + UFormattedNumberRange* uresult, + UErrorCode* ec) { + const UNumberRangeFormatterData* formatter = UNumberRangeFormatterData::validate(uformatter, *ec); + auto* result = UFormattedNumberRangeApiHelper::validate(uresult, *ec); + if (U_FAILURE(*ec)) { return; } + + result->fData.getStringRef().clear(); + result->fData.quantity1.setToDouble(first); + result->fData.quantity2.setToDouble(second); + formatter->fFormatter.formatImpl(result->fData, first == second, *ec); +} + +U_CAPI void U_EXPORT2 +unumrf_formatDecimalRange( + const UNumberRangeFormatter* uformatter, + const char* first, int32_t firstLen, + const char* second, int32_t secondLen, + UFormattedNumberRange* uresult, + UErrorCode* ec) { + const UNumberRangeFormatterData* formatter = UNumberRangeFormatterData::validate(uformatter, *ec); + auto* result = UFormattedNumberRangeApiHelper::validate(uresult, *ec); + if (U_FAILURE(*ec)) { return; } + + result->fData.getStringRef().clear(); + result->fData.quantity1.setToDecNumber({first, firstLen}, *ec); + result->fData.quantity2.setToDecNumber({second, secondLen}, *ec); + formatter->fFormatter.formatImpl(result->fData, first == second, *ec); +} + +U_CAPI UNumberRangeIdentityResult U_EXPORT2 +unumrf_resultGetIdentityResult( + const UFormattedNumberRange* uresult, + UErrorCode* ec) { + auto* result = UFormattedNumberRangeApiHelper::validate(uresult, *ec); + if (U_FAILURE(*ec)) { + return UNUM_IDENTITY_RESULT_COUNT; + } + return result->fData.identityResult; +} + +U_CAPI int32_t U_EXPORT2 +unumrf_resultGetFirstDecimalNumber( + const UFormattedNumberRange* uresult, + char* dest, + int32_t destCapacity, + UErrorCode* ec) { + const auto* result = UFormattedNumberRangeApiHelper::validate(uresult, *ec); + if (U_FAILURE(*ec)) { + return 0; + } + DecNum decnum; + return result->fData.quantity1.toDecNum(decnum, *ec) + .toCharString(*ec) + .extract(dest, destCapacity, *ec); +} + +U_CAPI int32_t U_EXPORT2 +unumrf_resultGetSecondDecimalNumber( + const UFormattedNumberRange* uresult, + char* dest, + int32_t destCapacity, + UErrorCode* ec) { + const auto* result = UFormattedNumberRangeApiHelper::validate(uresult, *ec); + if (U_FAILURE(*ec)) { + return 0; + } + DecNum decnum; + return result->fData.quantity2 + .toDecNum(decnum, *ec) + .toCharString(*ec) + .extract(dest, destCapacity, *ec); +} + +U_CAPI void U_EXPORT2 +unumrf_close(UNumberRangeFormatter* f) { + UErrorCode localStatus = U_ZERO_ERROR; + const UNumberRangeFormatterData* impl = UNumberRangeFormatterData::validate(f, localStatus); + delete impl; +} + + +#endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/numrange_fluent.cpp b/deps/icu-small/source/i18n/numrange_fluent.cpp index 33179026f8d2b5..d9286d1d713d2c 100644 --- a/deps/icu-small/source/i18n/numrange_fluent.cpp +++ b/deps/icu-small/source/i18n/numrange_fluent.cpp @@ -12,6 +12,7 @@ #include "numrange_impl.h" #include "util.h" #include "number_utypes.h" +#include "number_decnum.h" using namespace icu; using namespace icu::number; @@ -375,28 +376,4 @@ LocalizedNumberRangeFormatter::getFormatter(UErrorCode& status) const { } -UPRV_FORMATTED_VALUE_SUBCLASS_AUTO_IMPL(FormattedNumberRange) - -#define UPRV_NOARG - -UnicodeString FormattedNumberRange::getFirstDecimal(UErrorCode& status) const { - UPRV_FORMATTED_VALUE_METHOD_GUARD(ICU_Utility::makeBogusString()) - return fData->quantity1.toScientificString(); -} - -UnicodeString FormattedNumberRange::getSecondDecimal(UErrorCode& status) const { - UPRV_FORMATTED_VALUE_METHOD_GUARD(ICU_Utility::makeBogusString()) - return fData->quantity2.toScientificString(); -} - -UNumberRangeIdentityResult FormattedNumberRange::getIdentityResult(UErrorCode& status) const { - UPRV_FORMATTED_VALUE_METHOD_GUARD(UNUM_IDENTITY_RESULT_NOT_EQUAL) - return fData->identityResult; -} - - -UFormattedNumberRangeData::~UFormattedNumberRangeData() = default; - - - #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/numrange_impl.cpp b/deps/icu-small/source/i18n/numrange_impl.cpp index 9fb3dee861f1f6..3aae5c23548349 100644 --- a/deps/icu-small/source/i18n/numrange_impl.cpp +++ b/deps/icu-small/source/i18n/numrange_impl.cpp @@ -12,6 +12,7 @@ #include "unicode/numberrangeformatter.h" #include "numrange_impl.h" #include "patternprops.h" +#include "pluralranges.h" #include "uresimp.h" #include "util.h" @@ -106,92 +107,9 @@ void getNumberRangeData(const char* localeName, const char* nsName, NumberRangeD sink.fillInDefaults(status); } -class PluralRangesDataSink : public ResourceSink { - public: - PluralRangesDataSink(StandardPluralRanges& output) : fOutput(output) {} - - void put(const char* /*key*/, ResourceValue& value, UBool /*noFallback*/, UErrorCode& status) U_OVERRIDE { - ResourceArray entriesArray = value.getArray(status); - if (U_FAILURE(status)) { return; } - fOutput.setCapacity(entriesArray.getSize()); - for (int i = 0; entriesArray.getValue(i, value); i++) { - ResourceArray pluralFormsArray = value.getArray(status); - if (U_FAILURE(status)) { return; } - pluralFormsArray.getValue(0, value); - StandardPlural::Form first = StandardPlural::fromString(value.getUnicodeString(status), status); - if (U_FAILURE(status)) { return; } - pluralFormsArray.getValue(1, value); - StandardPlural::Form second = StandardPlural::fromString(value.getUnicodeString(status), status); - if (U_FAILURE(status)) { return; } - pluralFormsArray.getValue(2, value); - StandardPlural::Form result = StandardPlural::fromString(value.getUnicodeString(status), status); - if (U_FAILURE(status)) { return; } - fOutput.addPluralRange(first, second, result); - } - } - - private: - StandardPluralRanges& fOutput; -}; - -void getPluralRangesData(const Locale& locale, StandardPluralRanges& output, UErrorCode& status) { - if (U_FAILURE(status)) { return; } - LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "pluralRanges", &status)); - if (U_FAILURE(status)) { return; } - - CharString dataPath; - dataPath.append("locales/", -1, status); - dataPath.append(locale.getLanguage(), -1, status); - if (U_FAILURE(status)) { return; } - int32_t setLen; - // Not all languages are covered: fail gracefully - UErrorCode internalStatus = U_ZERO_ERROR; - const UChar* set = ures_getStringByKeyWithFallback(rb.getAlias(), dataPath.data(), &setLen, &internalStatus); - if (U_FAILURE(internalStatus)) { return; } - - dataPath.clear(); - dataPath.append("rules/", -1, status); - dataPath.appendInvariantChars(set, setLen, status); - if (U_FAILURE(status)) { return; } - PluralRangesDataSink sink(output); - ures_getAllItemsWithFallback(rb.getAlias(), dataPath.data(), sink, status); - if (U_FAILURE(status)) { return; } -} - } // namespace -void StandardPluralRanges::initialize(const Locale& locale, UErrorCode& status) { - getPluralRangesData(locale, *this, status); -} - -void StandardPluralRanges::addPluralRange( - StandardPlural::Form first, - StandardPlural::Form second, - StandardPlural::Form result) { - U_ASSERT(fTriplesLen < fTriples.getCapacity()); - fTriples[fTriplesLen] = {first, second, result}; - fTriplesLen++; -} - -void StandardPluralRanges::setCapacity(int32_t length) { - if (length > fTriples.getCapacity()) { - fTriples.resize(length, 0); - } -} - -StandardPlural::Form -StandardPluralRanges::resolve(StandardPlural::Form first, StandardPlural::Form second) const { - for (int32_t i=0; i PluralRangeTriples; - PluralRangeTriples fTriples; - int32_t fTriplesLen = 0; -}; - - class NumberRangeFormatterImpl : public UMemory { public: NumberRangeFormatterImpl(const RangeMacroProps& macros, UErrorCode& status); @@ -105,6 +76,11 @@ class NumberRangeFormatterImpl : public UMemory { }; +/** Helper function used in upluralrules.cpp */ +const UFormattedNumberRangeData* validateUFormattedNumberRange( + const UFormattedNumberRange* uresult, UErrorCode& status); + + } // namespace impl } // namespace number U_NAMESPACE_END diff --git a/deps/icu-small/source/i18n/olsontz.cpp b/deps/icu-small/source/i18n/olsontz.cpp index dd01180f8cc078..cb142f7b9e080f 100644 --- a/deps/icu-small/source/i18n/olsontz.cpp +++ b/deps/icu-small/source/i18n/olsontz.cpp @@ -197,58 +197,60 @@ OlsonTimeZone::OlsonTimeZone(const UResourceBundle* top, } // Process final rule and data, if any - const UChar *ruleIdUStr = ures_getStringByKey(res, kFINALRULE, &len, &ec); - ures_getByKey(res, kFINALRAW, r.getAlias(), &ec); - int32_t ruleRaw = ures_getInt(r.getAlias(), &ec); - ures_getByKey(res, kFINALYEAR, r.getAlias(), &ec); - int32_t ruleYear = ures_getInt(r.getAlias(), &ec); if (U_SUCCESS(ec)) { - UnicodeString ruleID(TRUE, ruleIdUStr, len); - UResourceBundle *rule = TimeZone::loadRule(top, ruleID, NULL, ec); - const int32_t *ruleData = ures_getIntVector(rule, &len, &ec); - if (U_SUCCESS(ec) && len == 11) { - UnicodeString emptyStr; - finalZone = new SimpleTimeZone( - ruleRaw * U_MILLIS_PER_SECOND, - emptyStr, - (int8_t)ruleData[0], (int8_t)ruleData[1], (int8_t)ruleData[2], - ruleData[3] * U_MILLIS_PER_SECOND, - (SimpleTimeZone::TimeMode) ruleData[4], - (int8_t)ruleData[5], (int8_t)ruleData[6], (int8_t)ruleData[7], - ruleData[8] * U_MILLIS_PER_SECOND, - (SimpleTimeZone::TimeMode) ruleData[9], - ruleData[10] * U_MILLIS_PER_SECOND, ec); - if (finalZone == NULL) { - ec = U_MEMORY_ALLOCATION_ERROR; - } else { - finalStartYear = ruleYear; + const UChar *ruleIdUStr = ures_getStringByKey(res, kFINALRULE, &len, &ec); + ures_getByKey(res, kFINALRAW, r.getAlias(), &ec); + int32_t ruleRaw = ures_getInt(r.getAlias(), &ec); + ures_getByKey(res, kFINALYEAR, r.getAlias(), &ec); + int32_t ruleYear = ures_getInt(r.getAlias(), &ec); + if (U_SUCCESS(ec)) { + UnicodeString ruleID(TRUE, ruleIdUStr, len); + UResourceBundle *rule = TimeZone::loadRule(top, ruleID, NULL, ec); + const int32_t *ruleData = ures_getIntVector(rule, &len, &ec); + if (U_SUCCESS(ec) && len == 11) { + UnicodeString emptyStr; + finalZone = new SimpleTimeZone( + ruleRaw * U_MILLIS_PER_SECOND, + emptyStr, + (int8_t)ruleData[0], (int8_t)ruleData[1], (int8_t)ruleData[2], + ruleData[3] * U_MILLIS_PER_SECOND, + (SimpleTimeZone::TimeMode) ruleData[4], + (int8_t)ruleData[5], (int8_t)ruleData[6], (int8_t)ruleData[7], + ruleData[8] * U_MILLIS_PER_SECOND, + (SimpleTimeZone::TimeMode) ruleData[9], + ruleData[10] * U_MILLIS_PER_SECOND, ec); + if (finalZone == NULL) { + ec = U_MEMORY_ALLOCATION_ERROR; + } else { + finalStartYear = ruleYear; - // Note: Setting finalStartYear to the finalZone is problematic. When a date is around - // year boundary, SimpleTimeZone may return false result when DST is observed at the - // beginning of year. We could apply safe margin (day or two), but when one of recurrent - // rules falls around year boundary, it could return false result. Without setting the - // start year, finalZone works fine around the year boundary of the start year. + // Note: Setting finalStartYear to the finalZone is problematic. When a date is around + // year boundary, SimpleTimeZone may return false result when DST is observed at the + // beginning of year. We could apply safe margin (day or two), but when one of recurrent + // rules falls around year boundary, it could return false result. Without setting the + // start year, finalZone works fine around the year boundary of the start year. - // finalZone->setStartYear(finalStartYear); + // finalZone->setStartYear(finalStartYear); - // Compute the millis for Jan 1, 0:00 GMT of the finalYear + // Compute the millis for Jan 1, 0:00 GMT of the finalYear - // Note: finalStartMillis is used for detecting either if - // historic transition data or finalZone to be used. In an - // extreme edge case - for example, two transitions fall into - // small windows of time around the year boundary, this may - // result incorrect offset computation. But I think it will - // never happen practically. Yoshito - Feb 20, 2010 - finalStartMillis = Grego::fieldsToDay(finalStartYear, 0, 1) * U_MILLIS_PER_DAY; + // Note: finalStartMillis is used for detecting either if + // historic transition data or finalZone to be used. In an + // extreme edge case - for example, two transitions fall into + // small windows of time around the year boundary, this may + // result incorrect offset computation. But I think it will + // never happen practically. Yoshito - Feb 20, 2010 + finalStartMillis = Grego::fieldsToDay(finalStartYear, 0, 1) * U_MILLIS_PER_DAY; + } + } else { + ec = U_INVALID_FORMAT_ERROR; } - } else { - ec = U_INVALID_FORMAT_ERROR; + ures_close(rule); + } else if (ec == U_MISSING_RESOURCE_ERROR) { + // No final zone + ec = U_ZERO_ERROR; } - ures_close(rule); - } else if (ec == U_MISSING_RESOURCE_ERROR) { - // No final zone - ec = U_ZERO_ERROR; } // initialize canonical ID diff --git a/deps/icu-small/source/i18n/olsontz.h b/deps/icu-small/source/i18n/olsontz.h index 79601546984a23..643a695369ef48 100644 --- a/deps/icu-small/source/i18n/olsontz.h +++ b/deps/icu-small/source/i18n/olsontz.h @@ -208,7 +208,7 @@ class U_I18N_API OlsonTimeZone: public BasicTimeZone { /** * TimeZone API. For a historical zone, whether DST is used or * not varies over time. In order to approximate expected - * behavior, this method returns TRUE if DST is observed at any + * behavior, this method returns true if DST is observed at any * point in the current year. */ virtual UBool useDaylightTime() const; @@ -234,7 +234,7 @@ class U_I18N_API OlsonTimeZone: public BasicTimeZone { * @param base The base time. * @param inclusive Whether the base time is inclusive or not. * @param result Receives the first transition after the base time. - * @return TRUE if the transition is found. + * @return true if the transition is found. */ virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const; @@ -244,7 +244,7 @@ class U_I18N_API OlsonTimeZone: public BasicTimeZone { * @param base The base time. * @param inclusive Whether the base time is inclusive or not. * @param result Receives the most recent transition before the base time. - * @return TRUE if the transition is found. + * @return true if the transition is found. */ virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const; diff --git a/deps/icu-small/source/i18n/persncal.cpp b/deps/icu-small/source/i18n/persncal.cpp index 4d366d41f0dffe..ba306653af28e0 100644 --- a/deps/icu-small/source/i18n/persncal.cpp +++ b/deps/icu-small/source/i18n/persncal.cpp @@ -79,7 +79,7 @@ PersianCalendar* PersianCalendar::clone() const { } PersianCalendar::PersianCalendar(const Locale& aLocale, UErrorCode& success) - : Calendar(TimeZone::createDefault(), aLocale, success) + : Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success) { setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. } diff --git a/deps/icu-small/source/i18n/persncal.h b/deps/icu-small/source/i18n/persncal.h index a9d940db78e6c7..f330ea8a0319b2 100644 --- a/deps/icu-small/source/i18n/persncal.h +++ b/deps/icu-small/source/i18n/persncal.h @@ -295,7 +295,7 @@ class PersianCalendar : public Calendar { virtual UBool inDaylightTime(UErrorCode& status) const; /** - * Returns TRUE because the Persian Calendar does have a default century + * Returns true because the Persian Calendar does have a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/pluralranges.cpp b/deps/icu-small/source/i18n/pluralranges.cpp new file mode 100644 index 00000000000000..da10e2117d04ad --- /dev/null +++ b/deps/icu-small/source/i18n/pluralranges.cpp @@ -0,0 +1,144 @@ +// © 2018 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING + +// Allow implicit conversion from char16_t* to UnicodeString for this file: +// Helpful in toString methods and elsewhere. +#define UNISTR_FROM_STRING_EXPLICIT + +#include "unicode/numberrangeformatter.h" +#include "pluralranges.h" +#include "uresimp.h" +#include "charstr.h" +#include "uassert.h" +#include "util.h" +#include "numrange_impl.h" + +U_NAMESPACE_BEGIN + + +namespace { + +class PluralRangesDataSink : public ResourceSink { + public: + PluralRangesDataSink(StandardPluralRanges& output) : fOutput(output) {} + + void put(const char* /*key*/, ResourceValue& value, UBool /*noFallback*/, UErrorCode& status) U_OVERRIDE { + ResourceArray entriesArray = value.getArray(status); + if (U_FAILURE(status)) { return; } + fOutput.setCapacity(entriesArray.getSize(), status); + if (U_FAILURE(status)) { return; } + for (int i = 0; entriesArray.getValue(i, value); i++) { + ResourceArray pluralFormsArray = value.getArray(status); + if (U_FAILURE(status)) { return; } + if (pluralFormsArray.getSize() != 3) { + status = U_RESOURCE_TYPE_MISMATCH; + return; + } + pluralFormsArray.getValue(0, value); + StandardPlural::Form first = StandardPlural::fromString(value.getUnicodeString(status), status); + if (U_FAILURE(status)) { return; } + pluralFormsArray.getValue(1, value); + StandardPlural::Form second = StandardPlural::fromString(value.getUnicodeString(status), status); + if (U_FAILURE(status)) { return; } + pluralFormsArray.getValue(2, value); + StandardPlural::Form result = StandardPlural::fromString(value.getUnicodeString(status), status); + if (U_FAILURE(status)) { return; } + fOutput.addPluralRange(first, second, result); + } + } + + private: + StandardPluralRanges& fOutput; +}; + +void getPluralRangesData(const Locale& locale, StandardPluralRanges& output, UErrorCode& status) { + LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "pluralRanges", &status)); + if (U_FAILURE(status)) { return; } + + CharString dataPath; + dataPath.append("locales/", -1, status); + dataPath.append(locale.getLanguage(), -1, status); + if (U_FAILURE(status)) { return; } + int32_t setLen; + // Not all languages are covered: fail gracefully + UErrorCode internalStatus = U_ZERO_ERROR; + const UChar* set = ures_getStringByKeyWithFallback(rb.getAlias(), dataPath.data(), &setLen, &internalStatus); + if (U_FAILURE(internalStatus)) { return; } + + dataPath.clear(); + dataPath.append("rules/", -1, status); + dataPath.appendInvariantChars(set, setLen, status); + if (U_FAILURE(status)) { return; } + PluralRangesDataSink sink(output); + ures_getAllItemsWithFallback(rb.getAlias(), dataPath.data(), sink, status); +} + +} // namespace + + +StandardPluralRanges +StandardPluralRanges::forLocale(const Locale& locale, UErrorCode& status) { + StandardPluralRanges result; + getPluralRangesData(locale, result, status); + return result; +} + +StandardPluralRanges +StandardPluralRanges::copy(UErrorCode& status) const { + StandardPluralRanges result; + if (fTriplesLen > result.fTriples.getCapacity()) { + if (result.fTriples.resize(fTriplesLen) == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + return result; + } + } + uprv_memcpy(result.fTriples.getAlias(), + fTriples.getAlias(), + fTriplesLen * sizeof(fTriples[0])); + result.fTriplesLen = fTriplesLen; + return result; +} + +LocalPointer +StandardPluralRanges::toPointer(UErrorCode& status) && noexcept { + return LocalPointer(new StandardPluralRanges(std::move(*this)), status); +} + +void StandardPluralRanges::addPluralRange( + StandardPlural::Form first, + StandardPlural::Form second, + StandardPlural::Form result) { + U_ASSERT(fTriplesLen < fTriples.getCapacity()); + fTriples[fTriplesLen] = {first, second, result}; + fTriplesLen++; +} + +void StandardPluralRanges::setCapacity(int32_t length, UErrorCode& status) { + if (U_FAILURE(status)) { return; } + if (length > fTriples.getCapacity()) { + if (fTriples.resize(length, 0) == nullptr) { + status = U_MEMORY_ALLOCATION_ERROR; + } + } +} + +StandardPlural::Form +StandardPluralRanges::resolve(StandardPlural::Form first, StandardPlural::Form second) const { + for (int32_t i=0; i toPointer(UErrorCode& status) && noexcept; + + /** Select rule based on the first and second forms */ + StandardPlural::Form resolve(StandardPlural::Form first, StandardPlural::Form second) const; + + /** Used for data loading. */ + void addPluralRange( + StandardPlural::Form first, + StandardPlural::Form second, + StandardPlural::Form result); + + /** Used for data loading. */ + void setCapacity(int32_t length, UErrorCode& status); + + private: + struct StandardPluralRangeTriple { + StandardPlural::Form first; + StandardPlural::Form second; + StandardPlural::Form result; + }; + + // TODO: An array is simple here, but it results in linear lookup time. + // Certain locales have 20-30 entries in this list. + // Consider changing to a smarter data structure. + typedef MaybeStackArray PluralRangeTriples; + PluralRangeTriples fTriples; + int32_t fTriplesLen = 0; +}; + +U_NAMESPACE_END + +#endif /* #if !UCONFIG_NO_FORMATTING */ +#endif //__PLURALRANGES_H__ diff --git a/deps/icu-small/source/i18n/plurfmt.cpp b/deps/icu-small/source/i18n/plurfmt.cpp index b99437630e67b5..aac35c5b094ff9 100644 --- a/deps/icu-small/source/i18n/plurfmt.cpp +++ b/deps/icu-small/source/i18n/plurfmt.cpp @@ -549,9 +549,15 @@ void PluralFormat::parseType(const UnicodeString& source, const NFRule *rbnfLeni UnicodeString currArg = pattern.tempSubString(partStart->getLimit(), partLimit->getIndex() - partStart->getLimit()); if (rbnfLenientScanner != NULL) { - // If lenient parsing is turned ON, we've got some time consuming parsing ahead of us. - int32_t length = -1; - currMatchIndex = rbnfLenientScanner->findTextLenient(source, currArg, startingAt, &length); + // Check if non-lenient rule finds the text before call lenient parsing + int32_t tempIndex = source.indexOf(currArg, startingAt); + if (tempIndex >= 0) { + currMatchIndex = tempIndex; + } else { + // If lenient parsing is turned ON, we've got some time consuming parsing ahead of us. + int32_t length = -1; + currMatchIndex = rbnfLenientScanner->findTextLenient(source, currArg, startingAt, &length); + } } else { currMatchIndex = source.indexOf(currArg, startingAt); diff --git a/deps/icu-small/source/i18n/plurrule.cpp b/deps/icu-small/source/i18n/plurrule.cpp index 54e3b2cd86c960..884db7c4f59311 100644 --- a/deps/icu-small/source/i18n/plurrule.cpp +++ b/deps/icu-small/source/i18n/plurrule.cpp @@ -19,6 +19,7 @@ #include "unicode/ures.h" #include "unicode/numfmt.h" #include "unicode/decimfmt.h" +#include "unicode/numberrangeformatter.h" #include "charstr.h" #include "cmemory.h" #include "cstring.h" @@ -36,6 +37,8 @@ #include "unifiedcache.h" #include "number_decimalquantity.h" #include "util.h" +#include "pluralranges.h" +#include "numrange_impl.h" #if !UCONFIG_NO_FORMATTING @@ -56,6 +59,7 @@ static const UChar PK_VAR_N[]={LOW_N,0}; static const UChar PK_VAR_I[]={LOW_I,0}; static const UChar PK_VAR_F[]={LOW_F,0}; static const UChar PK_VAR_T[]={LOW_T,0}; +static const UChar PK_VAR_E[]={LOW_E,0}; static const UChar PK_VAR_V[]={LOW_V,0}; static const UChar PK_WITHIN[]={LOW_W,LOW_I,LOW_T,LOW_H,LOW_I,LOW_N,0}; static const UChar PK_DECIMAL[]={LOW_D,LOW_E,LOW_C,LOW_I,LOW_M,LOW_A,LOW_L,0}; @@ -67,6 +71,7 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralKeywordEnumeration) PluralRules::PluralRules(UErrorCode& /*status*/) : UObject(), mRules(nullptr), + mStandardPluralRanges(nullptr), mInternalStatus(U_ZERO_ERROR) { } @@ -74,6 +79,7 @@ PluralRules::PluralRules(UErrorCode& /*status*/) PluralRules::PluralRules(const PluralRules& other) : UObject(other), mRules(nullptr), + mStandardPluralRanges(nullptr), mInternalStatus(U_ZERO_ERROR) { *this=other; @@ -81,6 +87,7 @@ PluralRules::PluralRules(const PluralRules& other) PluralRules::~PluralRules() { delete mRules; + delete mStandardPluralRanges; } SharedPluralRules::~SharedPluralRules() { @@ -89,14 +96,20 @@ SharedPluralRules::~SharedPluralRules() { PluralRules* PluralRules::clone() const { - PluralRules* newObj = new PluralRules(*this); // Since clone doesn't have a 'status' parameter, the best we can do is return nullptr if // the newly created object was not fully constructed properly (an error occurred). - if (newObj != nullptr && U_FAILURE(newObj->mInternalStatus)) { - delete newObj; - newObj = nullptr; + UErrorCode localStatus = U_ZERO_ERROR; + return clone(localStatus); +} + +PluralRules* +PluralRules::clone(UErrorCode& status) const { + LocalPointer newObj(new PluralRules(*this), status); + if (U_SUCCESS(status) && U_FAILURE(newObj->mInternalStatus)) { + status = newObj->mInternalStatus; + newObj.adoptInstead(nullptr); } - return newObj; + return newObj.orphan(); } PluralRules& @@ -104,6 +117,8 @@ PluralRules::operator=(const PluralRules& other) { if (this != &other) { delete mRules; mRules = nullptr; + delete mStandardPluralRanges; + mStandardPluralRanges = nullptr; mInternalStatus = other.mInternalStatus; if (U_FAILURE(mInternalStatus)) { // bail out early if the object we were copying from was already 'invalid'. @@ -119,6 +134,11 @@ PluralRules::operator=(const PluralRules& other) { mInternalStatus = mRules->fInternalStatus; } } + if (other.mStandardPluralRanges != nullptr) { + mStandardPluralRanges = other.mStandardPluralRanges->copy(mInternalStatus) + .toPointer(mInternalStatus) + .orphan(); + } } return *this; } @@ -211,11 +231,8 @@ PluralRules::forLocale(const Locale& locale, UPluralType type, UErrorCode& statu if (U_FAILURE(status)) { return nullptr; } - PluralRules *result = (*shared)->clone(); + PluralRules *result = (*shared)->clone(status); shared->removeRef(); - if (result == nullptr) { - status = U_MEMORY_ALLOCATION_ERROR; - } return result; } @@ -252,6 +269,10 @@ PluralRules::internalForLocale(const Locale& locale, UPluralType type, UErrorCod // Original impl used default rules. // Ask the question to ICU Core. + newObj->mStandardPluralRanges = StandardPluralRanges::forLocale(locale, status) + .toPointer(status) + .orphan(); + return newObj.orphan(); } @@ -272,6 +293,10 @@ PluralRules::select(const number::FormattedNumber& number, UErrorCode& status) c if (U_FAILURE(status)) { return ICU_Utility::makeBogusString(); } + if (U_FAILURE(mInternalStatus)) { + status = mInternalStatus; + return ICU_Utility::makeBogusString(); + } return select(dq); } @@ -285,6 +310,33 @@ PluralRules::select(const IFixedDecimal &number) const { } } +UnicodeString +PluralRules::select(const number::FormattedNumberRange& range, UErrorCode& status) const { + return select(range.getData(status), status); +} + +UnicodeString +PluralRules::select(const number::impl::UFormattedNumberRangeData* impl, UErrorCode& status) const { + if (U_FAILURE(status)) { + return ICU_Utility::makeBogusString(); + } + if (U_FAILURE(mInternalStatus)) { + status = mInternalStatus; + return ICU_Utility::makeBogusString(); + } + if (mStandardPluralRanges == nullptr) { + // Happens if PluralRules was constructed via createRules() + status = U_UNSUPPORTED_ERROR; + return ICU_Utility::makeBogusString(); + } + auto form1 = StandardPlural::fromString(select(impl->quantity1), status); + auto form2 = StandardPlural::fromString(select(impl->quantity2), status); + if (U_FAILURE(status)) { + return ICU_Utility::makeBogusString(); + } + auto result = mStandardPluralRanges->resolve(form1, form2); + return UnicodeString(StandardPlural::getKeyword(result), -1, US_INV); +} StringEnumeration* @@ -326,9 +378,23 @@ static double scaleForInt(double d) { return scale; } +/** + * Helper method for the overrides of getSamples() for double and FixedDecimal + * return value types. Provide only one of an allocated array of doubles or + * FixedDecimals, and a nullptr for the other. + */ static int32_t -getSamplesFromString(const UnicodeString &samples, double *dest, - int32_t destCapacity, UErrorCode& status) { +getSamplesFromString(const UnicodeString &samples, double *destDbl, + FixedDecimal* destFd, int32_t destCapacity, + UErrorCode& status) { + + if ((destDbl == nullptr && destFd == nullptr) + || (destDbl != nullptr && destFd != nullptr)) { + status = U_INTERNAL_PROGRAM_ERROR; + return 0; + } + + bool isDouble = destDbl != nullptr; int32_t sampleCount = 0; int32_t sampleStartIdx = 0; int32_t sampleEndIdx = 0; @@ -346,9 +412,13 @@ getSamplesFromString(const UnicodeString &samples, double *dest, int32_t tildeIndex = sampleRange.indexOf(TILDE); if (tildeIndex < 0) { FixedDecimal fixed(sampleRange, status); - double sampleValue = fixed.source; - if (fixed.visibleDecimalDigitCount == 0 || sampleValue != floor(sampleValue)) { - dest[sampleCount++] = sampleValue; + if (isDouble) { + double sampleValue = fixed.source; + if (fixed.visibleDecimalDigitCount == 0 || sampleValue != floor(sampleValue)) { + destDbl[sampleCount++] = sampleValue; + } + } else { + destFd[sampleCount++] = fixed; } } else { @@ -375,14 +445,21 @@ getSamplesFromString(const UnicodeString &samples, double *dest, rangeLo *= scale; rangeHi *= scale; for (double n=rangeLo; n<=rangeHi; n+=1) { - // Hack Alert: don't return any decimal samples with integer values that - // originated from a format with trailing decimals. - // This API is returning doubles, which can't distinguish having displayed - // zeros to the right of the decimal. - // This results in test failures with values mapping back to a different keyword. double sampleValue = n/scale; - if (!(sampleValue == floor(sampleValue) && fixedLo.visibleDecimalDigitCount > 0)) { - dest[sampleCount++] = sampleValue; + if (isDouble) { + // Hack Alert: don't return any decimal samples with integer values that + // originated from a format with trailing decimals. + // This API is returning doubles, which can't distinguish having displayed + // zeros to the right of the decimal. + // This results in test failures with values mapping back to a different keyword. + if (!(sampleValue == floor(sampleValue) && fixedLo.visibleDecimalDigitCount > 0)) { + destDbl[sampleCount++] = sampleValue; + } + } else { + int32_t v = (int32_t) fixedLo.getPluralOperand(PluralOperand::PLURAL_OPERAND_V); + int32_t e = (int32_t) fixedLo.getPluralOperand(PluralOperand::PLURAL_OPERAND_E); + FixedDecimal newSample = FixedDecimal::createWithExponent(sampleValue, v, e); + destFd[sampleCount++] = newSample; } if (sampleCount >= destCapacity) { break; @@ -394,24 +471,52 @@ getSamplesFromString(const UnicodeString &samples, double *dest, return sampleCount; } - int32_t PluralRules::getSamples(const UnicodeString &keyword, double *dest, int32_t destCapacity, UErrorCode& status) { - if (destCapacity == 0 || U_FAILURE(status)) { + if (U_FAILURE(status)) { return 0; } if (U_FAILURE(mInternalStatus)) { status = mInternalStatus; return 0; } + if (dest != nullptr ? destCapacity < 0 : destCapacity != 0) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return 0; + } RuleChain *rc = rulesForKeyword(keyword); if (rc == nullptr) { return 0; } - int32_t numSamples = getSamplesFromString(rc->fIntegerSamples, dest, destCapacity, status); + int32_t numSamples = getSamplesFromString(rc->fIntegerSamples, dest, nullptr, destCapacity, status); if (numSamples == 0) { - numSamples = getSamplesFromString(rc->fDecimalSamples, dest, destCapacity, status); + numSamples = getSamplesFromString(rc->fDecimalSamples, dest, nullptr, destCapacity, status); + } + return numSamples; +} + +int32_t +PluralRules::getSamples(const UnicodeString &keyword, FixedDecimal *dest, + int32_t destCapacity, UErrorCode& status) { + if (U_FAILURE(status)) { + return 0; + } + if (U_FAILURE(mInternalStatus)) { + status = mInternalStatus; + return 0; + } + if (dest != nullptr ? destCapacity < 0 : destCapacity != 0) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return 0; + } + RuleChain *rc = rulesForKeyword(keyword); + if (rc == nullptr) { + return 0; + } + int32_t numSamples = getSamplesFromString(rc->fIntegerSamples, nullptr, dest, destCapacity, status); + if (numSamples == 0) { + numSamples = getSamplesFromString(rc->fDecimalSamples, nullptr, dest, destCapacity, status); } return numSamples; } @@ -600,6 +705,7 @@ PluralRuleParser::parse(const UnicodeString& ruleData, PluralRules *prules, UErr case tVariableI: case tVariableF: case tVariableT: + case tVariableE: case tVariableV: U_ASSERT(curAndConstraint != nullptr); curAndConstraint->digitsType = type; @@ -984,6 +1090,8 @@ static UnicodeString tokenString(tokenType tok) { s.append(LOW_V); break; case tVariableT: s.append(LOW_T); break; + case tVariableE: + s.append(LOW_E); break; default: s.append(TILDE); } @@ -1160,6 +1268,7 @@ PluralRuleParser::checkSyntax(UErrorCode &status) case tVariableI: case tVariableF: case tVariableT: + case tVariableE: case tVariableV: if (type != tIs && type != tMod && type != tIn && type != tNot && type != tWithin && type != tEqual && type != tNotEqual) { @@ -1176,6 +1285,7 @@ PluralRuleParser::checkSyntax(UErrorCode &status) type == tVariableI || type == tVariableF || type == tVariableT || + type == tVariableE || type == tVariableV || type == tAt)) { status = U_UNEXPECTED_TOKEN; @@ -1207,6 +1317,7 @@ PluralRuleParser::checkSyntax(UErrorCode &status) type != tVariableI && type != tVariableF && type != tVariableT && + type != tVariableE && type != tVariableV) { status = U_UNEXPECTED_TOKEN; } @@ -1384,6 +1495,8 @@ PluralRuleParser::getKeyType(const UnicodeString &token, tokenType keyType) keyType = tVariableF; } else if (0 == token.compare(PK_VAR_T, 1)) { keyType = tVariableT; + } else if (0 == token.compare(PK_VAR_E, 1)) { + keyType = tVariableE; } else if (0 == token.compare(PK_VAR_V, 1)) { keyType = tVariableV; } else if (0 == token.compare(PK_IS, 2)) { @@ -1481,13 +1594,15 @@ PluralOperand tokenTypeToPluralOperand(tokenType tt) { return PLURAL_OPERAND_V; case tVariableT: return PLURAL_OPERAND_T; + case tVariableE: + return PLURAL_OPERAND_E; default: UPRV_UNREACHABLE; // unexpected. } } -FixedDecimal::FixedDecimal(double n, int32_t v, int64_t f) { - init(n, v, f); +FixedDecimal::FixedDecimal(double n, int32_t v, int64_t f, int32_t e) { + init(n, v, f, e); // check values. TODO make into unit test. // // long visiblePower = (int) Math.pow(10, v); @@ -1503,6 +1618,10 @@ FixedDecimal::FixedDecimal(double n, int32_t v, int64_t f) { // } } +FixedDecimal::FixedDecimal(double n, int32_t v, int64_t f) { + init(n, v, f); +} + FixedDecimal::FixedDecimal(double n, int32_t v) { // Ugly, but for samples we don't care. init(n, v, getFractionalDigits(n, v)); @@ -1522,20 +1641,36 @@ FixedDecimal::FixedDecimal() { FixedDecimal::FixedDecimal(const UnicodeString &num, UErrorCode &status) { CharString cs; - cs.appendInvariantChars(num, status); + int32_t parsedExponent = 0; + + int32_t exponentIdx = num.indexOf(u'e'); + if (exponentIdx < 0) { + exponentIdx = num.indexOf(u'E'); + } + if (exponentIdx >= 0) { + cs.appendInvariantChars(num.tempSubString(0, exponentIdx), status); + int32_t expSubstrStart = exponentIdx + 1; + parsedExponent = ICU_Utility::parseAsciiInteger(num, expSubstrStart); + } + else { + cs.appendInvariantChars(num, status); + } + DecimalQuantity dl; dl.setToDecNumber(cs.toStringPiece(), status); if (U_FAILURE(status)) { init(0, 0, 0); return; } + int32_t decimalPoint = num.indexOf(DOT); double n = dl.toDouble(); if (decimalPoint == -1) { - init(n, 0, 0); + init(n, 0, 0, parsedExponent); } else { - int32_t v = num.length() - decimalPoint - 1; - init(n, v, getFractionalDigits(n, v)); + int32_t fractionNumLength = exponentIdx < 0 ? num.length() : cs.length(); + int32_t v = fractionNumLength - decimalPoint - 1; + init(n, v, getFractionalDigits(n, v), parsedExponent); } } @@ -1546,6 +1681,7 @@ FixedDecimal::FixedDecimal(const FixedDecimal &other) { decimalDigits = other.decimalDigits; decimalDigitsWithoutTrailingZeros = other.decimalDigitsWithoutTrailingZeros; intValue = other.intValue; + exponent = other.exponent; _hasIntegerValue = other._hasIntegerValue; isNegative = other.isNegative; _isNaN = other._isNaN; @@ -1554,6 +1690,10 @@ FixedDecimal::FixedDecimal(const FixedDecimal &other) { FixedDecimal::~FixedDecimal() = default; +FixedDecimal FixedDecimal::createWithExponent(double n, int32_t v, int32_t e) { + return FixedDecimal(n, v, getFractionalDigits(n, v), e); +} + void FixedDecimal::init(double n) { int32_t numFractionDigits = decimals(n); @@ -1562,10 +1702,17 @@ void FixedDecimal::init(double n) { void FixedDecimal::init(double n, int32_t v, int64_t f) { + int32_t exponent = 0; + init(n, v, f, exponent); +} + + +void FixedDecimal::init(double n, int32_t v, int64_t f, int32_t e) { isNegative = n < 0.0; source = fabs(n); _isNaN = uprv_isNaN(source); _isInfinite = uprv_isInfinite(source); + exponent = e; if (_isNaN || _isInfinite) { v = 0; f = 0; @@ -1661,7 +1808,9 @@ int64_t FixedDecimal::getFractionalDigits(double n, int32_t v) { case 3: return (int64_t)(fract*1000.0 + 0.5); default: double scaled = floor(fract * pow(10.0, (double)v) + 0.5); - if (scaled > U_INT64_MAX) { + if (scaled >= static_cast(U_INT64_MAX)) { + // Note: a double cannot accurately represent U_INT64_MAX. Casting it to double + // will round up to the next representable value, which is U_INT64_MAX + 1. return U_INT64_MAX; } else { return (int64_t)scaled; @@ -1693,7 +1842,7 @@ double FixedDecimal::getPluralOperand(PluralOperand operand) const { case PLURAL_OPERAND_F: return static_cast(decimalDigits); case PLURAL_OPERAND_T: return static_cast(decimalDigitsWithoutTrailingZeros); case PLURAL_OPERAND_V: return visibleDecimalDigitCount; - case PLURAL_OPERAND_E: return 0; + case PLURAL_OPERAND_E: return exponent; default: UPRV_UNREACHABLE; // unexpected. } @@ -1719,6 +1868,23 @@ int32_t FixedDecimal::getVisibleFractionDigitCount() const { return visibleDecimalDigitCount; } +bool FixedDecimal::operator==(const FixedDecimal &other) const { + return source == other.source && visibleDecimalDigitCount == other.visibleDecimalDigitCount + && decimalDigits == other.decimalDigits && exponent == other.exponent; +} + +UnicodeString FixedDecimal::toString() const { + char pattern[15]; + char buffer[20]; + if (exponent == 0) { + snprintf(pattern, sizeof(pattern), "%%.%df", visibleDecimalDigitCount); + snprintf(buffer, sizeof(buffer), pattern, source); + } else { + snprintf(pattern, sizeof(pattern), "%%.%dfe%%d", visibleDecimalDigitCount); + snprintf(buffer, sizeof(buffer), pattern, source, exponent); + } + return UnicodeString(buffer, -1, US_INV); +} PluralAvailableLocalesEnumeration::PluralAvailableLocalesEnumeration(UErrorCode &status) { diff --git a/deps/icu-small/source/i18n/plurrule_impl.h b/deps/icu-small/source/i18n/plurrule_impl.h index a18cb0847a840e..8849e67e571da6 100644 --- a/deps/icu-small/source/i18n/plurrule_impl.h +++ b/deps/icu-small/source/i18n/plurrule_impl.h @@ -30,6 +30,12 @@ #include "hash.h" #include "uassert.h" +/** + * A FixedDecimal version of UPLRULES_NO_UNIQUE_VALUE used in PluralRulesTest + * for parsing of samples. + */ +#define UPLRULES_NO_UNIQUE_VALUE_DECIMAL (FixedDecimal((double)-0.00123456777)) + class PluralRulesTest; U_NAMESPACE_BEGIN @@ -138,6 +144,7 @@ enum tokenType { tVariableF, tVariableV, tVariableT, + tVariableE, tDecimal, tInteger, tEOF @@ -273,7 +280,9 @@ class U_I18N_API FixedDecimal: public IFixedDecimal, public UObject { * @param n the number, e.g. 12.345 * @param v The number of visible fraction digits, e.g. 3 * @param f The fraction digits, e.g. 345 + * @param e The exponent, e.g. 7 in 1.2e7 (for compact/scientific) */ + FixedDecimal(double n, int32_t v, int64_t f, int32_t e); FixedDecimal(double n, int32_t v, int64_t f); FixedDecimal(double n, int32_t); explicit FixedDecimal(double n); @@ -282,6 +291,8 @@ class U_I18N_API FixedDecimal: public IFixedDecimal, public UObject { FixedDecimal(const UnicodeString &s, UErrorCode &ec); FixedDecimal(const FixedDecimal &other); + static FixedDecimal createWithExponent(double n, int32_t v, int32_t e); + double getPluralOperand(PluralOperand operand) const U_OVERRIDE; bool isNaN() const U_OVERRIDE; bool isInfinite() const U_OVERRIDE; @@ -291,19 +302,25 @@ class U_I18N_API FixedDecimal: public IFixedDecimal, public UObject { int32_t getVisibleFractionDigitCount() const; + void init(double n, int32_t v, int64_t f, int32_t e); void init(double n, int32_t v, int64_t f); void init(double n); UBool quickInit(double n); // Try a fast-path only initialization, - // return TRUE if successful. + // return true if successful. void adjustForMinFractionDigits(int32_t min); static int64_t getFractionalDigits(double n, int32_t v); static int32_t decimals(double n); + bool operator==(const FixedDecimal &other) const; + + UnicodeString toString() const; + double source; int32_t visibleDecimalDigitCount; int64_t decimalDigits; int64_t decimalDigitsWithoutTrailingZeros; int64_t intValue; + int32_t exponent; UBool _hasIntegerValue; UBool isNegative; UBool _isNaN; @@ -320,8 +337,8 @@ class AndConstraint : public UMemory { int32_t opNum = -1; // for mod expressions, the right operand of the mod. int32_t value = -1; // valid for 'is' rules only. UVector32 *rangeList = nullptr; // for 'in', 'within' rules. Null otherwise. - UBool negated = FALSE; // TRUE for negated rules. - UBool integerOnly = FALSE; // TRUE for 'within' rules. + UBool negated = false; // true for negated rules. + UBool integerOnly = false; // true for 'within' rules. tokenType digitsType = none; // n | i | v | f constraint. AndConstraint *next = nullptr; // Internal error status, used for errors that occur during the copy constructor. @@ -357,8 +374,8 @@ class RuleChain : public UMemory { OrConstraint *ruleHeader = nullptr; UnicodeString fDecimalSamples; // Samples strings from rule source UnicodeString fIntegerSamples; // without @decimal or @integer, otherwise unprocessed. - UBool fDecimalSamplesUnbounded = FALSE; - UBool fIntegerSamplesUnbounded = FALSE; + UBool fDecimalSamplesUnbounded = false; + UBool fIntegerSamplesUnbounded = false; // Internal error status, used for errors that occur during the copy constructor. UErrorCode fInternalStatus = U_ZERO_ERROR; diff --git a/deps/icu-small/source/i18n/quant.h b/deps/icu-small/source/i18n/quant.h index d5aa8e5eeeedee..df6924cc127ba6 100644 --- a/deps/icu-small/source/i18n/quant.h +++ b/deps/icu-small/source/i18n/quant.h @@ -62,11 +62,11 @@ class Quantifier : public UnicodeFunctor, public UnicodeMatcher { * considered for matching will be text.charAt(limit-1) in the * forward direction or text.charAt(limit+1) in the backward * direction. - * @param incremental if TRUE, then assume further characters may + * @param incremental if true, then assume further characters may * be inserted at limit and check for partial matching. Otherwise * assume the text as given is complete. * @return a match degree value indicating a full match, a partial - * match, or a mismatch. If incremental is FALSE then + * match, or a mismatch. If incremental is false then * U_PARTIAL_MATCH should never be returned. */ virtual UMatchDegree matches(const Replaceable& text, @@ -81,7 +81,7 @@ class Quantifier : public UnicodeFunctor, public UnicodeMatcher { * @return A reference to 'result'. */ virtual UnicodeString& toPattern(UnicodeString& result, - UBool escapeUnprintable = FALSE) const; + UBool escapeUnprintable = false) const; /** * Implement UnicodeMatcher diff --git a/deps/icu-small/source/i18n/quantityformatter.h b/deps/icu-small/source/i18n/quantityformatter.h index 88c3f3844e924d..30bef08634a3f4 100644 --- a/deps/icu-small/source/i18n/quantityformatter.h +++ b/deps/icu-small/source/i18n/quantityformatter.h @@ -74,18 +74,18 @@ class U_I18N_API QuantityFormatter : public UMemory { * @param variant "zero", "one", "two", "few", "many", "other" * @param rawPattern the pattern for the variant e.g "{0} meters" * @param status any error returned here. - * @return TRUE on success; FALSE if status was set to a non zero error. + * @return true on success; false if status was set to a non zero error. */ UBool addIfAbsent(const char *variant, const UnicodeString &rawPattern, UErrorCode &status); /** - * returns TRUE if this object has at least the "other" variant. + * returns true if this object has at least the "other" variant. */ UBool isValid() const; /** * Gets the pattern formatter that would be used for a particular variant. - * If isValid() returns TRUE, this method is guaranteed to return a + * If isValid() returns true, this method is guaranteed to return a * non-NULL value. */ const SimpleFormatter *getByVariant(const char *variant) const; @@ -112,7 +112,7 @@ class U_I18N_API QuantityFormatter : public UMemory { /** * Selects the standard plural form for the number/formatter/rules. - * TODO(13591): Remove this method. + * Used in MeasureFormat for backwards compatibility with NumberFormat. */ static StandardPlural::Form selectPlural( const Formattable &number, diff --git a/deps/icu-small/source/i18n/rbt.h b/deps/icu-small/source/i18n/rbt.h index b450dc23f4975c..6c34824181fec3 100644 --- a/deps/icu-small/source/i18n/rbt.h +++ b/deps/icu-small/source/i18n/rbt.h @@ -161,7 +161,7 @@ class RuleBasedTransliterator : public Transliterator { * to construct a new transliterator. * @param result the string to receive the rules. Previous * contents will be deleted. - * @param escapeUnprintable if TRUE then convert unprintable + * @param escapeUnprintable if true then convert unprintable * character to their hex escape representations, \uxxxx or * \Uxxxxxxxx. Unprintable characters are those other than * U+000A, U+0020..U+007E. diff --git a/deps/icu-small/source/i18n/rbt_pars.cpp b/deps/icu-small/source/i18n/rbt_pars.cpp index 3eb58a2a904a46..802d65d0ac9bbe 100644 --- a/deps/icu-small/source/i18n/rbt_pars.cpp +++ b/deps/icu-small/source/i18n/rbt_pars.cpp @@ -1557,7 +1557,7 @@ UChar TransliteratorParser::getSegmentStandin(int32_t seg, UErrorCode& status) { return 0; } c = variableNext++; - // Set a placeholder in the master variables vector that will be + // Set a placeholder in the primary variables vector that will be // filled in later by setSegmentObject(). We know that we will get // called first because setSegmentObject() will call us. variablesVector.addElement((void*) NULL, status); diff --git a/deps/icu-small/source/i18n/rbt_pars.h b/deps/icu-small/source/i18n/rbt_pars.h index d51f2e852bb5b4..3e6517cfeb9078 100644 --- a/deps/icu-small/source/i18n/rbt_pars.h +++ b/deps/icu-small/source/i18n/rbt_pars.h @@ -210,7 +210,7 @@ class TransliteratorParser : public UMemory { /** * Assert that the given character is NOT within the variable range. - * If it is, return FALSE. This is neccesary to ensure that the + * If it is, return false. This is neccesary to ensure that the * variable range does not overlap characters used in a rule. * @param ch the given character. * @return True, if the given character is NOT within the variable range. diff --git a/deps/icu-small/source/i18n/rbt_rule.h b/deps/icu-small/source/i18n/rbt_rule.h index eb8556df0cda5d..76feeee3913e6a 100644 --- a/deps/icu-small/source/i18n/rbt_rule.h +++ b/deps/icu-small/source/i18n/rbt_rule.h @@ -172,9 +172,9 @@ class TransliterationRule : public UMemory { * segments, or null if there are none. The array itself is adopted, * but the pointers within it are not. * @param segsCount number of elements in segs[]. - * @param anchorStart TRUE if the the rule is anchored on the left to + * @param anchorStart true if the the rule is anchored on the left to * the context start. - * @param anchorEnd TRUE if the rule is anchored on the right to the + * @param anchorEnd true if the rule is anchored on the right to the * context limit. * @param data the rule data. * @param status Output parameter filled in with success or failure status. @@ -267,11 +267,11 @@ class TransliterationRule : public UMemory { * * @param text the text * @param pos the position indices - * @param incremental if TRUE, test for partial matches that may + * @param incremental if true, test for partial matches that may * be completed by additional text inserted at pos.limit. * @return one of U_MISMATCH, * U_PARTIAL_MATCH, or U_MATCH. If - * incremental is FALSE then U_PARTIAL_MATCH will not be returned. + * incremental is false then U_PARTIAL_MATCH will not be returned. */ UMatchDegree matchAndReplace(Replaceable& text, UTransPosition& pos, diff --git a/deps/icu-small/source/i18n/rbt_set.h b/deps/icu-small/source/i18n/rbt_set.h index 9b2b8b38dba5ca..b1163a0193f862 100644 --- a/deps/icu-small/source/i18n/rbt_set.h +++ b/deps/icu-small/source/i18n/rbt_set.h @@ -123,14 +123,14 @@ class TransliterationRuleSet : public UMemory { /** * Transliterate the given text with the given UTransPosition - * indices. Return TRUE if the transliteration should continue - * or FALSE if it should halt (because of a U_PARTIAL_MATCH match). - * Note that FALSE is only ever returned if isIncremental is TRUE. + * indices. Return true if the transliteration should continue + * or false if it should halt (because of a U_PARTIAL_MATCH match). + * Note that false is only ever returned if isIncremental is true. * @param text the text to be transliterated * @param index the position indices, which will be updated - * @param isIncremental if TRUE, assume new text may be inserted - * at index.limit, and return FALSE if thre is a partial match. - * @return TRUE unless a U_PARTIAL_MATCH has been obtained, + * @param isIncremental if true, assume new text may be inserted + * at index.limit, and return false if thre is a partial match. + * @return true unless a U_PARTIAL_MATCH has been obtained, * indicating that transliteration should stop until more text * arrives. */ diff --git a/deps/icu-small/source/i18n/regexcmp.h b/deps/icu-small/source/i18n/regexcmp.h index 85b7586793b9ff..5804ff302674a1 100644 --- a/deps/icu-small/source/i18n/regexcmp.h +++ b/deps/icu-small/source/i18n/regexcmp.h @@ -104,7 +104,7 @@ class U_I18N_API RegexCompile : public UMemory { int32_t LoopOp); UBool compileInlineInterval(); // Generate inline code for a {min,max} quantifier void literalChar(UChar32 c); // Compile a literal char - void fixLiterals(UBool split=FALSE); // Generate code for pending literal characters. + void fixLiterals(UBool split=false); // Generate code for pending literal characters. void insertOp(int32_t where); // Open up a slot for a new op in the // generated code at the specified location. void appendOp(int32_t op); // Append a new op to the compiled pattern. diff --git a/deps/icu-small/source/i18n/regextxt.h b/deps/icu-small/source/i18n/regextxt.h index 9cfabbe4153416..0f64b8437e7c32 100644 --- a/deps/icu-small/source/i18n/regextxt.h +++ b/deps/icu-small/source/i18n/regextxt.h @@ -29,7 +29,7 @@ U_NAMESPACE_BEGIN #endif #ifdef REGEX_DISABLE_CHUNK_MODE -# define UTEXT_FULL_TEXT_IN_CHUNK(ut,len) (FALSE) +# define UTEXT_FULL_TEXT_IN_CHUNK(ut,len) (false) #else # define UTEXT_FULL_TEXT_IN_CHUNK(ut,len) ((0==((ut)->chunkNativeStart))&&((len)==((ut)->chunkNativeLimit))&&((len)==((ut)->nativeIndexingLimit))) #endif diff --git a/deps/icu-small/source/i18n/region.cpp b/deps/icu-small/source/i18n/region.cpp index 198bea8f643a5b..8364bd1c1b2280 100644 --- a/deps/icu-small/source/i18n/region.cpp +++ b/deps/icu-small/source/i18n/region.cpp @@ -217,7 +217,7 @@ void U_CALLCONV Region::loadRegionData(UErrorCode &status) { if ( aliasToRegion != NULL && aliasFromRegion == NULL ) { // This is just an alias from some string to a region uhash_put(newRegionAliases.getAlias(),(void *)aliasFromStr.orphan(), (void *)aliasToRegion,&status); } else { - if ( aliasFromRegion == NULL ) { // Deprecated region code not in the master codes list - so need to create a deprecated region for it. + if ( aliasFromRegion == NULL ) { // Deprecated region code not in the primary codes list - so need to create a deprecated region for it. LocalPointer newRgn(new Region, status); if ( U_SUCCESS(status) ) { aliasFromRegion = newRgn.orphan(); diff --git a/deps/icu-small/source/i18n/reldatefmt.cpp b/deps/icu-small/source/i18n/reldatefmt.cpp index f10c5ba4884b84..5d43606169c8a8 100644 --- a/deps/icu-small/source/i18n/reldatefmt.cpp +++ b/deps/icu-small/source/i18n/reldatefmt.cpp @@ -1326,7 +1326,7 @@ ureldatefmt_formatNumeric( const URelativeDateTimeFormatter* reldatefmt, return res.extract(result, resultCapacity, *status); } -U_STABLE void U_EXPORT2 +U_CAPI void U_EXPORT2 ureldatefmt_formatNumericToResult( const URelativeDateTimeFormatter* reldatefmt, double offset, @@ -1369,7 +1369,7 @@ ureldatefmt_format( const URelativeDateTimeFormatter* reldatefmt, return res.extract(result, resultCapacity, *status); } -U_DRAFT void U_EXPORT2 +U_CAPI void U_EXPORT2 ureldatefmt_formatToResult( const URelativeDateTimeFormatter* reldatefmt, double offset, diff --git a/deps/icu-small/source/i18n/rematch.cpp b/deps/icu-small/source/i18n/rematch.cpp index 123aa8602ba474..653ef4d6c1f8d1 100644 --- a/deps/icu-small/source/i18n/rematch.cpp +++ b/deps/icu-small/source/i18n/rematch.cpp @@ -2072,7 +2072,7 @@ int32_t RegexMatcher::split(UText *input, UErrorCode &status) { // - // Check arguements for validity + // Check arguments for validity // if (U_FAILURE(status)) { return 0; diff --git a/deps/icu-small/source/i18n/rulebasedcollator.cpp b/deps/icu-small/source/i18n/rulebasedcollator.cpp index 60acf17815a5ee..917482d65bb4d6 100644 --- a/deps/icu-small/source/i18n/rulebasedcollator.cpp +++ b/deps/icu-small/source/i18n/rulebasedcollator.cpp @@ -1600,10 +1600,7 @@ RuleBasedCollator::internalGetShortDefinitionString(const char *locale, appendSubtag(result, 'Z', subtag, length, errorCode); if(U_FAILURE(errorCode)) { return 0; } - if(result.length() <= capacity) { - uprv_memcpy(buffer, result.data(), result.length()); - } - return u_terminateChars(buffer, capacity, result.length(), &errorCode); + return result.extract(buffer, capacity, errorCode); } UBool diff --git a/deps/icu-small/source/i18n/smpdtfmt.cpp b/deps/icu-small/source/i18n/smpdtfmt.cpp index d704642b0536a4..4717899cf38d7d 100644 --- a/deps/icu-small/source/i18n/smpdtfmt.cpp +++ b/deps/icu-small/source/i18n/smpdtfmt.cpp @@ -54,6 +54,7 @@ #include "unicode/udisplaycontext.h" #include "unicode/brkiter.h" #include "unicode/rbnf.h" +#include "unicode/dtptngen.h" #include "uresimp.h" #include "olsontz.h" #include "patternprops.h" @@ -650,6 +651,12 @@ SimpleDateFormat::operator==(const Format& other) const } //---------------------------------------------------------------------- +static const UChar* timeSkeletons[4] = { + u"jmmsszzzz", // kFull + u"jmmssz", // kLong + u"jmmss", // kMedium + u"jmm", // kShort +}; void SimpleDateFormat::construct(EStyle timeStyle, EStyle dateStyle, @@ -714,35 +721,75 @@ void SimpleDateFormat::construct(EStyle timeStyle, fDateOverride.setToBogus(); fTimeOverride.setToBogus(); + UnicodeString timePattern; + if (timeStyle >= kFull && timeStyle <= kShort) { + const char* baseLocID = locale.getBaseName(); + if (baseLocID[0]!=0 && uprv_strcmp(baseLocID,"und")!=0) { + UErrorCode useStatus = U_ZERO_ERROR; + Locale baseLoc(baseLocID); + Locale validLoc(getLocale(ULOC_VALID_LOCALE, useStatus)); + if (U_SUCCESS(useStatus) && validLoc!=baseLoc) { + bool useDTPG = false; + const char* baseReg = baseLoc.getCountry(); // empty string if no region + if ((baseReg[0]!=0 && uprv_strncmp(baseReg,validLoc.getCountry(),ULOC_COUNTRY_CAPACITY)!=0) + || uprv_strncmp(baseLoc.getLanguage(),validLoc.getLanguage(),ULOC_LANG_CAPACITY)!=0) { + // use DTPG if + // * baseLoc has a region and validLoc does not have the same one (or has none), OR + // * validLoc has a different language code than baseLoc + useDTPG = true; + } + if (useDTPG) { + // The standard time formats may have the wrong time cycle, because: + // the valid locale differs in important ways (region, language) from + // the base locale. + // We could *also* check whether they do actually have a mismatch with + // the time cycle preferences for the region, but that is a lot more + // work for little or no additional benefit, since just going ahead + // and always synthesizing the time format as per the following should + // create a locale-appropriate pattern with cycle that matches the + // region preferences anyway. + LocalPointer dtpg(DateTimePatternGenerator::createInstanceNoStdPat(locale, useStatus)); + if (U_SUCCESS(useStatus)) { + UnicodeString timeSkeleton(TRUE, timeSkeletons[timeStyle], -1); + timePattern = dtpg->getBestPattern(timeSkeleton, useStatus); + } + } + } + } + } + // if the pattern should include both date and time information, use the date/time // pattern string as a guide to tell use how to glue together the appropriate date // and time pattern strings. if ((timeStyle != kNone) && (dateStyle != kNone)) { - currentBundle.adoptInstead( - ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)timeStyle, NULL, &status)); - if (U_FAILURE(status)) { - status = U_INVALID_FORMAT_ERROR; - return; - } - switch (ures_getType(currentBundle.getAlias())) { - case URES_STRING: { - resStr = ures_getString(currentBundle.getAlias(), &resStrLen, &status); - break; - } - case URES_ARRAY: { - resStr = ures_getStringByIndex(currentBundle.getAlias(), 0, &resStrLen, &status); - ovrStr = ures_getStringByIndex(currentBundle.getAlias(), 1, &ovrStrLen, &status); - fTimeOverride.setTo(TRUE, ovrStr, ovrStrLen); - break; - } - default: { + UnicodeString tempus1(timePattern); + if (tempus1.length() == 0) { + currentBundle.adoptInstead( + ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)timeStyle, NULL, &status)); + if (U_FAILURE(status)) { status = U_INVALID_FORMAT_ERROR; return; } - } + switch (ures_getType(currentBundle.getAlias())) { + case URES_STRING: { + resStr = ures_getString(currentBundle.getAlias(), &resStrLen, &status); + break; + } + case URES_ARRAY: { + resStr = ures_getStringByIndex(currentBundle.getAlias(), 0, &resStrLen, &status); + ovrStr = ures_getStringByIndex(currentBundle.getAlias(), 1, &ovrStrLen, &status); + fTimeOverride.setTo(TRUE, ovrStr, ovrStrLen); + break; + } + default: { + status = U_INVALID_FORMAT_ERROR; + return; + } + } - UnicodeString tempus1(TRUE, resStr, resStrLen); + tempus1.setTo(TRUE, resStr, resStrLen); + } currentBundle.adoptInstead( ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)dateStyle, NULL, &status)); @@ -784,29 +831,32 @@ void SimpleDateFormat::construct(EStyle timeStyle, // pattern string from the resources // setTo() - see DateFormatSymbols::assignArray comments else if (timeStyle != kNone) { - currentBundle.adoptInstead( - ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)timeStyle, NULL, &status)); - if (U_FAILURE(status)) { - status = U_INVALID_FORMAT_ERROR; - return; - } - switch (ures_getType(currentBundle.getAlias())) { - case URES_STRING: { - resStr = ures_getString(currentBundle.getAlias(), &resStrLen, &status); - break; - } - case URES_ARRAY: { - resStr = ures_getStringByIndex(currentBundle.getAlias(), 0, &resStrLen, &status); - ovrStr = ures_getStringByIndex(currentBundle.getAlias(), 1, &ovrStrLen, &status); - fDateOverride.setTo(TRUE, ovrStr, ovrStrLen); - break; - } - default: { + fPattern.setTo(timePattern); + if (fPattern.length() == 0) { + currentBundle.adoptInstead( + ures_getByIndex(dateTimePatterns.getAlias(), (int32_t)timeStyle, NULL, &status)); + if (U_FAILURE(status)) { status = U_INVALID_FORMAT_ERROR; return; } + switch (ures_getType(currentBundle.getAlias())) { + case URES_STRING: { + resStr = ures_getString(currentBundle.getAlias(), &resStrLen, &status); + break; + } + case URES_ARRAY: { + resStr = ures_getStringByIndex(currentBundle.getAlias(), 0, &resStrLen, &status); + ovrStr = ures_getStringByIndex(currentBundle.getAlias(), 1, &ovrStrLen, &status); + fDateOverride.setTo(TRUE, ovrStr, ovrStrLen); + break; + } + default: { + status = U_INVALID_FORMAT_ERROR; + return; + } + } + fPattern.setTo(TRUE, resStr, resStrLen); } - fPattern.setTo(TRUE, resStr, resStrLen); } else if (dateStyle != kNone) { currentBundle.adoptInstead( @@ -848,7 +898,8 @@ Calendar* SimpleDateFormat::initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status) { if(!U_FAILURE(status)) { - fCalendar = Calendar::createInstance(adoptZone?adoptZone:TimeZone::createDefault(), locale, status); + fCalendar = Calendar::createInstance( + adoptZone ? adoptZone : TimeZone::forLocaleOrDefault(locale), locale, status); } return fCalendar; } diff --git a/deps/icu-small/source/i18n/strmatch.h b/deps/icu-small/source/i18n/strmatch.h index 09d04ede13e61a..84b1d47398fd60 100644 --- a/deps/icu-small/source/i18n/strmatch.h +++ b/deps/icu-small/source/i18n/strmatch.h @@ -109,11 +109,11 @@ class StringMatcher : public UnicodeFunctor, public UnicodeMatcher, public Unico * considered for matching will be text.charAt(limit-1) in the * forward direction or text.charAt(limit+1) in the backward * direction. - * @param incremental if TRUE, then assume further characters may + * @param incremental if true, then assume further characters may * be inserted at limit and check for partial matching. Otherwise * assume the text as given is complete. * @return a match degree value indicating a full match, a partial - * match, or a mismatch. If incremental is FALSE then + * match, or a mismatch. If incremental is false then * U_PARTIAL_MATCH should never be returned. */ virtual UMatchDegree matches(const Replaceable& text, @@ -128,16 +128,16 @@ class StringMatcher : public UnicodeFunctor, public UnicodeMatcher, public Unico * @return A reference to 'result'. */ virtual UnicodeString& toPattern(UnicodeString& result, - UBool escapeUnprintable = FALSE) const; + UBool escapeUnprintable = false) const; /** * Implement UnicodeMatcher - * Returns TRUE if this matcher will match a character c, where c + * Returns true if this matcher will match a character c, where c * & 0xFF == v, at offset, in the forward direction (with limit > * offset). This is used by RuleBasedTransliterator for * indexing. * @param v the given value - * @return TRUE if this matcher will match a character c, + * @return true if this matcher will match a character c, * where c & 0xFF == v */ virtual UBool matchesIndexValue(uint8_t v) const; @@ -181,7 +181,7 @@ class StringMatcher : public UnicodeFunctor, public UnicodeMatcher, public Unico * replacer that is equal to this one. * @param result the string to receive the pattern. Previous * contents will be deleted. - * @param escapeUnprintable if TRUE then convert unprintable + * @param escapeUnprintable if true then convert unprintable * character to their hex escape representations, \\uxxxx or * \\Uxxxxxxxx. Unprintable characters are defined by * Utility.isUnprintable(). diff --git a/deps/icu-small/source/i18n/taiwncal.h b/deps/icu-small/source/i18n/taiwncal.h index daadc124f40a18..bf384fa714f05b 100644 --- a/deps/icu-small/source/i18n/taiwncal.h +++ b/deps/icu-small/source/i18n/taiwncal.h @@ -156,7 +156,7 @@ class TaiwanCalendar : public GregorianCalendar { virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const; /** - * Returns TRUE because the Taiwan Calendar does have a default century + * Returns true because the Taiwan Calendar does have a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/timezone.cpp b/deps/icu-small/source/i18n/timezone.cpp index b90b78614aa00f..1461b80494e109 100644 --- a/deps/icu-small/source/i18n/timezone.cpp +++ b/deps/icu-small/source/i18n/timezone.cpp @@ -579,6 +579,24 @@ TimeZone::createDefault() // ------------------------------------- +TimeZone* U_EXPORT2 +TimeZone::forLocaleOrDefault(const Locale& locale) +{ + char buffer[ULOC_KEYWORDS_CAPACITY] = ""; + UErrorCode localStatus = U_ZERO_ERROR; + int32_t count = locale.getKeywordValue("timezone", buffer, sizeof(buffer), localStatus); + if (U_FAILURE(localStatus) || localStatus == U_STRING_NOT_TERMINATED_WARNING) { + // the "timezone" keyword exceeds ULOC_KEYWORDS_CAPACITY; ignore and use default. + count = 0; + } + if (count > 0) { + return TimeZone::createTimeZone(UnicodeString(buffer, count, US_INV)); + } + return TimeZone::createDefault(); +} + +// ------------------------------------- + void U_EXPORT2 TimeZone::adoptDefault(TimeZone* zone) { diff --git a/deps/icu-small/source/i18n/transreg.h b/deps/icu-small/source/i18n/transreg.h index 041244e1b02d77..04ed3fb501059c 100644 --- a/deps/icu-small/source/i18n/transreg.h +++ b/deps/icu-small/source/i18n/transreg.h @@ -69,7 +69,7 @@ class TransliteratorAlias : public UMemory { * it when the registry mutex is NOT held, to prevent deadlock. * It may only be called once. * - * Note: Only call create() if isRuleBased() returns FALSE. + * Note: Only call create() if isRuleBased() returns false. * * This method must be called *outside* of the TransliteratorRegistry * mutex. @@ -77,17 +77,17 @@ class TransliteratorAlias : public UMemory { Transliterator* create(UParseError&, UErrorCode&); /** - * Return TRUE if this alias is rule-based. If so, the caller + * Return true if this alias is rule-based. If so, the caller * must call parse() on it, then call TransliteratorRegistry::reget(). */ UBool isRuleBased() const; /** - * If isRuleBased() returns TRUE, then the caller must call this + * If isRuleBased() returns true, then the caller must call this * method, followed by TransliteratorRegistry::reget(). The latter * method must be called inside the TransliteratorRegistry mutex. * - * Note: Only call parse() if isRuleBased() returns TRUE. + * Note: Only call parse() if isRuleBased() returns true. * * This method must be called *outside* of the TransliteratorRegistry * mutex, because it can instantiate Transliterators embedded in diff --git a/deps/icu-small/source/i18n/tridpars.h b/deps/icu-small/source/i18n/tridpars.h index 3d657ed17c9784..cd56146023162f 100644 --- a/deps/icu-small/source/i18n/tridpars.h +++ b/deps/icu-small/source/i18n/tridpars.h @@ -222,7 +222,7 @@ class TransliteratorIDParser /* not : public UObject because all methods are sta * @param source the given source. * @param target the given target. * @param variant the given variant - * @param isSourcePresent If TRUE then the source is present. + * @param isSourcePresent If true then the source is present. * If the source is not present, ANY will be * given as the source, and isSourcePresent will be null * @return an array of 4 strings: source, target, variant, and diff --git a/deps/icu-small/source/i18n/tznames_impl.h b/deps/icu-small/source/i18n/tznames_impl.h index 1286eeb80dc503..417c0511f81f8a 100644 --- a/deps/icu-small/source/i18n/tznames_impl.h +++ b/deps/icu-small/source/i18n/tznames_impl.h @@ -92,9 +92,9 @@ struct CharacterNode { UBool fHasValuesVector; UBool fPadding; - // No value: fValues == NULL and fHasValuesVector == FALSE - // One value: fValues == value and fHasValuesVector == FALSE - // >=2 values: fValues == UVector of values and fHasValuesVector == TRUE + // No value: fValues == NULL and fHasValuesVector == false + // One value: fValues == value and fHasValuesVector == false + // >=2 values: fValues == UVector of values and fHasValuesVector == true }; inline UBool CharacterNode::hasValues() const { diff --git a/deps/icu-small/source/i18n/ucal.cpp b/deps/icu-small/source/i18n/ucal.cpp index 8ea7fbf4f56939..275ef7ea87e273 100644 --- a/deps/icu-small/source/i18n/ucal.cpp +++ b/deps/icu-small/source/i18n/ucal.cpp @@ -91,7 +91,7 @@ ucal_setDefaultTimeZone(const UChar* zoneID, UErrorCode* ec) { } } -U_DRAFT int32_t U_EXPORT2 +U_CAPI int32_t U_EXPORT2 ucal_getHostTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec) { int32_t len = 0; if (ec != NULL && U_SUCCESS(*ec)) { diff --git a/deps/icu-small/source/i18n/ucol_imp.h b/deps/icu-small/source/i18n/ucol_imp.h index a251fc461d3ac2..f463957fd4f2d8 100644 --- a/deps/icu-small/source/i18n/ucol_imp.h +++ b/deps/icu-small/source/i18n/ucol_imp.h @@ -41,10 +41,10 @@ * rules must be equivalent. * @param source first collator * @param target second collator - * @return TRUE or FALSE + * @return true or false * @internal ICU 3.0 */ -U_INTERNAL UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 ucol_equals(const UCollator *source, const UCollator *target); /** diff --git a/deps/icu-small/source/i18n/ucol_sit.cpp b/deps/icu-small/source/i18n/ucol_sit.cpp index 9fa7cd5fd73851..d6bbf97b310bd3 100644 --- a/deps/icu-small/source/i18n/ucol_sit.cpp +++ b/deps/icu-small/source/i18n/ucol_sit.cpp @@ -372,10 +372,7 @@ int32_t ucol_sit_dumpSpecs(CollatorSpec *s, char *destination, int32_t capacity, } len += s->entries[i].length(); } else { - len += s->entries[i].length(); - if(len < capacity) { - uprv_strncat(destination,s->entries[i].data(), s->entries[i].length()); - } + len += s->entries[i].extract(destination + len, capacity - len, *status); } } } diff --git a/deps/icu-small/source/i18n/ucsdet.cpp b/deps/icu-small/source/i18n/ucsdet.cpp index 46f69cf90cba6b..63f204d0e10421 100644 --- a/deps/icu-small/source/i18n/ucsdet.cpp +++ b/deps/icu-small/source/i18n/ucsdet.cpp @@ -193,7 +193,7 @@ ucsdet_getAllDetectableCharsets(const UCharsetDetector * /*ucsd*/, UErrorCode *s return CharsetDetector::getAllDetectableCharsets(*status); } -U_DRAFT UEnumeration * U_EXPORT2 +U_CAPI UEnumeration * U_EXPORT2 ucsdet_getDetectableCharsets(const UCharsetDetector *ucsd, UErrorCode *status) { return ((CharsetDetector *)ucsd)->getDetectableCharsets(*status); diff --git a/deps/icu-small/source/i18n/udat.cpp b/deps/icu-small/source/i18n/udat.cpp index da8befc9e3c65b..016805aab66fdd 100644 --- a/deps/icu-small/source/i18n/udat.cpp +++ b/deps/icu-small/source/i18n/udat.cpp @@ -82,19 +82,24 @@ static UCalendarDateFields gDateFieldMapping[] = { UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_ISO_FIELD = 32 (also UCAL_DST_OFFSET) UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33 (also UCAL_DST_OFFSET) UCAL_EXTENDED_YEAR, // UDAT_RELATED_YEAR_FIELD = 34 (not an exact match) - UCAL_FIELD_COUNT, // UDAT_FIELD_COUNT = 35 + UCAL_FIELD_COUNT, // UDAT_AM_PM_MIDNIGHT_NOON_FIELD=35 (no match) + UCAL_FIELD_COUNT, // UDAT_FLEXIBLE_DAY_PERIOD_FIELD=36 (no match) + UCAL_FIELD_COUNT, // UDAT_TIME_SEPARATOR_FIELD = 37 (no match) + // UDAT_FIELD_COUNT = 38 as of ICU 67 // UCAL_IS_LEAP_MONTH is not the target of a mapping }; U_CAPI UCalendarDateFields U_EXPORT2 udat_toCalendarDateField(UDateFormatField field) { - return gDateFieldMapping[field]; + static_assert(UDAT_FIELD_COUNT == UPRV_LENGTHOF(gDateFieldMapping), + "UDateFormatField and gDateFieldMapping should have the same number of entries and be kept in sync."); + return (field >= UDAT_ERA_FIELD && field < UPRV_LENGTHOF(gDateFieldMapping))? gDateFieldMapping[field]: UCAL_FIELD_COUNT; } /* For now- one opener. */ static UDateFormatOpener gOpener = NULL; -U_INTERNAL void U_EXPORT2 +U_CAPI void U_EXPORT2 udat_registerOpener(UDateFormatOpener opener, UErrorCode *status) { if(U_FAILURE(*status)) return; @@ -107,7 +112,7 @@ udat_registerOpener(UDateFormatOpener opener, UErrorCode *status) umtx_unlock(NULL); } -U_INTERNAL UDateFormatOpener U_EXPORT2 +U_CAPI UDateFormatOpener U_EXPORT2 udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status) { if(U_FAILURE(*status)) return NULL; @@ -419,7 +424,7 @@ udat_setLenient( UDateFormat* fmt, ((DateFormat*)fmt)->setLenient(isLenient); } -U_DRAFT UBool U_EXPORT2 +U_CAPI UBool U_EXPORT2 udat_getBooleanAttribute(const UDateFormat* fmt, UDateFormatBooleanAttribute attr, UErrorCode* status) @@ -429,7 +434,7 @@ udat_getBooleanAttribute(const UDateFormat* fmt, //return FALSE; } -U_DRAFT void U_EXPORT2 +U_CAPI void U_EXPORT2 udat_setBooleanAttribute(UDateFormat *fmt, UDateFormatBooleanAttribute attr, UBool newValue, @@ -452,7 +457,7 @@ udat_setCalendar(UDateFormat* fmt, ((DateFormat*)fmt)->setCalendar(*((Calendar*)calendarToSet)); } -U_DRAFT const UNumberFormat* U_EXPORT2 +U_CAPI const UNumberFormat* U_EXPORT2 udat_getNumberFormatForField(const UDateFormat* fmt, UChar field) { UErrorCode status = U_ZERO_ERROR; @@ -467,7 +472,7 @@ udat_getNumberFormat(const UDateFormat* fmt) return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat(); } -U_DRAFT void U_EXPORT2 +U_CAPI void U_EXPORT2 udat_adoptNumberFormatForFields( UDateFormat* fmt, const UChar* fields, UNumberFormat* numberFormatToSet, @@ -489,7 +494,7 @@ udat_setNumberFormat(UDateFormat* fmt, ((DateFormat*)fmt)->setNumberFormat(*((NumberFormat*)numberFormatToSet)); } -U_DRAFT void U_EXPORT2 +U_CAPI void U_EXPORT2 udat_adoptNumberFormat( UDateFormat* fmt, UNumberFormat* numberFormatToAdopt) { diff --git a/deps/icu-small/source/i18n/udateintervalformat.cpp b/deps/icu-small/source/i18n/udateintervalformat.cpp index 388960384b563f..355744346a39d7 100644 --- a/deps/icu-small/source/i18n/udateintervalformat.cpp +++ b/deps/icu-small/source/i18n/udateintervalformat.cpp @@ -18,6 +18,7 @@ #include "unicode/timezone.h" #include "unicode/locid.h" #include "unicode/unistr.h" +#include "unicode/udisplaycontext.h" #include "formattedval_impl.h" U_NAMESPACE_USE @@ -116,7 +117,7 @@ udtitvfmt_format(const UDateIntervalFormat* formatter, } -U_DRAFT void U_EXPORT2 +U_CAPI void U_EXPORT2 udtitvfmt_formatToResult( const UDateIntervalFormat* formatter, UDate fromDate, @@ -134,7 +135,7 @@ udtitvfmt_formatToResult( } } -U_DRAFT void U_EXPORT2 +U_CAPI void U_EXPORT2 udtitvfmt_formatCalendarToResult( const UDateIntervalFormat* formatter, UCalendar* fromCalendar, @@ -151,5 +152,25 @@ udtitvfmt_formatCalendarToResult( } } +U_CAPI void U_EXPORT2 +udtitvfmt_setContext(UDateIntervalFormat* formatter, + UDisplayContext value, + UErrorCode* status) { + if (U_FAILURE(*status)) { + return; + } + reinterpret_cast(formatter)->setContext( value, *status ); +} + +U_CAPI UDisplayContext U_EXPORT2 +udtitvfmt_getContext(const UDateIntervalFormat* formatter, + UDisplayContextType type, + UErrorCode* status) { + if (U_FAILURE(*status)) { + return (UDisplayContext)0; + } + return reinterpret_cast(formatter)->getContext( type, *status ); +} + #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/deps/icu-small/source/i18n/uitercollationiterator.h b/deps/icu-small/source/i18n/uitercollationiterator.h index 62b6f8341933bb..3a7b1a0ec23b47 100644 --- a/deps/icu-small/source/i18n/uitercollationiterator.h +++ b/deps/icu-small/source/i18n/uitercollationiterator.h @@ -96,7 +96,7 @@ class U_I18N_API FCDUIterCollationIterator : public UIterCollationIterator { /** * Extends the FCD text segment forward or normalizes around pos. - * @return TRUE if success + * @return true if success */ UBool nextSegment(UErrorCode &errorCode); @@ -107,7 +107,7 @@ class U_I18N_API FCDUIterCollationIterator : public UIterCollationIterator { /** * Extends the FCD text segment backward or normalizes around pos. - * @return TRUE if success + * @return true if success */ UBool previousSegment(UErrorCode &errorCode); diff --git a/deps/icu-small/source/i18n/ulocdata.cpp b/deps/icu-small/source/i18n/ulocdata.cpp index f651fee6fc4efa..3046167b328db8 100644 --- a/deps/icu-small/source/i18n/ulocdata.cpp +++ b/deps/icu-small/source/i18n/ulocdata.cpp @@ -172,7 +172,7 @@ ulocdata_getDelimiter(ULocaleData *uld, ULocaleDataDelimiterType type, return 0; } - delimiter = ures_getStringByKey(delimiterBundle, delimiterKeys[type], &len, &localStatus); + delimiter = ures_getStringByKeyWithFallback(delimiterBundle, delimiterKeys[type], &len, &localStatus); ures_close(delimiterBundle); if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) { diff --git a/deps/icu-small/source/i18n/unicode/alphaindex.h b/deps/icu-small/source/i18n/unicode/alphaindex.h index fe43995fe81155..d72abce9acd3ec 100644 --- a/deps/icu-small/source/i18n/unicode/alphaindex.h +++ b/deps/icu-small/source/i18n/unicode/alphaindex.h @@ -549,14 +549,14 @@ class U_I18N_API AlphabeticIndex: public UObject { /** - * Advance the iteration over the Buckets of this index. Return FALSE if + * Advance the iteration over the Buckets of this index. Return false if * there are no more Buckets. * * @param status Error code, will be set with the reason if the operation fails. * U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while * an enumeration of its contents are in process. * - * @return TRUE if success, FALSE if at end of iteration + * @return true if success, false if at end of iteration * @stable ICU 4.8 */ virtual UBool nextBucket(UErrorCode &status); @@ -609,7 +609,7 @@ class U_I18N_API AlphabeticIndex: public UObject { * @param status Error code, will be set with the reason if the operation fails. * U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while * an enumeration of its contents are in process. - * @return TRUE if successful, FALSE when the iteration advances past the last item. + * @return true if successful, false when the iteration advances past the last item. * @stable ICU 4.8 */ virtual UBool nextRecord(UErrorCode &status); diff --git a/deps/icu-small/source/i18n/unicode/basictz.h b/deps/icu-small/source/i18n/unicode/basictz.h index cc8059709f49b0..7199fb341deec8 100644 --- a/deps/icu-small/source/i18n/unicode/basictz.h +++ b/deps/icu-small/source/i18n/unicode/basictz.h @@ -56,7 +56,7 @@ class U_I18N_API BasicTimeZone: public TimeZone { * @param base The base time. * @param inclusive Whether the base time is inclusive or not. * @param result Receives the first transition after the base time. - * @return TRUE if the transition is found. + * @return true if the transition is found. * @stable ICU 3.8 */ virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0; @@ -66,7 +66,7 @@ class U_I18N_API BasicTimeZone: public TimeZone { * @param base The base time. * @param inclusive Whether the base time is inclusive or not. * @param result Receives the most recent transition before the base time. - * @return TRUE if the transition is found. + * @return true if the transition is found. * @stable ICU 3.8 */ virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0; diff --git a/deps/icu-small/source/i18n/unicode/calendar.h b/deps/icu-small/source/i18n/unicode/calendar.h index 2a8c2935ca8e24..cc84bb274dee04 100644 --- a/deps/icu-small/source/i18n/unicode/calendar.h +++ b/deps/icu-small/source/i18n/unicode/calendar.h @@ -464,10 +464,10 @@ class U_I18N_API Calendar : public UObject { UBool operator!=(const Calendar& that) const {return !operator==(that);} /** - * Returns TRUE if the given Calendar object is equivalent to this + * Returns true if the given Calendar object is equivalent to this * one. An equivalent Calendar will behave exactly as this one * does, but it may be set to a different time. By contrast, for - * the operator==() method to return TRUE, the other Calendar must + * the operator==() method to return true, the other Calendar must * be set to the same time. * * @param other the Calendar to be compared with this Calendar @@ -1359,7 +1359,7 @@ class U_I18N_API Calendar : public UObject { * localeID.append(calType); * char langTag[100]; * UErrorCode errorCode = U_ZERO_ERROR; - * int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), TRUE, &errorCode); + * int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), true, &errorCode); * if (U_FAILURE(errorCode)) { * // deal with errors & overflow * } @@ -1410,21 +1410,21 @@ class U_I18N_API Calendar : public UObject { virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const; /** - * Returns TRUE if the given UDate is in the weekend in + * Returns true if the given UDate is in the weekend in * this calendar system. * @param date The UDate in question. * @param status The error code for the operation. - * @return TRUE if the given UDate is in the weekend in - * this calendar system, FALSE otherwise. + * @return true if the given UDate is in the weekend in + * this calendar system, false otherwise. * @stable ICU 4.4 */ virtual UBool isWeekend(UDate date, UErrorCode &status) const; /** - * Returns TRUE if this Calendar's current date-time is in the weekend in + * Returns true if this Calendar's current date-time is in the weekend in * this calendar system. - * @return TRUE if this Calendar's current date-time is in the weekend in - * this calendar system, FALSE otherwise. + * @return true if this Calendar's current date-time is in the weekend in + * this calendar system, false otherwise. * @stable ICU 4.4 */ virtual UBool isWeekend(void) const; @@ -2372,7 +2372,7 @@ class U_I18N_API Calendar : public UObject { * * @param key the registry key returned by a previous call to registerFactory * @param status the in/out status code, no special meanings are assigned - * @return TRUE if the factory for the key was successfully unregistered + * @return true if the factory for the key was successfully unregistered * @internal */ static UBool unregister(URegistryKey key, UErrorCode& status); @@ -2398,7 +2398,7 @@ class U_I18N_API Calendar : public UObject { #endif /* !UCONFIG_NO_SERVICE */ /** - * @return TRUE if this calendar has a default century (i.e. 03 -> 2003) + * @return true if this calendar has a default century (i.e. 03 -> 2003) * @internal */ virtual UBool haveDefaultCentury() const = 0; @@ -2458,7 +2458,7 @@ class U_I18N_API Calendar : public UObject { * @param base The base time, inclusive * @param transitionTime Receives the result time * @param status The error status - * @return TRUE if a transition is found. + * @return true if a transition is found. */ UBool getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const; @@ -2531,7 +2531,7 @@ Calendar::internalSet(UCalendarDateFields field, int32_t value) { fFields[field] = value; fStamp[field] = kInternallySet; - fIsSet[field] = TRUE; // Remove later + fIsSet[field] = true; // Remove later } diff --git a/deps/icu-small/source/i18n/unicode/choicfmt.h b/deps/icu-small/source/i18n/unicode/choicfmt.h index 3b2f48cb1f853c..cb01fca253355d 100644 --- a/deps/icu-small/source/i18n/unicode/choicfmt.h +++ b/deps/icu-small/source/i18n/unicode/choicfmt.h @@ -106,7 +106,7 @@ class MessageFormat; * arrays of numbers, closure flags and strings, * they are interpreted just like * the sequence of (number separator string) in an equivalent pattern string. - * closure[i]==TRUE corresponds to a less_than separator sign. + * closure[i]==true corresponds to a less_than separator sign. * The equivalent pattern string will be constructed automatically.

    * *

    During formatting, a number is mapped to the first range @@ -126,7 +126,7 @@ class MessageFormat; *

    Here is an example of two arrays that map the number * 1..7 to the English day of the week abbreviations * Sun..Sat. No closures array is given; this is the same as - * specifying all closures to be FALSE.

    + * specifying all closures to be false.

    * *
        {1,2,3,4,5,6,7},
      *     {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}
    @@ -138,7 +138,7 @@ class MessageFormat; * like the turned bracket in European notation: [-Inf, 1) == [-Inf, 1[ )

    * *
        {0, 1, 1},
    - *     {FALSE, FALSE, TRUE},
    + *     {false, false, true},
      *     {"no files", "one file", "many files"}
    * *

    Here is an example that shows formatting and parsing:

    @@ -189,7 +189,7 @@ class U_I18N_API ChoiceFormat: public NumberFormat { /** * Constructs a new ChoiceFormat with the given limits and message strings. - * All closure flags default to FALSE, + * All closure flags default to false, * equivalent to less_than_or_equal separators. * * Copies the limits and formats instead of adopting them. @@ -210,9 +210,9 @@ class U_I18N_API ChoiceFormat: public NumberFormat { * * @param limits Array of limit values * @param closures Array of booleans specifying whether each - * element of 'limits' is open or closed. If FALSE, then the + * element of 'limits' is open or closed. If false, then the * corresponding limit number is a member of its range. - * If TRUE, then the limit number belongs to the previous range it. + * If true, then the limit number belongs to the previous range it. * @param formats Array of formats * @param count Size of 'limits', 'closures', and 'formats' arrays * @deprecated ICU 49 Use MessageFormat instead, with plural and select arguments. @@ -568,13 +568,13 @@ class U_I18N_API ChoiceFormat: public NumberFormat { * The intervals may be closed, half open, or open. This affects * formatting but does not affect parsing. Interval i is affected * by fClosures[i] and fClosures[i+1]. If fClosures[i] - * is FALSE, then the value fChoiceLimits[i] is in interval i. + * is false, then the value fChoiceLimits[i] is in interval i. * That is, intervals i and i are: * * i-1: ... x < fChoiceLimits[i] * i: fChoiceLimits[i] <= x ... * - * If fClosures[i] is TRUE, then the value fChoiceLimits[i] is + * If fClosures[i] is true, then the value fChoiceLimits[i] is * in interval i-1. That is, intervals i-1 and i are: * * i-1: ... x <= fChoiceLimits[i] diff --git a/deps/icu-small/source/i18n/unicode/coleitr.h b/deps/icu-small/source/i18n/unicode/coleitr.h index 809d435e509b49..2696b588278cde 100644 --- a/deps/icu-small/source/i18n/unicode/coleitr.h +++ b/deps/icu-small/source/i18n/unicode/coleitr.h @@ -253,7 +253,7 @@ class U_I18N_API CollationElementIterator U_FINAL : public UObject { /** * Checks if a comparison order is ignorable. * @param order the collation order. - * @return TRUE if a character is ignorable, FALSE otherwise. + * @return true if a character is ignorable, false otherwise. * @stable ICU 2.0 */ static inline UBool isIgnorable(int32_t order); diff --git a/deps/icu-small/source/i18n/unicode/coll.h b/deps/icu-small/source/i18n/unicode/coll.h index f5564c73944bcb..c750711fc158cf 100644 --- a/deps/icu-small/source/i18n/unicode/coll.h +++ b/deps/icu-small/source/i18n/unicode/coll.h @@ -236,21 +236,21 @@ class U_I18N_API Collator : public UObject { // Collator public methods -------------------------------------------- /** - * Returns TRUE if "other" is the same as "this". + * Returns true if "other" is the same as "this". * - * The base class implementation returns TRUE if "other" has the same type/class as "this": + * The base class implementation returns true if "other" has the same type/class as "this": * `typeid(*this) == typeid(other)`. * * Subclass implementations should do something like the following: * - * if (this == &other) { return TRUE; } - * if (!Collator::operator==(other)) { return FALSE; } // not the same class + * if (this == &other) { return true; } + * if (!Collator::operator==(other)) { return false; } // not the same class * * const MyCollator &o = (const MyCollator&)other; * (compare this vs. o's subclass fields) * * @param other Collator object to be compared - * @return TRUE if other is the same as this. + * @return true if other is the same as this. * @stable ICU 2.0 */ virtual UBool operator==(const Collator& other) const; @@ -259,7 +259,7 @@ class U_I18N_API Collator : public UObject { * Returns true if "other" is not the same as "this". * Calls ! operator==(const Collator&) const which works for all subclasses. * @param other Collator object to be compared - * @return TRUE if other is not the same as this. + * @return true if other is not the same as this. * @stable ICU 2.0 */ virtual UBool operator!=(const Collator& other) const; @@ -304,7 +304,7 @@ class U_I18N_API Collator : public UObject { * Starting with ICU 54, collation attributes can be specified via locale keywords as well, * in the old locale extension syntax ("el@colCaseFirst=upper") * or in language tag syntax ("el-u-kf-upper"). - * See User Guide: Collation API. + * See User Guide: Collation API. * * The UErrorCode& err parameter is used to return status information to the user. * To check whether the construction succeeded or not, you should check @@ -788,7 +788,7 @@ class U_I18N_API Collator : public UObject { * applications who wish to cache collators, or otherwise reuse * collators when possible. The functional equivalent may change * over time. For more information, please see the + * href="https://unicode-org.github.io/icu/userguide/locale#locales-and-services"> * Locales and Services section of the ICU User Guide. * @param keyword a particular keyword as enumerated by * ucol_getKeywords. @@ -841,7 +841,7 @@ class U_I18N_API Collator : public UObject { * Collator::createInstance to avoid undefined behavior. * @param key the registry key returned by a previous call to registerInstance * @param status the in/out status code, no special meanings are assigned - * @return TRUE if the collator for the key was successfully unregistered + * @return true if the collator for the key was successfully unregistered * @stable ICU 2.6 */ static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status); @@ -1139,7 +1139,7 @@ class U_I18N_API Collator : public UObject { * This string will be normalized. * The structure and the syntax of the string is defined in the "Naming collators" * section of the users guide: - * http://userguide.icu-project.org/collation/concepts#TOC-Collator-naming-scheme + * https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme * This function supports preflighting. * * This is internal, and intended to be used with delegate converters. diff --git a/deps/icu-small/source/i18n/unicode/curramt.h b/deps/icu-small/source/i18n/unicode/curramt.h index 65e6619db30c16..9c8496381d7aa3 100644 --- a/deps/icu-small/source/i18n/unicode/curramt.h +++ b/deps/icu-small/source/i18n/unicode/curramt.h @@ -41,7 +41,7 @@ class U_I18N_API CurrencyAmount: public Measure { /** * Construct an object with the given numeric amount and the given * ISO currency code. - * @param amount a numeric object; amount.isNumeric() must be TRUE + * @param amount a numeric object; amount.isNumeric() must be true * @param isoCode the 3-letter ISO 4217 currency code; must not be * NULL and must have length 3 * @param ec input-output error code. If the amount or the isoCode diff --git a/deps/icu-small/source/i18n/unicode/dcfmtsym.h b/deps/icu-small/source/i18n/unicode/dcfmtsym.h index 582e7533a4aceb..b2c39a0236e4aa 100644 --- a/deps/icu-small/source/i18n/unicode/dcfmtsym.h +++ b/deps/icu-small/source/i18n/unicode/dcfmtsym.h @@ -378,7 +378,7 @@ class U_I18N_API DecimalFormatSymbols : public UObject { * back to the locale. */ void initialize(const Locale& locale, UErrorCode& success, - UBool useLastResortData = FALSE, const NumberingSystem* ns = nullptr); + UBool useLastResortData = false, const NumberingSystem* ns = nullptr); /** * Initialize the symbols with default values. @@ -543,12 +543,12 @@ inline const UnicodeString& DecimalFormatSymbols::getConstDigitSymbol(int32_t di // ------------------------------------- inline void -DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propogateDigits = TRUE) { +DecimalFormatSymbols::setSymbol(ENumberFormatSymbol symbol, const UnicodeString &value, const UBool propagateDigits = true) { if (symbol == kCurrencySymbol) { - fIsCustomCurrencySymbol = TRUE; + fIsCustomCurrencySymbol = true; } else if (symbol == kIntlCurrencySymbol) { - fIsCustomIntlCurrencySymbol = TRUE; + fIsCustomIntlCurrencySymbol = true; } if(symbolIn order to enable significant digits formatting, use a pattern * containing the '@' pattern character. Alternatively, - * call setSignificantDigitsUsed(TRUE). + * call setSignificantDigitsUsed(true). * *
  • In order to disable significant digits formatting, use a * pattern that does not contain the '@' pattern - * character. Alternatively, call setSignificantDigitsUsed(FALSE). + * character. Alternatively, call setSignificantDigitsUsed(false). * *
  • The number of significant digits has no effect on parsing. * @@ -817,8 +817,8 @@ class U_I18N_API DecimalFormat : public NumberFormat { /** * Sets whether lenient parsing should be enabled (it is off by default). * - * @param enable \c TRUE if lenient parsing should be used, - * \c FALSE otherwise. + * @param enable \c true if lenient parsing should be used, + * \c false otherwise. * @stable ICU 4.8 */ void setLenient(UBool enable) U_OVERRIDE; @@ -1507,7 +1507,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { /** * Return whether or not scientific notation is used. - * @return TRUE if this object formats and parses scientific notation + * @return true if this object formats and parses scientific notation * @see #setScientificNotation * @see #getMinimumExponentDigits * @see #setMinimumExponentDigits @@ -1523,7 +1523,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { * maximum number of integer digits is set to more than 8, the effective * maximum will be 1. This allows this call to generate a 'default' scientific * number format without additional changes. - * @param useScientific TRUE if this object formats and parses scientific + * @param useScientific true if this object formats and parses scientific * notation * @see #isScientificNotation * @see #getMinimumExponentDigits @@ -1562,7 +1562,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { /** * Return whether the exponent sign is always shown. - * @return TRUE if the exponent is always prefixed with either the + * @return true if the exponent is always prefixed with either the * localized minus sign or the localized plus sign, false if only negative * exponents are prefixed with the localized minus sign. * @see #setScientificNotation @@ -1577,7 +1577,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { /** * Set whether the exponent sign is always shown. This has no effect * unless scientific notation is in use. - * @param expSignAlways TRUE if the exponent is always prefixed with either + * @param expSignAlways true if the exponent is always prefixed with either * the localized minus sign or the localized plus sign, false if only * negative exponents are prefixed with the localized minus sign. * @see #setScientificNotation @@ -1674,8 +1674,15 @@ class U_I18N_API DecimalFormat : public NumberFormat { int32_t getMinimumGroupingDigits() const; /** - * Sets the minimum grouping digits. Setting to a value less than or - * equal to 1 turns off minimum grouping digits. + * Sets the minimum grouping digits. Setting the value to + * - 1: Turns off minimum grouping digits. + * - 0 or -1: The behavior is undefined. + * - UNUM_MINIMUM_GROUPING_DIGITS_AUTO: Display grouping using the default + * strategy for all locales. + * - UNUM_MINIMUM_GROUPING_DIGITS_MIN2: Display grouping using locale + * defaults, except do not show grouping on values smaller than 10000 + * (such that there is a minimum of two digits before the first + * separator). * * For more control over grouping strategies, use NumberFormatter. * @@ -1689,7 +1696,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { * Allows you to get the behavior of the decimal separator with integers. * (The decimal separator will always appear with decimals.) * - * @return TRUE if the decimal separator always appear with decimals. + * @return true if the decimal separator always appear with decimals. * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 * @stable ICU 2.0 */ @@ -1699,7 +1706,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { * Allows you to set the behavior of the decimal separator with integers. * (The decimal separator will always appear with decimals.) * - * @param newValue set TRUE if the decimal separator will always appear with decimals. + * @param newValue set true if the decimal separator will always appear with decimals. * Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 * @stable ICU 2.0 */ @@ -1708,7 +1715,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { /** * Allows you to get the parse behavior of the pattern decimal mark. * - * @return TRUE if input must contain a match to decimal mark in pattern + * @return true if input must contain a match to decimal mark in pattern * @stable ICU 54 */ UBool isDecimalPatternMatchRequired(void) const; @@ -1716,10 +1723,10 @@ class U_I18N_API DecimalFormat : public NumberFormat { /** * Allows you to set the parse behavior of the pattern decimal mark. * - * if TRUE, the input must have a decimal mark if one was specified in the pattern. When - * FALSE the decimal mark may be omitted from the input. + * if true, the input must have a decimal mark if one was specified in the pattern. When + * false the decimal mark may be omitted from the input. * - * @param newValue set TRUE if input must contain a match to decimal mark in pattern + * @param newValue set true if input must contain a match to decimal mark in pattern * @stable ICU 54 */ virtual void setDecimalPatternMatchRequired(UBool newValue); @@ -1962,7 +1969,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { * to one. If the maximum significant digits count is less than * min, then it is set to min. * This function also enables the use of significant digits - * by this formatter - areSignificantDigitsUsed() will return TRUE. + * by this formatter - areSignificantDigitsUsed() will return true. * @see #areSignificantDigitsUsed * @param min the fewest significant digits to be shown * @stable ICU 3.0 @@ -1975,7 +1982,7 @@ class U_I18N_API DecimalFormat : public NumberFormat { * to one. If the minimum significant digits count is greater * than max, then it is set to max. * This function also enables the use of significant digits - * by this formatter - areSignificantDigitsUsed() will return TRUE. + * by this formatter - areSignificantDigitsUsed() will return true. * @see #areSignificantDigitsUsed * @param max the most significant digits to be shown * @stable ICU 3.0 diff --git a/deps/icu-small/source/i18n/unicode/dtfmtsym.h b/deps/icu-small/source/i18n/unicode/dtfmtsym.h index f9ec88272b2b5c..f368eaef551434 100644 --- a/deps/icu-small/source/i18n/unicode/dtfmtsym.h +++ b/deps/icu-small/source/i18n/unicode/dtfmtsym.h @@ -919,7 +919,8 @@ class U_I18N_API DateFormatSymbols U_FINAL : public UObject { * failure code upon return. * @param useLastResortData determine if use last resort data */ - void initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData = FALSE); + void initializeData(const Locale& locale, const char *type, + UErrorCode& status, UBool useLastResortData = false); /** * Copy or alias an array in another object, as appropriate. @@ -983,12 +984,12 @@ class U_I18N_API DateFormatSymbols U_FINAL : public UObject { static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c); /** - * Returns TRUE if f (with its pattern character repeated count times) is a numeric field. + * Returns true if f (with its pattern character repeated count times) is a numeric field. */ static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count); /** - * Returns TRUE if c (repeated count times) is the pattern character for a numeric field. + * Returns true if c (repeated count times) is the pattern character for a numeric field. */ static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count); public: diff --git a/deps/icu-small/source/i18n/unicode/dtitvfmt.h b/deps/icu-small/source/i18n/unicode/dtitvfmt.h index 4e4d712b4f5b5c..3d20d8e9c44990 100644 --- a/deps/icu-small/source/i18n/unicode/dtitvfmt.h +++ b/deps/icu-small/source/i18n/unicode/dtitvfmt.h @@ -31,6 +31,7 @@ #include "unicode/dtitvinf.h" #include "unicode/dtptngen.h" #include "unicode/formattedvalue.h" +#include "unicode/udisplaycontext.h" U_NAMESPACE_BEGIN @@ -651,6 +652,34 @@ class U_I18N_API DateIntervalFormat : public Format { */ virtual void setTimeZone(const TimeZone& zone); +#ifndef U_FORCE_HIDE_DRAFT_API + /** + * Set a particular UDisplayContext value in the formatter, such as + * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. This causes the formatted + * result to be capitalized appropriately for the context in which + * it is intended to be used, considering both the locale and the + * type of field at the beginning of the formatted result. + * @param value The UDisplayContext value to set. + * @param status Input/output status. If at entry this indicates a failure + * status, the function will do nothing; otherwise this will be + * updated with any new status from the function. + * @draft ICU 68 + */ + virtual void setContext(UDisplayContext value, UErrorCode& status); + + /** + * Get the formatter's UDisplayContext value for the specified UDisplayContextType, + * such as UDISPCTX_TYPE_CAPITALIZATION. + * @param type The UDisplayContextType whose value to return + * @param status Input/output status. If at entry this indicates a failure + * status, the function will do nothing; otherwise this will be + * updated with any new status from the function. + * @return The UDisplayContextValue for the specified type. + * @draft ICU 68 + */ + virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const; +#endif // U_FORCE_HIDE_DRAFT_API + /** * Return the class ID for this class. This is useful only for comparing to * a return value from getDynamicClassID(). For example: @@ -796,7 +825,7 @@ class U_I18N_API DateIntervalFormat : public Format { * to be formatted into date interval string * @param toCalendar calendar set to the to date in date interval * to be formatted into date interval string - * @param fromToOnSameDay TRUE iff from and to dates are on the same day + * @param fromToOnSameDay true iff from and to dates are on the same day * (any difference is in ampm/hours or below) * @param appendTo Output parameter to receive result. * Result is appended to existing contents. @@ -867,6 +896,19 @@ class U_I18N_API DateIntervalFormat : public Format { + /** + * Converts special hour metacharacters (such as 'j') in the skeleton into locale-appropriate + * pattern characters. + * + * + * @param skeleton The skeleton to convert + * @return A copy of the skeleton, which "j" and any other special hour metacharacters converted to the regular ones. + * + */ + UnicodeString normalizeHourMetacharacters(const UnicodeString& skeleton) const; + + + /** * get separated date and time skeleton from a combined skeleton. * @@ -919,8 +961,8 @@ class U_I18N_API DateIntervalFormat : public Format { * @param dateSkeleton normalized date skeleton * @param timeSkeleton normalized time skeleton * @return whether the resource is found for the skeleton. - * TRUE if interval pattern found for the skeleton, - * FALSE otherwise. + * true if interval pattern found for the skeleton, + * false otherwise. */ UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton, const UnicodeString& timeSkeleton); @@ -948,8 +990,8 @@ class U_I18N_API DateIntervalFormat : public Format { * @param extendedBestSkeleton extended best match skeleton * @return whether the interval pattern is found * through extending skeleton or not. - * TRUE if interval pattern is found by - * extending skeleton, FALSE otherwise. + * true if interval pattern is found by + * extending skeleton, false otherwise. */ UBool setIntervalPattern(UCalendarDateFields field, const UnicodeString* skeleton, @@ -984,6 +1026,7 @@ class U_I18N_API DateIntervalFormat : public Format { * @param differenceInfo the difference between 2 skeletons * 1 means only field width differs * 2 means v/z exchange + * @param suppressDayPeriodField if true, remove the day period field from the pattern, if there is one * @param adjustedIntervalPattern adjusted interval pattern */ static void U_EXPORT2 adjustFieldWidth( @@ -991,6 +1034,7 @@ class U_I18N_API DateIntervalFormat : public Format { const UnicodeString& bestMatchSkeleton, const UnicodeString& bestMatchIntervalPattern, int8_t differenceInfo, + UBool suppressDayPeriodField, UnicodeString& adjustedIntervalPattern); /** @@ -1137,6 +1181,11 @@ class U_I18N_API DateIntervalFormat : public Format { UnicodeString* fDatePattern; UnicodeString* fTimePattern; UnicodeString* fDateTimeFormat; + + /** + * Other formatting information + */ + UDisplayContext fCapitalizationContext; }; inline UBool diff --git a/deps/icu-small/source/i18n/unicode/dtitvinf.h b/deps/icu-small/source/i18n/unicode/dtitvinf.h index 50e19abb4ce2cb..8452614bfb8d87 100644 --- a/deps/icu-small/source/i18n/unicode/dtitvinf.h +++ b/deps/icu-small/source/i18n/unicode/dtitvinf.h @@ -307,8 +307,8 @@ class U_I18N_API DateIntervalInfo U_FINAL : public UObject { /** Get default order -- whether the first date in pattern is later date or not. - * return default date ordering in interval pattern. TRUE if the first date - * in pattern is later date, FALSE otherwise. + * return default date ordering in interval pattern. true if the first date + * in pattern is later date, false otherwise. * @stable ICU 4.0 */ UBool getDefaultOrder() const; diff --git a/deps/icu-small/source/i18n/unicode/dtptngen.h b/deps/icu-small/source/i18n/unicode/dtptngen.h index f79c6d45dc6b29..357a25d9a8e197 100644 --- a/deps/icu-small/source/i18n/unicode/dtptngen.h +++ b/deps/icu-small/source/i18n/unicode/dtptngen.h @@ -76,6 +76,13 @@ class U_I18N_API DateTimePatternGenerator : public UObject { #ifndef U_HIDE_INTERNAL_API + /** + * For ICU use only. Skips loading the standard date/time patterns (which is done via DateFormat). + * + * @internal + */ + static DateTimePatternGenerator* U_EXPORT2 createInstanceNoStdPat(const Locale& uLocale, UErrorCode& status); + /** * For ICU use only * @@ -526,7 +533,7 @@ class U_I18N_API DateTimePatternGenerator : public UObject { /** * Constructor. */ - DateTimePatternGenerator(const Locale& locale, UErrorCode & status); + DateTimePatternGenerator(const Locale& locale, UErrorCode & status, UBool skipStdPatterns = false); /** * Copy constructor. @@ -573,7 +580,7 @@ class U_I18N_API DateTimePatternGenerator : public UObject { // with #13183, no longer need flags for b, B }; - void initData(const Locale &locale, UErrorCode &status); + void initData(const Locale &locale, UErrorCode &status, UBool skipStdPatterns = false); void addCanonicalItems(UErrorCode &status); void addICUPatterns(const Locale& locale, UErrorCode& status); void hackTimes(const UnicodeString& hackPattern, UErrorCode& status); diff --git a/deps/icu-small/source/i18n/unicode/fieldpos.h b/deps/icu-small/source/i18n/unicode/fieldpos.h index c9849d67a37d29..6c28d2d3159b66 100644 --- a/deps/icu-small/source/i18n/unicode/fieldpos.h +++ b/deps/icu-small/source/i18n/unicode/fieldpos.h @@ -161,7 +161,7 @@ class U_I18N_API FieldPosition : public UObject { /** * Equality operator. * @param that the object to be compared with. - * @return TRUE if the two field positions are equal, FALSE otherwise. + * @return true if the two field positions are equal, false otherwise. * @stable ICU 2.0 */ UBool operator==(const FieldPosition& that) const; @@ -169,7 +169,7 @@ class U_I18N_API FieldPosition : public UObject { /** * Equality operator. * @param that the object to be compared with. - * @return TRUE if the two field positions are not equal, FALSE otherwise. + * @return true if the two field positions are not equal, false otherwise. * @stable ICU 2.0 */ UBool operator!=(const FieldPosition& that) const; diff --git a/deps/icu-small/source/i18n/unicode/fmtable.h b/deps/icu-small/source/i18n/unicode/fmtable.h index 7bec4f6906e7ee..3a090393ac4bec 100644 --- a/deps/icu-small/source/i18n/unicode/fmtable.h +++ b/deps/icu-small/source/i18n/unicode/fmtable.h @@ -179,7 +179,7 @@ class U_I18N_API Formattable : public UObject { /** * Equality comparison. * @param other the object to be compared with. - * @return TRUE if other are equal to this, FALSE otherwise. + * @return true if other are equal to this, false otherwise. * @stable ICU 2.0 */ UBool operator==(const Formattable &other) const; @@ -187,7 +187,7 @@ class U_I18N_API Formattable : public UObject { /** * Equality operator. * @param other the object to be compared with. - * @return TRUE if other are unequal to this, FALSE otherwise. + * @return true if other are unequal to this, false otherwise. * @stable ICU 2.0 */ UBool operator!=(const Formattable& other) const @@ -277,9 +277,9 @@ class U_I18N_API Formattable : public UObject { Type getType(void) const; /** - * Returns TRUE if the data type of this Formattable object + * Returns true if the data type of this Formattable object * is kDouble, kLong, or kInt64 - * @return TRUE if this is a pure numeric object + * @return true if this is a pure numeric object * @stable ICU 3.0 */ UBool isNumeric() const; diff --git a/deps/icu-small/source/i18n/unicode/formattedvalue.h b/deps/icu-small/source/i18n/unicode/formattedvalue.h index 4469b6328e7cb9..f4e588d01cbddf 100644 --- a/deps/icu-small/source/i18n/unicode/formattedvalue.h +++ b/deps/icu-small/source/i18n/unicode/formattedvalue.h @@ -116,7 +116,7 @@ class U_I18N_API ConstrainedFieldPosition : public UMemory { * Gets the field category for the current position. * * The return value is well-defined only after - * FormattedValue#nextPosition returns TRUE. + * FormattedValue#nextPosition returns true. * * @return The field category saved in the instance. * @stable ICU 64 @@ -129,7 +129,7 @@ class U_I18N_API ConstrainedFieldPosition : public UMemory { * Gets the field for the current position. * * The return value is well-defined only after - * FormattedValue#nextPosition returns TRUE. + * FormattedValue#nextPosition returns true. * * @return The field saved in the instance. * @stable ICU 64 @@ -141,7 +141,7 @@ class U_I18N_API ConstrainedFieldPosition : public UMemory { /** * Gets the INCLUSIVE start index for the current position. * - * The return value is well-defined only after FormattedValue#nextPosition returns TRUE. + * The return value is well-defined only after FormattedValue#nextPosition returns true. * * @return The start index saved in the instance. * @stable ICU 64 @@ -153,7 +153,7 @@ class U_I18N_API ConstrainedFieldPosition : public UMemory { /** * Gets the EXCLUSIVE end index stored for the current position. * - * The return value is well-defined only after FormattedValue#nextPosition returns TRUE. + * The return value is well-defined only after FormattedValue#nextPosition returns true. * * @return The end index saved in the instance. * @stable ICU 64 @@ -301,8 +301,8 @@ class U_I18N_API FormattedValue /* not : public UObject because this is an inter * see ConstrainedFieldPosition#constrainCategory * and ConstrainedFieldPosition#constrainField. * @param status Set if an error occurs. - * @return TRUE if a new occurrence of the field was found; - * FALSE otherwise or if an error was set. + * @return true if a new occurrence of the field was found; + * false otherwise or if an error was set. * * @stable ICU 64 */ diff --git a/deps/icu-small/source/i18n/unicode/fpositer.h b/deps/icu-small/source/i18n/unicode/fpositer.h index ba2a838315c7cb..35aa5da20f2cfa 100644 --- a/deps/icu-small/source/i18n/unicode/fpositer.h +++ b/deps/icu-small/source/i18n/unicode/fpositer.h @@ -96,7 +96,7 @@ class U_I18N_API FieldPositionIterator : public UObject { /** * If the current position is valid, updates the FieldPosition values, advances the iterator, - * and returns TRUE, otherwise returns FALSE. + * and returns true, otherwise returns false. * @stable ICU 4.4 */ UBool next(FieldPosition& fp); diff --git a/deps/icu-small/source/i18n/unicode/gregocal.h b/deps/icu-small/source/i18n/unicode/gregocal.h index 236bd003c160a6..139258d822a30c 100644 --- a/deps/icu-small/source/i18n/unicode/gregocal.h +++ b/deps/icu-small/source/i18n/unicode/gregocal.h @@ -344,7 +344,7 @@ class U_I18N_API GregorianCalendar: public Calendar { UBool isLeapYear(int32_t year) const; /** - * Returns TRUE if the given Calendar object is equivalent to this + * Returns true if the given Calendar object is equivalent to this * one. Calendar override. * * @param other the Calendar to be compared with this Calendar @@ -756,7 +756,7 @@ class U_I18N_API GregorianCalendar: public Calendar { public: // internal implementation /** - * @return TRUE if this calendar has the notion of a default century + * @return true if this calendar has the notion of a default century * @internal */ virtual UBool haveDefaultCentury() const; diff --git a/deps/icu-small/source/i18n/unicode/measfmt.h b/deps/icu-small/source/i18n/unicode/measfmt.h index 8f73de87fa55d6..f95f39f0d5e6a2 100644 --- a/deps/icu-small/source/i18n/unicode/measfmt.h +++ b/deps/icu-small/source/i18n/unicode/measfmt.h @@ -309,7 +309,7 @@ class U_I18N_API MeasureFormat : public Format { /** * ICU use only. * Allows subclass to change locale. Note that this method also changes - * the NumberFormat object. Returns TRUE if locale changed; FALSE if no + * the NumberFormat object. Returns true if locale changed; false if no * change was made. * @internal. */ diff --git a/deps/icu-small/source/i18n/unicode/measunit.h b/deps/icu-small/source/i18n/unicode/measunit.h index 8b65497e12eb63..b9f732ae99011d 100644 --- a/deps/icu-small/source/i18n/unicode/measunit.h +++ b/deps/icu-small/source/i18n/unicode/measunit.h @@ -434,7 +434,7 @@ class U_I18N_API MeasureUnit: public UObject { * For example, if the receiver is "kilowatt" and the argument is "hour-per-day", then the * unit "kilowatt-hour-per-day" is returned. * - * NOTE: Only works on SINGLE and COMPOUND units. If either unit (receivee and argument) is a + * NOTE: Only works on SINGLE and COMPOUND units. If either unit (receiver and argument) is a * MIXED unit, an error will occur. For more information, see UMeasureUnitComplexity. * * @param other The MeasureUnit to multiply with the target. @@ -445,9 +445,9 @@ class U_I18N_API MeasureUnit: public UObject { MeasureUnit product(const MeasureUnit& other, UErrorCode& status) const; #endif // U_HIDE_DRAFT_API -#ifndef U_HIDE_INTERNAL_API +#ifndef U_HIDE_DRAFT_API /** - * Gets the list of SINGLE units contained within a MIXED of COMPOUND unit. + * Gets the list of SINGLE units contained within a MIXED or COMPOUND unit. * * Examples: * - Given "meter-kilogram-per-second", three units will be returned: "meter", @@ -457,15 +457,12 @@ class U_I18N_API MeasureUnit: public UObject { * * If this is a SINGLE unit, an array of length 1 will be returned. * - * TODO(ICU-21021): Finalize this API and propose it as draft. - * - * @param outCount The number of elements in the return array. * @param status Set if an error occurs. - * @return An array of single units, owned by the caller. - * @internal ICU 67 Technical Preview + * @return A pair with the list of units as a LocalArray and the number of units in the list. + * @draft ICU 68 */ - LocalArray splitToSingleUnits(int32_t& outCount, UErrorCode& status) const; -#endif // U_HIDE_INTERNAL_API + inline std::pair, int32_t> splitToSingleUnits(UErrorCode& status) const; +#endif // U_HIDE_DRAFT_API /** * getAvailable gets all of the available units. @@ -540,33 +537,10 @@ class U_I18N_API MeasureUnit: public UObject { #ifndef U_HIDE_INTERNAL_API /** * ICU use only. - * Returns associated array index for this measure unit. Only valid for - * non-currency measure units. - * @internal - */ - int32_t getIndex() const; - - /** - * ICU use only. - * Returns maximum value from getIndex plus 1. - * @internal - */ - static int32_t getIndexCount(); - - /** - * ICU use only. - * @return the unit.getIndex() of the unit which has this unit.getType() and unit.getSubtype(), - * or a negative value if there is no such unit + * Returns associated array index for this measure unit. * @internal */ - static int32_t internalGetIndexForTypeAndSubtype(const char *type, const char *subtype); - - /** - * ICU use only. - * @internal - */ - static MeasureUnit resolveUnitPerUnit( - const MeasureUnit &unit, const MeasureUnit &perUnit, bool* isResolved); + int32_t getOffset() const; #endif /* U_HIDE_INTERNAL_API */ // All code between the "Start generated createXXX methods" comment and @@ -913,22 +887,6 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getMole(); - /** - * Returns by pointer, unit of concentr: permillion. - * Caller owns returned value and must free it. - * Also see {@link #getPartPerMillion()}. - * @param status ICU error code. - * @stable ICU 57 - */ - static MeasureUnit *createPartPerMillion(UErrorCode &status); - - /** - * Returns by value, unit of concentr: permillion. - * Also see {@link #createPartPerMillion()}. - * @stable ICU 64 - */ - static MeasureUnit getPartPerMillion(); - /** * Returns by pointer, unit of concentr: percent. * Caller owns returned value and must free it. @@ -961,6 +919,22 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getPermille(); + /** + * Returns by pointer, unit of concentr: permillion. + * Caller owns returned value and must free it. + * Also see {@link #getPartPerMillion()}. + * @param status ICU error code. + * @stable ICU 57 + */ + static MeasureUnit *createPartPerMillion(UErrorCode &status); + + /** + * Returns by value, unit of concentr: permillion. + * Also see {@link #createPartPerMillion()}. + * @stable ICU 64 + */ + static MeasureUnit getPartPerMillion(); + /** * Returns by pointer, unit of concentr: permyriad. * Caller owns returned value and must free it. @@ -1265,23 +1239,21 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getDayPerson(); -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of duration: decade. * Caller owns returned value and must free it. * Also see {@link #getDecade()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createDecade(UErrorCode &status); /** * Returns by value, unit of duration: decade. * Also see {@link #createDecade()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getDecade(); -#endif /* U_HIDE_DRAFT_API */ /** * Returns by pointer, unit of duration: hour. @@ -1667,23 +1639,21 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getKilowattHour(); -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of energy: therm-us. * Caller owns returned value and must free it. * Also see {@link #getThermUs()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createThermUs(UErrorCode &status); /** * Returns by value, unit of energy: therm-us. * Also see {@link #createThermUs()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getThermUs(); -#endif /* U_HIDE_DRAFT_API */ /** * Returns by pointer, unit of force: newton. @@ -1782,130 +1752,134 @@ class U_I18N_API MeasureUnit: public UObject { static MeasureUnit getMegahertz(); #ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of graphics: dot. + * Caller owns returned value and must free it. + * Also see {@link #getDot()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createDot(UErrorCode &status); + + /** + * Returns by value, unit of graphics: dot. + * Also see {@link #createDot()}. + * @draft ICU 68 + */ + static MeasureUnit getDot(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of graphics: dot-per-centimeter. * Caller owns returned value and must free it. * Also see {@link #getDotPerCentimeter()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createDotPerCentimeter(UErrorCode &status); /** * Returns by value, unit of graphics: dot-per-centimeter. * Also see {@link #createDotPerCentimeter()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getDotPerCentimeter(); -#endif /* U_HIDE_DRAFT_API */ -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of graphics: dot-per-inch. * Caller owns returned value and must free it. * Also see {@link #getDotPerInch()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createDotPerInch(UErrorCode &status); /** * Returns by value, unit of graphics: dot-per-inch. * Also see {@link #createDotPerInch()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getDotPerInch(); -#endif /* U_HIDE_DRAFT_API */ -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of graphics: em. * Caller owns returned value and must free it. * Also see {@link #getEm()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createEm(UErrorCode &status); /** * Returns by value, unit of graphics: em. * Also see {@link #createEm()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getEm(); -#endif /* U_HIDE_DRAFT_API */ -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of graphics: megapixel. * Caller owns returned value and must free it. * Also see {@link #getMegapixel()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createMegapixel(UErrorCode &status); /** * Returns by value, unit of graphics: megapixel. * Also see {@link #createMegapixel()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getMegapixel(); -#endif /* U_HIDE_DRAFT_API */ -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of graphics: pixel. * Caller owns returned value and must free it. * Also see {@link #getPixel()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createPixel(UErrorCode &status); /** * Returns by value, unit of graphics: pixel. * Also see {@link #createPixel()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getPixel(); -#endif /* U_HIDE_DRAFT_API */ -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of graphics: pixel-per-centimeter. * Caller owns returned value and must free it. * Also see {@link #getPixelPerCentimeter()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createPixelPerCentimeter(UErrorCode &status); /** * Returns by value, unit of graphics: pixel-per-centimeter. * Also see {@link #createPixelPerCentimeter()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getPixelPerCentimeter(); -#endif /* U_HIDE_DRAFT_API */ -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of graphics: pixel-per-inch. * Caller owns returned value and must free it. * Also see {@link #getPixelPerInch()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createPixelPerInch(UErrorCode &status); /** * Returns by value, unit of graphics: pixel-per-inch. * Also see {@link #createPixelPerInch()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getPixelPerInch(); -#endif /* U_HIDE_DRAFT_API */ /** * Returns by pointer, unit of length: astronomical-unit. @@ -1955,6 +1929,24 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getDecimeter(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of length: earth-radius. + * Caller owns returned value and must free it. + * Also see {@link #getEarthRadius()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createEarthRadius(UErrorCode &status); + + /** + * Returns by value, unit of length: earth-radius. + * Also see {@link #createEarthRadius()}. + * @draft ICU 68 + */ + static MeasureUnit getEarthRadius(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of length: fathom. * Caller owns returned value and must free it. @@ -2243,6 +2235,42 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getYard(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of light: candela. + * Caller owns returned value and must free it. + * Also see {@link #getCandela()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createCandela(UErrorCode &status); + + /** + * Returns by value, unit of light: candela. + * Also see {@link #createCandela()}. + * @draft ICU 68 + */ + static MeasureUnit getCandela(); +#endif /* U_HIDE_DRAFT_API */ + +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of light: lumen. + * Caller owns returned value and must free it. + * Also see {@link #getLumen()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createLumen(UErrorCode &status); + + /** + * Returns by value, unit of light: lumen. + * Also see {@link #createLumen()}. + * @draft ICU 68 + */ + static MeasureUnit getLumen(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of light: lux. * Caller owns returned value and must free it. @@ -2323,6 +2351,24 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getEarthMass(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of mass: grain. + * Caller owns returned value and must free it. + * Also see {@link #getGrain()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createGrain(UErrorCode &status); + + /** + * Returns by value, unit of mass: grain. + * Also see {@link #createGrain()}. + * @draft ICU 68 + */ + static MeasureUnit getGrain(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of mass: gram. * Caller owns returned value and must free it. @@ -2611,23 +2657,21 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getAtmosphere(); -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of pressure: bar. * Caller owns returned value and must free it. * Also see {@link #getBar()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createBar(UErrorCode &status); /** * Returns by value, unit of pressure: bar. * Also see {@link #createBar()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getBar(); -#endif /* U_HIDE_DRAFT_API */ /** * Returns by pointer, unit of pressure: hectopascal. @@ -2725,23 +2769,21 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getMillimeterOfMercury(); -#ifndef U_HIDE_DRAFT_API /** * Returns by pointer, unit of pressure: pascal. * Caller owns returned value and must free it. * Also see {@link #getPascal()}. * @param status ICU error code. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit *createPascal(UErrorCode &status); /** * Returns by value, unit of pressure: pascal. * Also see {@link #createPascal()}. - * @draft ICU 65 + * @stable ICU 65 */ static MeasureUnit getPascal(); -#endif /* U_HIDE_DRAFT_API */ /** * Returns by pointer, unit of pressure: pound-force-per-square-inch. @@ -3143,6 +3185,78 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getDeciliter(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of volume: dessert-spoon. + * Caller owns returned value and must free it. + * Also see {@link #getDessertSpoon()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createDessertSpoon(UErrorCode &status); + + /** + * Returns by value, unit of volume: dessert-spoon. + * Also see {@link #createDessertSpoon()}. + * @draft ICU 68 + */ + static MeasureUnit getDessertSpoon(); +#endif /* U_HIDE_DRAFT_API */ + +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of volume: dessert-spoon-imperial. + * Caller owns returned value and must free it. + * Also see {@link #getDessertSpoonImperial()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createDessertSpoonImperial(UErrorCode &status); + + /** + * Returns by value, unit of volume: dessert-spoon-imperial. + * Also see {@link #createDessertSpoonImperial()}. + * @draft ICU 68 + */ + static MeasureUnit getDessertSpoonImperial(); +#endif /* U_HIDE_DRAFT_API */ + +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of volume: dram. + * Caller owns returned value and must free it. + * Also see {@link #getDram()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createDram(UErrorCode &status); + + /** + * Returns by value, unit of volume: dram. + * Also see {@link #createDram()}. + * @draft ICU 68 + */ + static MeasureUnit getDram(); +#endif /* U_HIDE_DRAFT_API */ + +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of volume: drop. + * Caller owns returned value and must free it. + * Also see {@link #getDrop()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createDrop(UErrorCode &status); + + /** + * Returns by value, unit of volume: drop. + * Also see {@link #createDrop()}. + * @draft ICU 68 + */ + static MeasureUnit getDrop(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of volume: fluid-ounce. * Caller owns returned value and must free it. @@ -3223,6 +3337,24 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getHectoliter(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of volume: jigger. + * Caller owns returned value and must free it. + * Also see {@link #getJigger()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createJigger(UErrorCode &status); + + /** + * Returns by value, unit of volume: jigger. + * Also see {@link #createJigger()}. + * @draft ICU 68 + */ + static MeasureUnit getJigger(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of volume: liter. * Caller owns returned value and must free it. @@ -3271,6 +3403,24 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getMilliliter(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of volume: pinch. + * Caller owns returned value and must free it. + * Also see {@link #getPinch()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createPinch(UErrorCode &status); + + /** + * Returns by value, unit of volume: pinch. + * Also see {@link #createPinch()}. + * @draft ICU 68 + */ + static MeasureUnit getPinch(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of volume: pint. * Caller owns returned value and must free it. @@ -3319,6 +3469,24 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getQuart(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of volume: quart-imperial. + * Caller owns returned value and must free it. + * Also see {@link #getQuartImperial()}. + * @param status ICU error code. + * @draft ICU 68 + */ + static MeasureUnit *createQuartImperial(UErrorCode &status); + + /** + * Returns by value, unit of volume: quart-imperial. + * Also see {@link #createQuartImperial()}. + * @draft ICU 68 + */ + static MeasureUnit getQuartImperial(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of volume: tablespoon. * Caller owns returned value and must free it. @@ -3351,7 +3519,6 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getTeaspoon(); - // End generated createXXX methods protected: @@ -3369,12 +3536,6 @@ class U_I18N_API MeasureUnit: public UObject { */ void initCurrency(StringPiece isoCurrency); - /** - * For ICU use only. - * @internal - */ - void initNoUnit(const char *subtype); - #endif /* U_HIDE_INTERNAL_API */ private: @@ -3393,7 +3554,6 @@ class U_I18N_API MeasureUnit: public UObject { MeasureUnit(int32_t typeId, int32_t subTypeId); MeasureUnit(MeasureUnitImpl&& impl); void setTo(int32_t typeId, int32_t subTypeId); - int32_t getOffset() const; static MeasureUnit *create(int typeId, int subTypeId, UErrorCode &status); /** @@ -3405,9 +3565,21 @@ class U_I18N_API MeasureUnit: public UObject { */ static bool findBySubType(StringPiece subType, MeasureUnit* output); + /** Internal version of public API */ + LocalArray splitToSingleUnitsImpl(int32_t& outCount, UErrorCode& status) const; + friend struct MeasureUnitImpl; }; +#ifndef U_HIDE_DRAFT_API // @draft ICU 68 +inline std::pair, int32_t> +MeasureUnit::splitToSingleUnits(UErrorCode& status) const { + int32_t length; + auto array = splitToSingleUnitsImpl(length, status); + return std::make_pair(std::move(array), length); +} +#endif // U_HIDE_DRAFT_API + U_NAMESPACE_END #endif // !UNCONFIG_NO_FORMATTING diff --git a/deps/icu-small/source/i18n/unicode/measure.h b/deps/icu-small/source/i18n/unicode/measure.h index a15173d739d94f..0ed02626b13b8f 100644 --- a/deps/icu-small/source/i18n/unicode/measure.h +++ b/deps/icu-small/source/i18n/unicode/measure.h @@ -48,7 +48,7 @@ class U_I18N_API Measure: public UObject { * Construct an object with the given numeric amount and the given * unit. After this call, the caller must not delete the given * unit object. - * @param number a numeric object; amount.isNumeric() must be TRUE + * @param number a numeric object; amount.isNumeric() must be true * @param adoptedUnit the unit object, which must not be NULL * @param ec input-output error code. If the amount or the unit * is invalid, then this will be set to a failing value. diff --git a/deps/icu-small/source/i18n/unicode/msgfmt.h b/deps/icu-small/source/i18n/unicode/msgfmt.h index 99b0eaeec1dcd8..2d9bc8f2e2b0f8 100644 --- a/deps/icu-small/source/i18n/unicode/msgfmt.h +++ b/deps/icu-small/source/i18n/unicode/msgfmt.h @@ -255,7 +255,7 @@ class NumberFormat; * or preformatted values, but not pattern strings or custom format objects.

    * *

    For more details, see the - * ICU User Guide.

    + * ICU User Guide.

    * *

    Usage Information

    * @@ -920,7 +920,7 @@ class U_I18N_API MessageFormat : public Format { int32_t argTypeCapacity; /** - * TRUE if there are different argTypes for the same argument. + * true if there are different argTypes for the same argument. * This only matters when the MessageFormat is used in the plain C (umsg_xxx) API * where the pattern argTypes determine how the va_arg list is read. */ diff --git a/deps/icu-small/source/i18n/unicode/nounit.h b/deps/icu-small/source/i18n/unicode/nounit.h index 61b5c16ee3955b..cee45e352df473 100644 --- a/deps/icu-small/source/i18n/unicode/nounit.h +++ b/deps/icu-small/source/i18n/unicode/nounit.h @@ -29,80 +29,53 @@ U_NAMESPACE_BEGIN /** * Dimensionless unit for percent and permille. + * Prior to ICU 68, this namespace was a class with the same name. * @see NumberFormatter - * @draft ICU 60 + * @draft ICU 68 */ -class U_I18N_API NoUnit: public MeasureUnit { -public: +namespace NoUnit { /** * Returns an instance for the base unit (dimensionless and no scaling). * - * @return a NoUnit instance - * @draft ICU 60 + * Prior to ICU 68, this function returned a NoUnit by value. + * + * Since ICU 68, this function returns the same value as the default MeasureUnit constructor. + * + * @return a MeasureUnit instance + * @draft ICU 68 */ - static NoUnit U_EXPORT2 base(); + static inline MeasureUnit U_EXPORT2 base() { + return MeasureUnit(); + } /** * Returns an instance for percent, or 1/100 of a base unit. * - * @return a NoUnit instance - * @draft ICU 60 + * Prior to ICU 68, this function returned a NoUnit by value. + * + * Since ICU 68, this function returns the same value as MeasureUnit::getPercent(). + * + * @return a MeasureUnit instance + * @draft ICU 68 */ - static NoUnit U_EXPORT2 percent(); + static inline MeasureUnit U_EXPORT2 percent() { + return MeasureUnit::getPercent(); + } /** * Returns an instance for permille, or 1/1000 of a base unit. * - * @return a NoUnit instance - * @draft ICU 60 - */ - static NoUnit U_EXPORT2 permille(); - - /** - * Copy operator. - * @draft ICU 60 - */ - NoUnit(const NoUnit& other); - - /** - * Destructor. - * @draft ICU 60 - */ - virtual ~NoUnit(); - - /** - * Return a polymorphic clone of this object. The result will - * have the same class as returned by getDynamicClassID(). - * @draft ICU 60 - */ - virtual NoUnit* clone() const; - - /** - * Returns a unique class ID for this object POLYMORPHICALLY. - * This method implements a simple form of RTTI used by ICU. - * @return The class ID for this object. All objects of a given - * class have the same class ID. Objects of other classes have - * different class IDs. - * @draft ICU 60 - */ - virtual UClassID getDynamicClassID() const; - - /** - * Returns the class ID for this class. This is used to compare to - * the return value of getDynamicClassID(). - * @return The class ID for all objects of this class. - * @draft ICU 60 - */ - static UClassID U_EXPORT2 getStaticClassID(); - -private: - /** - * Constructor - * @internal (private) + * Prior to ICU 68, this function returned a NoUnit by value. + * + * Since ICU 68, this function returns the same value as MeasureUnit::getPermille(). + * + * @return a MeasureUnit instance + * @draft ICU 68 */ - NoUnit(const char* subtype); - -}; + static inline MeasureUnit U_EXPORT2 permille() { + return MeasureUnit::getPermille(); + } +} U_NAMESPACE_END diff --git a/deps/icu-small/source/i18n/unicode/numberformatter.h b/deps/icu-small/source/i18n/unicode/numberformatter.h index 615cf49f7b7539..06329b8e7aa024 100644 --- a/deps/icu-small/source/i18n/unicode/numberformatter.h +++ b/deps/icu-small/source/i18n/unicode/numberformatter.h @@ -99,6 +99,13 @@ class MultiplierParseHandler; } } +namespace units { + +// Forward declarations: +class UnitsRouter; + +} // namespace units + namespace number { // icu::number // Forward declarations: @@ -157,6 +164,7 @@ struct RangeMacroProps; struct UFormattedNumberImpl; class MutablePatternModifier; class ImmutablePatternModifier; +struct DecimalFormatWarehouse; /** * Used for NumberRangeFormatter and implemented in numrange_fluent.cpp. @@ -371,9 +379,9 @@ class U_I18N_API Notation : public UMemory { UBool copyErrorTo(UErrorCode &status) const { if (fType == NTN_ERROR) { status = fUnion.errorCode; - return TRUE; + return true; } - return FALSE; + return false; } // To allow MacroProps to initialize empty instances: @@ -705,12 +713,8 @@ class U_I18N_API Precision : public UMemory { typedef PrecisionUnion::FractionSignificantSettings FractionSignificantSettings; typedef PrecisionUnion::IncrementSettings IncrementSettings; - /** The Precision encapsulates the RoundingMode when used within the implementation. */ - UNumberFormatRoundingMode fRoundingMode; - - Precision(const PrecisionType& type, const PrecisionUnion& union_, - UNumberFormatRoundingMode roundingMode) - : fType(type), fUnion(union_), fRoundingMode(roundingMode) {} + Precision(const PrecisionType& type, const PrecisionUnion& union_) + : fType(type), fUnion(union_) {} Precision(UErrorCode errorCode) : fType(RND_ERROR) { fUnion.errorCode = errorCode; @@ -725,9 +729,9 @@ class U_I18N_API Precision : public UMemory { UBool copyErrorTo(UErrorCode &status) const { if (fType == RND_ERROR) { status = fUnion.errorCode; - return TRUE; + return true; } - return FALSE; + return false; } // On the parent type so that this method can be called internally on Precision instances. @@ -744,8 +748,6 @@ class U_I18N_API Precision : public UMemory { static CurrencyPrecision constructCurrency(UCurrencyUsage usage); - static Precision constructPassThrough(); - // To allow MacroProps/MicroProps to initialize bogus instances: friend struct impl::MacroProps; friend struct impl::MicroProps; @@ -766,6 +768,9 @@ class U_I18N_API Precision : public UMemory { // To allow access to the skeleton generation code: friend class impl::GeneratorHelpers; + + // To allow access to isBogus and the default (bogus) constructor: + friend class units::UnitsRouter; }; /** @@ -969,9 +974,9 @@ class U_I18N_API IntegerWidth : public UMemory { UBool copyErrorTo(UErrorCode &status) const { if (fHasError) { status = fUnion.errorCode; - return TRUE; + return true; } - return FALSE; + return false; } void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const; @@ -1095,11 +1100,11 @@ class U_I18N_API Scale : public UMemory { } UBool copyErrorTo(UErrorCode &status) const { - if (fError != U_ZERO_ERROR) { + if (U_FAILURE(fError)) { status = fError; - return TRUE; + return true; } - return FALSE; + return false; } void applyTo(impl::DecimalQuantity& quantity) const; @@ -1126,6 +1131,71 @@ class U_I18N_API Scale : public UMemory { namespace impl { +// Do not enclose entire Usage with #ifndef U_HIDE_INTERNAL_API, needed for a protected field +/** + * Manages NumberFormatterSettings::usage()'s char* instance on the heap. + * @internal + */ +class U_I18N_API Usage : public UMemory { + +#ifndef U_HIDE_INTERNAL_API + + public: + /** @internal */ + Usage(const Usage& other); + + /** @internal */ + Usage& operator=(const Usage& other); + + /** @internal */ + Usage(Usage &&src) U_NOEXCEPT; + + /** @internal */ + Usage& operator=(Usage&& src) U_NOEXCEPT; + + /** @internal */ + ~Usage(); + + /** @internal */ + int16_t length() const { return fLength; } + + /** @internal + * Makes a copy of value. Set to "" to unset. + */ + void set(StringPiece value); + + /** @internal */ + bool isSet() const { return fLength > 0; } + +#endif // U_HIDE_INTERNAL_API + + private: + char *fUsage; + int16_t fLength; + UErrorCode fError; + + Usage() : fUsage(nullptr), fLength(0), fError(U_ZERO_ERROR) {} + + /** @internal */ + UBool copyErrorTo(UErrorCode &status) const { + if (U_FAILURE(fError)) { + status = fError; + return true; + } + return false; + } + + // Allow NumberFormatterImpl to access fUsage. + friend class impl::NumberFormatterImpl; + + // Allow skeleton generation code to access private members. + friend class impl::GeneratorHelpers; + + // Allow MacroProps/MicroProps to initialize empty instances and to call + // copyErrorTo(). + friend struct impl::MacroProps; +}; + // Do not enclose entire SymbolsWrapper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field /** @internal */ class U_I18N_API SymbolsWrapper : public UMemory { @@ -1192,12 +1262,12 @@ class U_I18N_API SymbolsWrapper : public UMemory { UBool copyErrorTo(UErrorCode &status) const { if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; - return TRUE; + return true; } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; - return TRUE; + return true; } - return FALSE; + return false; } private: @@ -1239,13 +1309,13 @@ class U_I18N_API Grouper : public UMemory { fGrouping2(grouping2), fMinGrouping(minGrouping), fStrategy(strategy) {} -#endif // U_HIDE_INTERNAL_API /** @internal */ int16_t getPrimary() const; /** @internal */ int16_t getSecondary() const; +#endif // U_HIDE_INTERNAL_API private: /** @@ -1309,10 +1379,10 @@ class U_I18N_API Padder : public UMemory { /** @internal */ static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position); -#endif // U_HIDE_INTERNAL_API /** @internal */ static Padder forProperties(const DecimalFormatProperties& properties); +#endif // U_HIDE_INTERNAL_API private: UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding @@ -1341,9 +1411,9 @@ class U_I18N_API Padder : public UMemory { UBool copyErrorTo(UErrorCode &status) const { if (fWidth == -3) { status = fUnion.errorCode; - return TRUE; + return true; } - return FALSE; + return false; } bool isValid() const { @@ -1372,10 +1442,10 @@ struct U_I18N_API MacroProps : public UMemory { Notation notation; /** @internal */ - MeasureUnit unit; // = NoUnit::base(); + MeasureUnit unit; // = MeasureUnit(); (the base dimensionless unit) /** @internal */ - MeasureUnit perUnit; // = NoUnit::base(); + MeasureUnit perUnit; // = MeasureUnit(); (the base dimensionless unit) /** @internal */ Precision precision; // = Precision(); (bogus) @@ -1409,6 +1479,9 @@ struct U_I18N_API MacroProps : public UMemory { /** @internal */ Scale scale; // = Scale(); (benign value) + /** @internal */ + Usage usage; // = Usage(); (no usage) + /** @internal */ const AffixPatternProvider* affixProvider = nullptr; // no ownership @@ -1430,7 +1503,7 @@ struct U_I18N_API MacroProps : public UMemory { bool copyErrorTo(UErrorCode &status) const { return notation.copyErrorTo(status) || precision.copyErrorTo(status) || padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) || - symbols.copyErrorTo(status) || scale.copyErrorTo(status); + symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status); } }; @@ -1507,10 +1580,15 @@ class U_I18N_API NumberFormatterSettings { * All units will be properly localized with locale data, and all units are compatible with notation styles, * rounding precisions, and other number formatter settings. * + * \note If the usage() is set, the output unit **will be changed** to + * produce localised units, according to usage, locale and unit. See + * FormattedNumber::getOutputUnit(). + * * Pass this method any instance of {@link MeasureUnit}. For units of measure: * *
          * NumberFormatter::with().unit(MeasureUnit::getMeter())
    +     * NumberFormatter::with().unit(MeasureUnit::forIdentifier("foot-per-second", status))
          * 
    * * Currency: @@ -1693,7 +1771,7 @@ class U_I18N_API NumberFormatterSettings { * * The default is HALF_EVEN. For more information on rounding mode, see the ICU userguide here: * - * http://userguide.icu-project.org/formatparse/numbers/rounding-modes + * https://unicode-org.github.io/icu/userguide/format_parse/numbers/rounding-modes * * @param roundingMode The rounding mode to use. * @return The fluent chain. @@ -2038,6 +2116,61 @@ class U_I18N_API NumberFormatterSettings { */ Derived scale(const Scale &scale) &&; +#ifndef U_HIDE_DRAFT_API + /** + * Specifies the usage for which numbers will be formatted ("person-height", + * "road", "rainfall", etc.) + * + * When a `usage` is specified, the output unit will change depending on the + * `Locale` and the unit quantity. For example, formatting length + * measurements specified in meters: + * + * `NumberFormatter::with().usage("person").unit(MeasureUnit::getMeter()).locale("en-US")` + * * When formatting 0.25, the output will be "10 inches". + * * When formatting 1.50, the output will be "4 feet and 11 inches". + * + * The input unit specified via unit() determines the type of measurement + * being formatted (e.g. "length" when the unit is "foot"). The usage + * requested will be looked for only within this category of measurement + * units. + * + * The output unit can be found via FormattedNumber::getOutputUnit(). + * + * If the usage has multiple parts (e.g. "land-agriculture-grain") and does + * not match a known usage preference, the last part will be dropped + * repeatedly until a match is found (e.g. trying "land-agriculture", then + * "land"). If a match is still not found, usage will fall back to + * "default". + * + * Setting usage to an empty string clears the usage (disables usage-based + * localized formatting). + * + * Setting a usage string but not a correct input unit will result in an + * U_ILLEGAL_ARGUMENT_ERROR. + * + * When using usage, specifying rounding or precision is unnecessary. + * Specifying a precision in some manner will override the default + * formatting. + * + * @param usage A `usage` parameter from the units resource. See the + * unitPreferenceData in *source/data/misc/units.txt*, generated from + * `unitPreferenceData` in [CLDR's + * supplemental/units.xml](https://github.com/unicode-org/cldr/blob/master/common/supplemental/units.xml). + * @return The fluent chain. + * @draft ICU 68 + */ + Derived usage(StringPiece usage) const &; + + /** + * Overload of usage() for use on an rvalue reference. + * + * @param usage The unit `usage`. + * @return The fluent chain. + * @draft ICU 68 + */ + Derived usage(StringPiece usage) &&; +#endif // U_HIDE_DRAFT_API + #ifndef U_HIDE_INTERNAL_API /** @@ -2120,13 +2253,13 @@ class U_I18N_API NumberFormatterSettings { /** * Sets the UErrorCode if an error occurred in the fluent chain. * Preserves older error codes in the outErrorCode. - * @return TRUE if U_FAILURE(outErrorCode) + * @return true if U_FAILURE(outErrorCode) * @stable ICU 60 */ UBool copyErrorTo(UErrorCode &outErrorCode) const { if (U_FAILURE(outErrorCode)) { // Do not overwrite the older error code - return TRUE; + return true; } fMacros.copyErrorTo(outErrorCode); return U_FAILURE(outErrorCode); @@ -2385,6 +2518,10 @@ class U_I18N_API LocalizedNumberFormatter const impl::NumberFormatterImpl* fCompiled {nullptr}; char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t + // Owned pointer to a DecimalFormatWarehouse, used when copying a LocalizedNumberFormatter + // from a DecimalFormat. + const impl::DecimalFormatWarehouse* fWarehouse {nullptr}; + explicit LocalizedNumberFormatter(const NumberFormatterSettings& other); explicit LocalizedNumberFormatter(NumberFormatterSettings&& src) U_NOEXCEPT; @@ -2393,10 +2530,12 @@ class U_I18N_API LocalizedNumberFormatter LocalizedNumberFormatter(impl::MacroProps &¯os, const Locale &locale); - void clear(); + void resetCompiled(); void lnfMoveHelper(LocalizedNumberFormatter&& src); + void lnfCopyHelper(const LocalizedNumberFormatter& src, UErrorCode& status); + /** * @return true if the compiled formatter is available. */ @@ -2485,7 +2624,6 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { /** @copydoc FormattedValue::nextPosition() */ UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE; -#ifndef U_HIDE_DRAFT_API /** * Export the formatted number as a "numeric string" conforming to the * syntax defined in the Decimal Arithmetic Specification, available at @@ -2502,10 +2640,24 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { * for example, std::string. * @param status Set if an error occurs. * @return A StringClass containing the numeric string. - * @draft ICU 65 + * @stable ICU 65 */ template inline StringClass toDecimalNumber(UErrorCode& status) const; + +#ifndef U_HIDE_DRAFT_API + /** + * Gets the resolved output unit. + * + * The output unit is dependent upon the localized preferences for the usage + * specified via NumberFormatterSettings::usage(), and may be a unit with + * UMEASURE_UNIT_MIXED unit complexity (MeasureUnit::getComplexity()), such + * as "foot-and-inch" or "hour-and-minute-and-second". + * + * @return `MeasureUnit`. + * @draft ICU 68 + */ + MeasureUnit getOutputUnit(UErrorCode& status) const; #endif // U_HIDE_DRAFT_API #ifndef U_HIDE_INTERNAL_API @@ -2541,7 +2693,6 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { explicit FormattedNumber(UErrorCode errorCode) : fData(nullptr), fErrorCode(errorCode) {} - // TODO(ICU-20775): Propose this as API. void toDecimalNumber(ByteSink& sink, UErrorCode& status) const; // To give LocalizedNumberFormatter format methods access to this class's constructor: @@ -2639,4 +2790,3 @@ U_NAMESPACE_END #endif /* U_SHOW_CPLUSPLUS_API */ #endif // __NUMBERFORMATTER_H__ - diff --git a/deps/icu-small/source/i18n/unicode/numberrangeformatter.h b/deps/icu-small/source/i18n/unicode/numberrangeformatter.h index 59f14d8be53189..67339bb6e68da8 100644 --- a/deps/icu-small/source/i18n/unicode/numberrangeformatter.h +++ b/deps/icu-small/source/i18n/unicode/numberrangeformatter.h @@ -16,6 +16,7 @@ #include "unicode/formattedvalue.h" #include "unicode/fpositer.h" #include "unicode/numberformatter.h" +#include "unicode/unumberrangeformatter.h" /** * \file @@ -31,7 +32,7 @@ * .numberFormatterFirst(NumberFormatter::with().adoptUnit(MeasureUnit::createMeter())) * .numberFormatterSecond(NumberFormatter::with().adoptUnit(MeasureUnit::createKilometer())) * .locale("en-GB") - * .formatRange(750, 1.2, status) + * .formatFormattableRange(750, 1.2, status) * .toString(status); * // => "750 m - 1.2 km" * @@ -44,130 +45,11 @@ */ -/** - * Defines how to merge fields that are identical across the range sign. - * - * @stable ICU 63 - */ -typedef enum UNumberRangeCollapse { - /** - * Use locale data and heuristics to determine how much of the string to collapse. Could end up collapsing none, - * some, or all repeated pieces in a locale-sensitive way. - * - * The heuristics used for this option are subject to change over time. - * - * @stable ICU 63 - */ - UNUM_RANGE_COLLAPSE_AUTO, - - /** - * Do not collapse any part of the number. Example: "3.2 thousand kilograms – 5.3 thousand kilograms" - * - * @stable ICU 63 - */ - UNUM_RANGE_COLLAPSE_NONE, - - /** - * Collapse the unit part of the number, but not the notation, if present. Example: "3.2 thousand – 5.3 thousand - * kilograms" - * - * @stable ICU 63 - */ - UNUM_RANGE_COLLAPSE_UNIT, - - /** - * Collapse any field that is equal across the range sign. May introduce ambiguity on the magnitude of the - * number. Example: "3.2 – 5.3 thousand kilograms" - * - * @stable ICU 63 - */ - UNUM_RANGE_COLLAPSE_ALL -} UNumberRangeCollapse; - -/** - * Defines the behavior when the two numbers in the range are identical after rounding. To programmatically detect - * when the identity fallback is used, compare the lower and upper BigDecimals via FormattedNumber. - * - * @stable ICU 63 - * @see NumberRangeFormatter - */ -typedef enum UNumberRangeIdentityFallback { - /** - * Show the number as a single value rather than a range. Example: "$5" - * - * @stable ICU 63 - */ - UNUM_IDENTITY_FALLBACK_SINGLE_VALUE, - - /** - * Show the number using a locale-sensitive approximation pattern. If the numbers were the same before rounding, - * show the single value. Example: "~$5" or "$5" - * - * @stable ICU 63 - */ - UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE, - - /** - * Show the number using a locale-sensitive approximation pattern. Use the range pattern always, even if the - * inputs are the same. Example: "~$5" - * - * @stable ICU 63 - */ - UNUM_IDENTITY_FALLBACK_APPROXIMATELY, - - /** - * Show the number as the range of two equal values. Use the range pattern always, even if the inputs are the - * same. Example (with RangeCollapse.NONE): "$5 – $5" - * - * @stable ICU 63 - */ - UNUM_IDENTITY_FALLBACK_RANGE -} UNumberRangeIdentityFallback; - -/** - * Used in the result class FormattedNumberRange to indicate to the user whether the numbers formatted in the range - * were equal or not, and whether or not the identity fallback was applied. - * - * @stable ICU 63 - * @see NumberRangeFormatter - */ -typedef enum UNumberRangeIdentityResult { - /** - * Used to indicate that the two numbers in the range were equal, even before any rounding rules were applied. - * - * @stable ICU 63 - * @see NumberRangeFormatter - */ - UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING, - - /** - * Used to indicate that the two numbers in the range were equal, but only after rounding rules were applied. - * - * @stable ICU 63 - * @see NumberRangeFormatter - */ - UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING, - - /** - * Used to indicate that the two numbers in the range were not equal, even after rounding rules were applied. - * - * @stable ICU 63 - * @see NumberRangeFormatter - */ - UNUM_IDENTITY_RESULT_NOT_EQUAL, - -#ifndef U_HIDE_INTERNAL_API - /** - * The number of entries in this enum. - * @internal - */ - UNUM_IDENTITY_RESULT_COUNT -#endif - -} UNumberRangeIdentityResult; - U_NAMESPACE_BEGIN +// Forward declarations: +class PluralRules; + namespace number { // icu::number // Forward declarations: @@ -182,6 +64,7 @@ struct RangeMacroProps; class DecimalQuantity; class UFormattedNumberRangeData; class NumberRangeFormatterImpl; +struct UFormattedNumberRangeImpl; } // namespace impl @@ -418,8 +301,8 @@ class U_I18N_API NumberRangeFormatterSettings { /** * Sets the behavior when the two sides of the range are the same. This could happen if the same two numbers are - * passed to the formatRange function, or if different numbers are passed to the function but they become the same - * after rounding rules are applied. Possible values: + * passed to the formatFormattableRange function, or if different numbers are passed to the function but they + * become the same after rounding rules are applied. Possible values: *

    *