ICU 67.1  67.1
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#License
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 
62 public:
70  LocaleBuilder();
71 
76  virtual ~LocaleBuilder();
77 
90  LocaleBuilder& setLocale(const Locale& locale);
91 
108  LocaleBuilder& setLanguageTag(StringPiece tag);
109 
123  LocaleBuilder& setLanguage(StringPiece language);
124 
139  LocaleBuilder& setScript(StringPiece script);
140 
158  LocaleBuilder& setRegion(StringPiece region);
159 
179  LocaleBuilder& setVariant(StringPiece variant);
180 
200  LocaleBuilder& setExtension(char key, StringPiece value);
201 
220  LocaleBuilder& setUnicodeLocaleKeyword(
221  StringPiece key, StringPiece type);
222 
233  LocaleBuilder& addUnicodeLocaleAttribute(StringPiece attribute);
234 
246  LocaleBuilder& removeUnicodeLocaleAttribute(StringPiece attribute);
247 
255  LocaleBuilder& clear();
256 
264  LocaleBuilder& clearExtensions();
265 
279  Locale build(UErrorCode& status);
280 
281 #ifndef U_HIDE_DRAFT_API
282 
291  UBool copyErrorTo(UErrorCode &outErrorCode) const;
292 #endif /* U_HIDE_DRAFT_API */
293 
294 private:
295  friend class LocaleMatcher::Result;
296 
297  void copyExtensionsFrom(const Locale& src, UErrorCode& errorCode);
298 
299  UErrorCode status_;
300  char language_[9];
301  char script_[5];
302  char region_[4];
303  CharString *variant_; // Pointer not object so we need not #include internal charstr.h.
304  icu::Locale *extensions_; // Pointer not object. Storage for all other fields.
305 
306 };
307 
308 U_NAMESPACE_END
309 
310 #endif /* U_SHOW_CPLUSPLUS_API */
311 
312 #endif // __LOCALEBUILDER_H__
icu::LocaleBuilder
LocaleBuilder is used to build instances of Locale from values configured by the setters.
Definition: localebuilder.h:61
icu::LocaleMatcher::Result
Data for the best-matching pair of a desired and a supported locale.
Definition: localematcher.h:194
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
U_COMMON_API
#define U_COMMON_API
Definition: utypes.h:300
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
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
localematcher.h
C++ API: Locale matcher: User's desired locales vs. application's supported locales.
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::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195