ICU4C 79
Loading...
Searching...
No Matches
localebuilder.h
Go to the documentation of this file.
1// © 2018 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3#ifndef __LOCALEBUILDER_H__
4#define __LOCALEBUILDER_H__
5
6#include "unicode/utypes.h"
7
8#if U_SHOW_CPLUSPLUS_API
9
10#include "unicode/locid.h"
12#include "unicode/stringpiece.h"
13#include "unicode/uobject.h"
14
19
20U_NAMESPACE_BEGIN
21class FixedString;
22
62public:
71
76 virtual ~LocaleBuilder();
77
90 LocaleBuilder& setLocale(const Locale& locale) U_LIFETIME_BOUND;
91
108
122 LocaleBuilder& setLanguage(StringPiece language) U_LIFETIME_BOUND;
123
138 LocaleBuilder& setScript(StringPiece script) U_LIFETIME_BOUND;
139
157 LocaleBuilder& setRegion(StringPiece region) U_LIFETIME_BOUND;
158
178 LocaleBuilder& setVariant(StringPiece variant) U_LIFETIME_BOUND;
179
199 LocaleBuilder& setExtension(char key, StringPiece value) U_LIFETIME_BOUND;
200
220
232
245
253 LocaleBuilder& clear() U_LIFETIME_BOUND;
254
262 LocaleBuilder& clearExtensions() U_LIFETIME_BOUND;
263
278
288 UBool copyErrorTo(UErrorCode &outErrorCode) const;
289
290private:
291 friend class LocaleMatcher::Result;
292
293 void copyExtensionsFrom(const Locale& src, UErrorCode& errorCode);
294
295 UErrorCode status_;
296 char language_[9];
297 char script_[5];
298 char region_[4];
299 FixedString *variant_; // Pointer not object so we need not #include internal fixedstring.h.
300 icu::Locale *extensions_; // Pointer not object. Storage for all other fields.
301
302};
303
304U_NAMESPACE_END
305
306#endif /* U_SHOW_CPLUSPLUS_API */
307
308#endif // __LOCALEBUILDER_H__
LocaleBuilder & setLanguageTag(StringPiece tag)
Resets the LocaleBuilder to match the provided IETF BCP 47 language tag.
LocaleBuilder & setScript(StringPiece script)
Sets the script.
LocaleBuilder & setUnicodeLocaleKeyword(StringPiece key, StringPiece type)
Sets the Unicode locale keyword type for the given key.
LocaleBuilder & setExtension(char key, StringPiece value)
Sets the extension for the given key.
Locale build(UErrorCode &status)
Returns an instance of Locale created from the fields set on this builder.
LocaleBuilder & clear()
Resets the builder to its initial, empty state.
LocaleBuilder & setLocale(const Locale &locale)
Resets the LocaleBuilder to match the provided locale.
UBool copyErrorTo(UErrorCode &outErrorCode) const
Sets the UErrorCode if an error occurred while recording sets.
virtual ~LocaleBuilder()
Destructor.
LocaleBuilder & addUnicodeLocaleAttribute(StringPiece attribute)
Adds a unicode locale attribute, if not already present, otherwise has no effect.
LocaleBuilder()
Constructs an empty LocaleBuilder.
LocaleBuilder & removeUnicodeLocaleAttribute(StringPiece attribute)
Removes a unicode locale attribute, if present, otherwise has no effect.
LocaleBuilder & setVariant(StringPiece variant)
Sets the variant.
LocaleBuilder & setLanguage(StringPiece language)
Sets the language.
LocaleBuilder & clearExtensions()
Resets the extensions to their initial, empty state.
LocaleBuilder & setRegion(StringPiece region)
Sets the region.
Immutable class that picks the best match between a user's desired locales and an application's suppo...
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
A string-like object that points to a sized piece of memory.
Definition stringpiece.h:61
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
C++ API: Locale matcher: User's desired locales vs.
C++ API: Locale ID object.
File coll.h.
Definition brkiter.h:59
C++ API: StringPiece: Read-only byte string wrapper class.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
C++ API: Common ICU base class UObject.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:315