localebuilder.h
Go to the documentation of this file.
// © 2018 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#ifndef __LOCALEBUILDER_H__
#define __LOCALEBUILDER_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#include "unicode/locid.h"
#include "unicode/localematcher.h"
#include "unicode/stringpiece.h"
#include "unicode/uobject.h"
U_NAMESPACE_BEGIN
class CharString;
class U_COMMON_API LocaleBuilder : public UObject {
public:
LocaleBuilder();
virtual ~LocaleBuilder();
LocaleBuilder& setLocale(const Locale& locale);
LocaleBuilder& setLanguageTag(StringPiece tag);
LocaleBuilder& setLanguage(StringPiece language);
LocaleBuilder& setScript(StringPiece script);
LocaleBuilder& setRegion(StringPiece region);
LocaleBuilder& setVariant(StringPiece variant);
LocaleBuilder& setExtension(char key, StringPiece value);
LocaleBuilder& setUnicodeLocaleKeyword(
StringPiece key, StringPiece type);
LocaleBuilder& addUnicodeLocaleAttribute(StringPiece attribute);
LocaleBuilder& removeUnicodeLocaleAttribute(StringPiece attribute);
LocaleBuilder& clear();
LocaleBuilder& clearExtensions();
Locale build(UErrorCode& status);
UBool copyErrorTo(UErrorCode &outErrorCode) const;
private:
friend class LocaleMatcher::Result;
void copyExtensionsFrom(const Locale& src, UErrorCode& errorCode);
UErrorCode status_;
char language_[9];
char script_[5];
char region_[4];
CharString *variant_; // Pointer not object so we need not #include internal charstr.h.
icu::Locale *extensions_; // Pointer not object. Storage for all other fields.
};
U_NAMESPACE_END
#endif /* U_SHOW_CPLUSPLUS_API */
#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::setLanguageTag
LocaleBuilder & setLanguageTag(StringPiece tag)
Resets the LocaleBuilder to match the provided IETF BCP 47 language tag.
icu::LocaleBuilder::setVariant
LocaleBuilder & setVariant(StringPiece variant)
Sets the variant.
icu::LocaleBuilder::setLanguage
LocaleBuilder & setLanguage(StringPiece language)
Sets the language.
icu::LocaleBuilder::build
Locale build(UErrorCode &status)
Returns an instance of Locale created from the fields set on this builder.
icu::LocaleBuilder::addUnicodeLocaleAttribute
LocaleBuilder & addUnicodeLocaleAttribute(StringPiece attribute)
Adds a unicode locale attribute, if not already present, otherwise has no effect.
icu::LocaleBuilder::clearExtensions
LocaleBuilder & clearExtensions()
Resets the extensions to their initial, empty state.
icu::LocaleBuilder::setLocale
LocaleBuilder & setLocale(const Locale &locale)
Resets the LocaleBuilder to match the provided locale.
icu::LocaleBuilder::setRegion
LocaleBuilder & setRegion(StringPiece region)
Sets the region.
icu::LocaleBuilder::removeUnicodeLocaleAttribute
LocaleBuilder & removeUnicodeLocaleAttribute(StringPiece attribute)
Removes a unicode locale attribute, if present, otherwise has no effect.
icu::LocaleBuilder::setExtension
LocaleBuilder & setExtension(char key, StringPiece value)
Sets the extension for the given key.
icu::LocaleBuilder::copyErrorTo
UBool copyErrorTo(UErrorCode &outErrorCode) const
Sets the UErrorCode if an error occurred while recording sets.
icu::LocaleBuilder::clear
LocaleBuilder & clear()
Resets the builder to its initial, empty state.
icu::LocaleBuilder::~LocaleBuilder
virtual ~LocaleBuilder()
Destructor.
icu::LocaleBuilder::LocaleBuilder
LocaleBuilder()
Constructs an empty LocaleBuilder.
icu::LocaleBuilder::setScript
LocaleBuilder & setScript(StringPiece script)
Sets the script.
icu::LocaleBuilder::setUnicodeLocaleKeyword
LocaleBuilder & setUnicodeLocaleKeyword(StringPiece key, StringPiece type)
Sets the Unicode locale keyword type for the given key.
icu::LocaleMatcher::Result
Data for the best-matching pair of a desired and a supported locale.
Definition: localematcher.h:192
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
localematcher.h
C++ API: Locale matcher: User's desired locales vs.
locid.h
C++ API: Locale ID object.
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
uobject.h
C++ API: Common ICU base class UObject.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
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