// © 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" /** * \file * \brief C++ API: Builder API for Locale */ U_NAMESPACE_BEGIN class CharString; /** * <code>LocaleBuilder</code> is used to build instances of <code>Locale</code> * from values configured by the setters. Unlike the <code>Locale</code> * constructors, the <code>LocaleBuilder</code> checks if a value configured by a * setter satisfies the syntax requirements defined by the <code>Locale</code> * class. A <code>Locale</code> object created by a <code>LocaleBuilder</code> is * well-formed and can be transformed to a well-formed IETF BCP 47 language tag * without losing information. * * <p>The following example shows how to create a <code>Locale</code> object * with the <code>LocaleBuilder</code>. * <blockquote> * <pre> * UErrorCode status = U_ZERO_ERROR; * Locale aLocale = LocaleBuilder() * .setLanguage("sr") * .setScript("Latn") * .setRegion("RS") * .build(status); * if (U_SUCCESS(status)) { * // ... * } * </pre> * </blockquote> * * <p>LocaleBuilders can be reused; <code>clear()</code> resets all * fields to their default values. * * <p>LocaleBuilder tracks errors in an internal UErrorCode. For all setters, * except setLanguageTag and setLocale, LocaleBuilder will return immediately * if the internal UErrorCode is in error state. * To reset internal state and error code, call clear method. * The setLanguageTag and setLocale method will first clear the internal * UErrorCode, then track the error of the validation of the input parameter * into the internal UErrorCode. * * @stable ICU 64 */ class U_COMMON_API LocaleBuilder : public UObject { … }; U_NAMESPACE_END #endif /* U_SHOW_CPLUSPLUS_API */ #endif // __LOCALEBUILDER_H__