36 #if U_SHOW_CPLUSPLUS_API
39 #include <string_view>
280 const char* country =
nullptr,
281 const char* variant =
nullptr,
282 const char* keywordsAndValues =
nullptr);
359 #ifndef U_HIDE_SYSTEM_API
440 template<
typename StringClass>
441 inline StringClass toLanguageTag(
UErrorCode& status)
const;
454 #ifndef U_HIDE_INTERNAL_API
621 template<
typename StringClass,
typename OutputIterator>
622 inline void getKeywords(OutputIterator iterator,
UErrorCode& status)
const;
635 template<
typename StringClass,
typename OutputIterator>
636 inline void getUnicodeKeywords(OutputIterator iterator,
UErrorCode& status)
const;
656 int32_t bufferCapacity,
687 template<
typename StringClass>
720 template<
typename StringClass>
743 const char* keywordValue,
1057 template<
typename Iter>
1093 template<
typename Iter,
typename Conv>
1107 it_(begin), end_(end), converter_(converter) {}
1128 #ifndef U_HIDE_INTERNAL_API
1153 Locale& init(
const char* localeID,
UBool canonicalize);
1161 enum ELocaleType : uint8_t {
1171 static Locale* getLocaleCache();
1181 static constexpr
size_t SIZE = 32;
1183 ELocaleType type = eNEST;
1187 uint8_t variantBegin;
1188 char baseName[SIZE -
1193 sizeof variantBegin];
1195 const char* getLanguage()
const {
return language; }
1196 const char* getScript()
const {
return script; }
1197 const char* getRegion()
const {
return region; }
1198 const char* getVariant()
const {
return variantBegin == 0 ?
"" : getBaseName() + variantBegin; }
1199 const char* getBaseName()
const {
return baseName; }
1202 static void* U_EXPORT2
operator new(size_t) noexcept =
delete;
1203 static void* U_EXPORT2
operator new[](size_t) noexcept =
delete;
1205 Nest() : language{
'\0'}, script{
'\0'}, region{
'\0'}, variantBegin{0}, baseName{
'\0'} {}
1207 void init(std::string_view language,
1208 std::string_view script,
1209 std::string_view region,
1210 uint8_t variantBegin);
1212 static bool fits(int32_t length,
1213 std::string_view language,
1214 std::string_view script,
1215 std::string_view region) {
1216 return length < static_cast<int32_t>(
sizeof Nest::baseName) &&
1217 language.size() <
sizeof Nest::language &&
1218 script.size() <
sizeof Nest::script &&
1219 region.size() <
sizeof Nest::region;
1223 friend union Payload;
1224 Nest(Heap&& heap, uint8_t variantBegin);
1226 static_assert(
sizeof(Nest) == Nest::SIZE);
1240 const char* getLanguage()
const {
return language; }
1241 const char* getScript()
const {
return script; }
1242 const char* getRegion()
const {
return region; }
1243 const char* getVariant()
const;
1244 const char* getFullName()
const;
1245 const char* getBaseName()
const;
1248 static void* U_EXPORT2
operator new(size_t) noexcept =
delete;
1249 static void* U_EXPORT2
operator new[](size_t) noexcept =
delete;
1251 Heap(std::string_view language,
1252 std::string_view script,
1253 std::string_view region,
1254 int32_t variantBegin);
1257 Heap& operator=(
const Heap& other);
1258 Heap& operator=(Heap&& other) noexcept;
1260 static_assert(
sizeof(Heap) <=
sizeof(Nest));
1272 void copy(
const Payload& other);
1273 void move(Payload&& other) noexcept;
1277 static void* U_EXPORT2
operator new(size_t) noexcept =
delete;
1278 static void* U_EXPORT2
operator new[](size_t) noexcept =
delete;
1280 Payload() : type{eBOGUS} {}
1283 Payload(
const Payload& other);
1284 Payload(Payload&& other) noexcept;
1286 Payload& operator=(
const Payload& other);
1287 Payload& operator=(Payload&& other) noexcept;
1290 bool isBogus()
const {
return type == eBOGUS; }
1292 template <
typename T,
typename... Args> T& emplace(Args&&... args);
1294 template <
typename T> T* get();
1296 template <
typename BogusFn,
typename NestFn,
typename HeapFn,
typename... Args>
1297 auto visit(BogusFn bogusFn, NestFn nestFn, HeapFn heapFn, Args... args)
const;
1308 template <
const char* (Nest::*
const NEST)() const,
1309 const
char* (Heap::*const HEAP)() const>
1310 const
char* getField() const;
1312 static const Locale &getLocale(
int locid);
1330 template<
typename StringClass>
inline StringClass
1336 toLanguageTag(sink, status);
1340 template<
typename StringClass,
typename OutputIterator>
inline void
1349 int32_t resultLength;
1350 const char* buffer = keys->next(&resultLength, status);
1351 if (
U_FAILURE(status) || buffer ==
nullptr) {
1354 *iterator++ = StringClass(buffer, resultLength);
1358 template<
typename StringClass,
typename OutputIterator>
inline void
1367 int32_t resultLength;
1368 const char* buffer = keys->next(&resultLength, status);
1369 if (
U_FAILURE(status) || buffer ==
nullptr) {
1372 *iterator++ = StringClass(buffer, resultLength);
1376 template<
typename StringClass>
inline StringClass
1382 getKeywordValue(keywordName, sink, status);
1386 template<
typename StringClass>
inline StringClass
1392 getUnicodeKeywordValue(keywordName, sink, status);
1398 return payload.isBogus();
C++ API: Interface for writing bytes, and implementation classes.
A ByteSink can be filled with bytes.
UBool isNull() const
nullptr check.
"Smart pointer" class, deletes objects via the standard C++ delete operator.
A generic Locale iterator implementation over Locale input iterators.
UBool hasNext() const override
ConvertingIterator(Iter begin, Iter end, Conv converter)
Constructs an iterator from a begin/end range.
const Locale & next() override
A Locale iterator interface similar to a Java Iterator<Locale>.
virtual UBool hasNext() const =0
virtual const Locale & next()=0
A generic Locale iterator implementation over Locale input iterators.
RangeIterator(Iter begin, Iter end)
Constructs an iterator from a begin/end range.
UBool hasNext() const override
const Locale & next() override
A Locale object represents a specific geographical, political, or cultural region.
static U_COMMON_API const Locale & getJapan()
Useful constant for this country/region.
U_COMMON_API const char * getLanguage() const
Returns the locale's ISO-639 language code.
static U_COMMON_API Locale forLanguageTag(StringPiece tag, UErrorCode &status)
Returns a Locale for the specified BCP47 language tag string.
U_COMMON_API UBool isBogus() const
Gets the bogus state.
static U_COMMON_API const Locale & getUS()
Useful constant for this country/region.
U_COMMON_API int32_t getKeywordValue(const char *keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const
Gets the value for a keyword.
U_COMMON_API void getUnicodeKeywordValue(StringPiece keywordName, ByteSink &sink, UErrorCode &status) const
Gets the Unicode value for a Unicode keyword.
U_COMMON_API UnicodeString & getDisplayName(UnicodeString &name) const
Fills in "name" with the name of this locale in a format suitable for user display in the default loc...
U_COMMON_API void minimizeSubtags(bool favorScript, UErrorCode &status)
Minimize the subtags for this Locale, per the algorithm described.
U_COMMON_API Locale * clone() const
Clone this object.
static U_COMMON_API const Locale & getCanadaFrench()
Useful constant for this country/region.
static U_COMMON_API Locale createFromName(StringPiece name)
U_COMMON_API void toLanguageTag(ByteSink &sink, UErrorCode &status) const
Returns a well-formed language tag for this Locale.
static U_COMMON_API const char *const * getISOCountries()
Gets a list of all available 2-letter country codes defined in ISO 3166.
static U_COMMON_API const Locale & getJapanese()
Useful constant for this language.
static U_COMMON_API const Locale & getItalian()
Useful constant for this language.
U_COMMON_API UnicodeString & getDisplayVariant(UnicodeString &dispVar) const
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display ...
U_COMMON_API StringEnumeration * createUnicodeKeywords(UErrorCode &status) const
Gets the list of Unicode keywords for the specified locale.
static U_COMMON_API const Locale & getItaly()
Useful constant for this country/region.
static U_COMMON_API const Locale & getPRC()
Useful constant for this country/region.
U_COMMON_API const char * getISO3Language() const
returns the locale's three-letter language code, as specified in ISO draft standard ISO-639-2.
static U_COMMON_API const char *const * getISOLanguages()
Returns a list of all unique language codes defined in ISO 639.
static U_COMMON_API Locale createCanonical(const char *name)
Creates a locale from the given string after canonicalizing the string according to CLDR by calling u...
static U_COMMON_API const Locale & getChinese()
Useful constant for this language.
U_COMMON_API int32_t hashCode() const
Generates a hash code for the locale.
U_COMMON_API Locale(const char *language, const char *country=nullptr, const char *variant=nullptr, const char *keywordsAndValues=nullptr)
Construct a locale from language, country, variant.
U_COMMON_API void minimizeSubtags(UErrorCode &status)
Minimize the subtags for this Locale, per the algorithm described in the following CLDR technical rep...
static U_COMMON_API const Locale & getFrance()
Useful constant for this country/region.
static U_COMMON_API const Locale & getGerman()
Useful constant for this language.
static U_COMMON_API const Locale * getAvailableLocales(int32_t &count)
Returns a list of all installed locales.
U_COMMON_API Locale()
Construct a default locale object, a Locale for the default locale ID.
static U_COMMON_API UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
U_COMMON_API UnicodeString & getDisplayCountry(const Locale &displayLocale, UnicodeString &dispCountry) const
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display i...
U_COMMON_API const char * getISO3Country() const
Fills in "name" with the locale's three-letter ISO-3166 country code.
U_COMMON_API UnicodeString & getDisplayScript(UnicodeString &dispScript) const
Fills in "dispScript" with the name of this locale's script in a format suitable for user display in ...
static U_COMMON_API const Locale & getFrench()
Useful constant for this language.
U_COMMON_API UnicodeString & getDisplayLanguage(UnicodeString &dispLang) const
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in ...
U_COMMON_API void setFromPOSIXID(const char *posixID)
Set this from a single POSIX style locale string.
U_COMMON_API void getKeywordValue(StringPiece keywordName, ByteSink &sink, UErrorCode &status) const
Gets the value for a keyword.
U_COMMON_API bool operator==(const Locale &other) const
Checks if two locale keys are the same.
U_COMMON_API const char * getName() const
Returns the programmatic name of the entire locale, with the language, country and variant separated ...
void getUnicodeKeywords(OutputIterator iterator, UErrorCode &status) const
Gets the set of Unicode keywords for this Locale.
U_COMMON_API Locale & operator=(const Locale &other)
Replaces the entire contents of *this with the specified value.
static U_COMMON_API const Locale & getEnglish()
Useful constant for this language.
static U_COMMON_API const Locale & getRoot()
Useful constant for the Root locale.
static U_COMMON_API const Locale & getUK()
Useful constant for this country/region.
U_COMMON_API uint32_t getLCID() const
Returns the Windows LCID value corresponding to this locale.
U_COMMON_API StringEnumeration * createKeywords(UErrorCode &status) const
Gets the list of keywords for the specified locale.
U_COMMON_API UnicodeString & getDisplayScript(const Locale &displayLocale, UnicodeString &dispScript) const
Fills in "dispScript" with the name of this locale's country in a format suitable for user display in...
U_COMMON_API Locale(Locale &&other) noexcept
Move constructor; might leave source in bogus state.
static U_COMMON_API const Locale & getCanada()
Useful constant for this country/region.
U_COMMON_API UnicodeString & getDisplayCountry(UnicodeString &dispCountry) const
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display i...
static U_COMMON_API const Locale & getGermany()
Useful constant for this country/region.
U_COMMON_API UnicodeString & getDisplayVariant(const Locale &displayLocale, UnicodeString &dispVar) const
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display ...
U_COMMON_API void setKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode &status)
Sets or removes the value for a keyword.
static U_COMMON_API const Locale & getDefault()
Common methods of getting the current default Locale.
U_COMMON_API UnicodeString & getDisplayLanguage(const Locale &displayLocale, UnicodeString &dispLang) const
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in ...
static U_COMMON_API const Locale & getTraditionalChinese()
Useful constant for this language.
U_COMMON_API const char * getBaseName() const
Returns the programmatic name of the entire locale as getName() would return, but without keywords.
U_COMMON_API Locale & operator=(Locale &&other) noexcept
Move assignment operator; might leave source in bogus state.
U_COMMON_API void canonicalize(UErrorCode &status)
Canonicalize the locale ID of this object according to CLDR.
void getKeywords(OutputIterator iterator, UErrorCode &status) const
Gets the set of keywords for this Locale.
U_COMMON_API void setToBogus()
Sets the locale to bogus A bogus locale represents a non-existing locale associated with services tha...
static U_COMMON_API const Locale & getChina()
Useful constant for this country/region.
static U_COMMON_API const Locale & getSimplifiedChinese()
Useful constant for this language.
U_COMMON_API Locale(const Locale &other)
Initializes a Locale object from another Locale object.
static U_COMMON_API void setDefault(const Locale &newLocale, UErrorCode &success)
Sets the default.
static U_COMMON_API const Locale & getKorea()
Useful constant for this country/region.
static U_COMMON_API const Locale & getTaiwan()
Useful constant for this country/region.
U_COMMON_API UBool isRightToLeft() const
Returns whether this locale's script is written right-to-left.
virtual U_COMMON_API UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
U_COMMON_API void addLikelySubtags(UErrorCode &status)
Add the likely subtags for this Locale, per the algorithm described in the following CLDR technical r...
U_COMMON_API void setKeywordValue(const char *keywordName, const char *keywordValue, UErrorCode &status)
Sets or removes the value for a keyword.
U_COMMON_API UnicodeString & getDisplayName(const Locale &displayLocale, UnicodeString &name) const
Fills in "name" with the name of this locale in a format suitable for user display in the locale spec...
virtual U_COMMON_API ~Locale()
Destructor.
U_COMMON_API void setUnicodeKeywordValue(StringPiece keywordName, StringPiece keywordValue, UErrorCode &status)
Sets or removes the Unicode value for a Unicode keyword.
U_COMMON_API const char * getCountry() const
Returns the locale's ISO-3166 country code.
U_COMMON_API const char * getScript() const
Returns the locale's ISO-15924 abbreviation script code.
static U_COMMON_API Locale createFromName(const char *name)
Creates a locale which has had minimal canonicalization as per uloc_getName().
U_COMMON_API const char * getVariant() const
Returns the locale's variant code.
static U_COMMON_API const Locale & getKorean()
Useful constant for this language.
Implementation of ByteSink that writes to a "string".
Base class for 'pure' C++ implementations of uenum api.
A string-like object that points to a sized piece of memory.
UMemory is the common ICU base class.
UObject is the common ICU "boilerplate" class.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void locale_available_init()
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
C API: Platform Utilities.
C++ API: String Enumeration.
C++ API: StringPiece: Read-only byte string wrapper class.
C API: Locale ID functionality similar to C++ class Locale.
#define ULOC_SCRIPT_CAPACITY
Useful constant for the maximum size of the script part of a locale ID (including the terminating NUL...
#define ULOC_COUNTRY_CAPACITY
Useful constant for the maximum size of the country part of a locale ID (including the terminating NU...
#define ULOC_LANG_CAPACITY
Useful constant for the maximum size of the language part of a locale ID.
int8_t UBool
The ICU boolean type, a signed-byte integer.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
#define U_FAILURE(x)
Does the error code indicate a failure?
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
#define U_COMMON_API_CLASS
Set to export library symbols from inside the common library, and to import them from outside,...