ICU 66.0.1  66.0.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 
15 #ifndef U_HIDE_DRAFT_API
16 
21 U_NAMESPACE_BEGIN
22 class CharString;
23 
63 public:
71  LocaleBuilder();
72 
77  virtual ~LocaleBuilder();
78 
91  LocaleBuilder& setLocale(const Locale& locale);
92 
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 
282 #ifndef U_HIDE_DRAFT_API
283 
292  UBool copyErrorTo(UErrorCode &outErrorCode) const;
293 #endif /* U_HIDE_DRAFT_API */
294 
295 private:
296  friend class LocaleMatcher::Result;
297 
298  void copyExtensionsFrom(const Locale& src, UErrorCode& errorCode);
299 
300  UErrorCode status_;
301  char language_[9];
302  char script_[5];
303  char region_[4];
304  CharString *variant_; // Pointer not object so we need not #include internal charstr.h.
305  icu::Locale *extensions_; // Pointer not object. Storage for all other fields.
306 
307 };
308 
309 U_NAMESPACE_END
310 
311 #endif // U_HIDE_DRAFT_API
312 
313 #endif /* U_SHOW_CPLUSPLUS_API */
314 
315 #endif // __LOCALEBUILDER_H__
C++ API: Locale matcher: User's desired locales vs.
LocaleBuilder is used to build instances of Locale from values configured by the setters.
Definition: localebuilder.h:62
C++ API: StringPiece: Read-only byte string wrapper class.
Data for the best-matching pair of a desired and a supported locale.
C++ API: Common ICU base class UObject.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
C++ API: Locale ID object.
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:300
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195