ICU 68.2: localebuilder.h Source File

ICU 68.2 68.2

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"
11 #include "unicode/localematcher.h"
12 #include "unicode/stringpiece.h"
13 #include "unicode/uobject.h"
14
20 U_NAMESPACE_BEGIN
21 class CharString;
22
61 class U_COMMON_API LocaleBuilder : public UObject {
62 public:
70 LocaleBuilder();
71
76 virtual ~LocaleBuilder();
77
90 LocaleBuilder& setLocale(const Locale& locale);
91
109 LocaleBuilder& setLanguageTag(StringPiece tag);
110
124 LocaleBuilder& setLanguage(StringPiece language);
125
140 LocaleBuilder& setScript(StringPiece script);
141
159 LocaleBuilder& setRegion(StringPiece region);
160
180 LocaleBuilder& setVariant(StringPiece variant);
181
201 LocaleBuilder& setExtension(char key, StringPiece value);
202
221 LocaleBuilder& setUnicodeLocaleKeyword(
222 StringPiece key, StringPiece type);
223
234 LocaleBuilder& addUnicodeLocaleAttribute(StringPiece attribute);
235
247 LocaleBuilder& removeUnicodeLocaleAttribute(StringPiece attribute);
248
256 LocaleBuilder& clear();
257
265 LocaleBuilder& clearExtensions();
266
280 Locale build(UErrorCode& status);
281
291 UBool copyErrorTo(UErrorCode &outErrorCode) const;
292
293 private:
294 friend class LocaleMatcher::Result;
295
296 void copyExtensionsFrom(const Locale& src, UErrorCode& errorCode);
297
298 UErrorCode status_;
299 char language_[9];
300 char script_[5];
301 char region_[4];
302 CharString *variant_; // Pointer not object so we need not #include internal charstr.h.
303 icu::Locale *extensions_; // Pointer not object. Storage for all other fields.
304
305 };
306
307 U_NAMESPACE_END
308
309 #endif /* U_SHOW_CPLUSPLUS_API */
310
311 #endif // __LOCALEBUILDER_H__
icu::LocaleBuilder
LocaleBuilder is used to build instances of Locale from values configured by the setters.
Definition: localebuilder.h:61
icu::LocaleBuilder::LocaleBuilder
LocaleBuilder()
Constructs an empty LocaleBuilder.
icu::LocaleMatcher::Result
Data for the best-matching pair of a desired and a supported locale.
Definition: localematcher.h:196
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:300
icu::LocaleBuilder::setLanguage
LocaleBuilder & setLanguage(StringPiece language)
Sets the language.
icu::LocaleBuilder::setUnicodeLocaleKeyword
LocaleBuilder & setUnicodeLocaleKeyword(StringPiece key, StringPiece type)
Sets the Unicode locale keyword type for the given key.
icu::LocaleBuilder::setLanguageTag
LocaleBuilder & setLanguageTag(StringPiece tag)
Resets the LocaleBuilder to match the provided Unicode Locale Identifier .
icu::LocaleBuilder::copyErrorTo
UBool copyErrorTo(UErrorCode &outErrorCode) const
Sets the UErrorCode if an error occurred while recording sets.
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
icu::LocaleBuilder::setRegion
LocaleBuilder & setRegion(StringPiece region)
Sets the region.
icu::LocaleBuilder::setScript
LocaleBuilder & setScript(StringPiece script)
Sets the script.
icu::LocaleBuilder::setExtension
LocaleBuilder & setExtension(char key, StringPiece value)
Sets the extension for the given key.
icu::LocaleBuilder::~LocaleBuilder
virtual ~LocaleBuilder()
Destructor.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::LocaleBuilder::addUnicodeLocaleAttribute
LocaleBuilder & addUnicodeLocaleAttribute(StringPiece attribute)
Adds a unicode locale attribute, if not already present, otherwise has no effect.
localematcher.h
C++ API: Locale matcher: User's desired locales vs.
icu::LocaleBuilder::setVariant
LocaleBuilder & setVariant(StringPiece variant)
Sets the variant.
icu::LocaleBuilder::clear
LocaleBuilder & clear()
Resets the builder to its initial, empty state.
icu::LocaleBuilder::setLocale
LocaleBuilder & setLocale(const Locale &locale)
Resets the LocaleBuilder to match the provided locale.
icu::LocaleBuilder::clearExtensions
LocaleBuilder & clearExtensions()
Resets the extensions to their initial, empty state.
icu::LocaleBuilder::removeUnicodeLocaleAttribute
LocaleBuilder & removeUnicodeLocaleAttribute(StringPiece attribute)
Removes a unicode locale attribute, if present, otherwise has no effect.
locid.h
C++ API: Locale ID object.
uobject.h
C++ API: Common ICU base class UObject.
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
icu::LocaleBuilder::build
Locale build(UErrorCode &status)
Returns an instance of Locale created from the fields set on this builder.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195