1*0e209d39SAndroid Build Coastguard Worker // © 2023 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker #ifndef __ULOCBUILDER_H__ 4*0e209d39SAndroid Build Coastguard Worker #define __ULOCBUILDER_H__ 5*0e209d39SAndroid Build Coastguard Worker 6*0e209d39SAndroid Build Coastguard Worker #include "unicode/localpointer.h" 7*0e209d39SAndroid Build Coastguard Worker #include "unicode/ulocale.h" 8*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 9*0e209d39SAndroid Build Coastguard Worker 10*0e209d39SAndroid Build Coastguard Worker /** 11*0e209d39SAndroid Build Coastguard Worker * \file 12*0e209d39SAndroid Build Coastguard Worker * \brief C API: Builder API for Locale 13*0e209d39SAndroid Build Coastguard Worker */ 14*0e209d39SAndroid Build Coastguard Worker 15*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DRAFT_API 16*0e209d39SAndroid Build Coastguard Worker 17*0e209d39SAndroid Build Coastguard Worker /** 18*0e209d39SAndroid Build Coastguard Worker * Opaque C service object type for the locale builder API 19*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 20*0e209d39SAndroid Build Coastguard Worker */ 21*0e209d39SAndroid Build Coastguard Worker struct ULocaleBuilder; 22*0e209d39SAndroid Build Coastguard Worker 23*0e209d39SAndroid Build Coastguard Worker /** 24*0e209d39SAndroid Build Coastguard Worker * C typedef for struct ULocaleBuilder. 25*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 26*0e209d39SAndroid Build Coastguard Worker */ 27*0e209d39SAndroid Build Coastguard Worker typedef struct ULocaleBuilder ULocaleBuilder; 28*0e209d39SAndroid Build Coastguard Worker 29*0e209d39SAndroid Build Coastguard Worker /** 30*0e209d39SAndroid Build Coastguard Worker * <code>ULocaleBuilder</code> is used to build valid <code>locale</code> id 31*0e209d39SAndroid Build Coastguard Worker * string or IETF BCP 47 language tag from values configured by the setters. 32*0e209d39SAndroid Build Coastguard Worker * The <code>ULocaleBuilder</code> checks if a value configured by a 33*0e209d39SAndroid Build Coastguard Worker * setter satisfies the syntax requirements defined by the <code>Locale</code> 34*0e209d39SAndroid Build Coastguard Worker * class. A string of Locale created by a <code>ULocaleBuilder</code> is 35*0e209d39SAndroid Build Coastguard Worker * well-formed and can be transformed to a well-formed IETF BCP 47 language tag 36*0e209d39SAndroid Build Coastguard Worker * without losing information. 37*0e209d39SAndroid Build Coastguard Worker * 38*0e209d39SAndroid Build Coastguard Worker * <p>The following example shows how to create a <code>locale</code> string 39*0e209d39SAndroid Build Coastguard Worker * with the <code>ULocaleBuilder</code>. 40*0e209d39SAndroid Build Coastguard Worker * <blockquote> 41*0e209d39SAndroid Build Coastguard Worker * <pre> 42*0e209d39SAndroid Build Coastguard Worker * UErrorCode err = U_ZERO_ERROR; 43*0e209d39SAndroid Build Coastguard Worker * char buffer[ULOC_FULLNAME_CAPACITY]; 44*0e209d39SAndroid Build Coastguard Worker * ULocaleBuilder* builder = ulocbld_open(); 45*0e209d39SAndroid Build Coastguard Worker * ulocbld_setLanguage(builder, "sr", -1); 46*0e209d39SAndroid Build Coastguard Worker * ulocbld_setScript(builder, "Latn", -1); 47*0e209d39SAndroid Build Coastguard Worker * ulocbld_setRegion(builder, "RS", -1); 48*0e209d39SAndroid Build Coastguard Worker * int32_t length = ulocbld_buildLocaleID( 49*0e209d39SAndroid Build Coastguard Worker * builder, buffer, ULOC_FULLNAME_CAPACITY, &error); 50*0e209d39SAndroid Build Coastguard Worker * ulocbld_close(builder); 51*0e209d39SAndroid Build Coastguard Worker * </pre> 52*0e209d39SAndroid Build Coastguard Worker * </blockquote> 53*0e209d39SAndroid Build Coastguard Worker * 54*0e209d39SAndroid Build Coastguard Worker * <p>ULocaleBuilders can be reused; <code>ulocbld_clear()</code> resets all 55*0e209d39SAndroid Build Coastguard Worker * fields to their default values. 56*0e209d39SAndroid Build Coastguard Worker * 57*0e209d39SAndroid Build Coastguard Worker * <p>ULocaleBuilder tracks errors in an internal UErrorCode. For all setters, 58*0e209d39SAndroid Build Coastguard Worker * except ulocbld_setLanguageTag and ulocbld_setLocale, ULocaleBuilder will return immediately 59*0e209d39SAndroid Build Coastguard Worker * if the internal UErrorCode is in error state. 60*0e209d39SAndroid Build Coastguard Worker * To reset internal state and error code, call clear method. 61*0e209d39SAndroid Build Coastguard Worker * The ulocbld_setLanguageTag and setLocale method will first clear the internal 62*0e209d39SAndroid Build Coastguard Worker * UErrorCode, then track the error of the validation of the input parameter 63*0e209d39SAndroid Build Coastguard Worker * into the internal UErrorCode. 64*0e209d39SAndroid Build Coastguard Worker * 65*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 66*0e209d39SAndroid Build Coastguard Worker */ 67*0e209d39SAndroid Build Coastguard Worker 68*0e209d39SAndroid Build Coastguard Worker /** 69*0e209d39SAndroid Build Coastguard Worker * Constructs an empty ULocaleBuilder. The default value of all 70*0e209d39SAndroid Build Coastguard Worker * fields, extensions, and private use information is the 71*0e209d39SAndroid Build Coastguard Worker * empty string. The created builder should be destroyed by calling 72*0e209d39SAndroid Build Coastguard Worker * ulocbld_close(); 73*0e209d39SAndroid Build Coastguard Worker * 74*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 75*0e209d39SAndroid Build Coastguard Worker */ 76*0e209d39SAndroid Build Coastguard Worker U_CAPI ULocaleBuilder* U_EXPORT2 77*0e209d39SAndroid Build Coastguard Worker ulocbld_open(void); 78*0e209d39SAndroid Build Coastguard Worker 79*0e209d39SAndroid Build Coastguard Worker /** 80*0e209d39SAndroid Build Coastguard Worker * Close the builder and destroy it's internal states. 81*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 82*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 83*0e209d39SAndroid Build Coastguard Worker */ 84*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 85*0e209d39SAndroid Build Coastguard Worker ulocbld_close(ULocaleBuilder* builder); 86*0e209d39SAndroid Build Coastguard Worker 87*0e209d39SAndroid Build Coastguard Worker /** 88*0e209d39SAndroid Build Coastguard Worker * Resets the <code>ULocaleBuilder</code> to match the provided 89*0e209d39SAndroid Build Coastguard Worker * <code>locale</code>. Existing state is discarded. 90*0e209d39SAndroid Build Coastguard Worker * 91*0e209d39SAndroid Build Coastguard Worker * <p>All fields of the locale must be well-formed. 92*0e209d39SAndroid Build Coastguard Worker * <p>This method clears the internal UErrorCode. 93*0e209d39SAndroid Build Coastguard Worker * 94*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 95*0e209d39SAndroid Build Coastguard Worker * @param locale the locale, a const char * pointer (need not be terminated when 96*0e209d39SAndroid Build Coastguard Worker * the length is non-negative) 97*0e209d39SAndroid Build Coastguard Worker * @param length the length of the locale; if negative, then the locale need to be 98*0e209d39SAndroid Build Coastguard Worker * null terminated, 99*0e209d39SAndroid Build Coastguard Worker * 100*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 101*0e209d39SAndroid Build Coastguard Worker */ 102*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 103*0e209d39SAndroid Build Coastguard Worker ulocbld_setLocale(ULocaleBuilder* builder, const char* locale, int32_t length); 104*0e209d39SAndroid Build Coastguard Worker 105*0e209d39SAndroid Build Coastguard Worker /** 106*0e209d39SAndroid Build Coastguard Worker * Resets the <code>ULocaleBuilder</code> to match the provided 107*0e209d39SAndroid Build Coastguard Worker * <code>ULocale</code>. Existing state is discarded. 108*0e209d39SAndroid Build Coastguard Worker * 109*0e209d39SAndroid Build Coastguard Worker * <p>The locale must be not bogus. 110*0e209d39SAndroid Build Coastguard Worker * <p>This method clears the internal UErrorCode. 111*0e209d39SAndroid Build Coastguard Worker * 112*0e209d39SAndroid Build Coastguard Worker * @param builder the builder. 113*0e209d39SAndroid Build Coastguard Worker * @param locale the locale, a ULocale* pointer. The builder adopts the locale 114*0e209d39SAndroid Build Coastguard Worker * after the call and the client must not delete it. 115*0e209d39SAndroid Build Coastguard Worker * 116*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 117*0e209d39SAndroid Build Coastguard Worker */ 118*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 119*0e209d39SAndroid Build Coastguard Worker ulocbld_adoptULocale(ULocaleBuilder* builder, ULocale* locale); 120*0e209d39SAndroid Build Coastguard Worker 121*0e209d39SAndroid Build Coastguard Worker /** 122*0e209d39SAndroid Build Coastguard Worker * Resets the ULocaleBuilder to match the provided IETF BCP 47 language tag. 123*0e209d39SAndroid Build Coastguard Worker * Discards the existing state. 124*0e209d39SAndroid Build Coastguard Worker * The empty string causes the builder to be reset, like {@link #ulocbld_clear}. 125*0e209d39SAndroid Build Coastguard Worker * Legacy language tags (marked as “Type: grandfathered” in BCP 47) 126*0e209d39SAndroid Build Coastguard Worker * are converted to their canonical form before being processed. 127*0e209d39SAndroid Build Coastguard Worker * Otherwise, the <code>language tag</code> must be well-formed, 128*0e209d39SAndroid Build Coastguard Worker * or else the ulocbld_buildLocaleID() and ulocbld_buildLanguageTag() methods 129*0e209d39SAndroid Build Coastguard Worker * will later report an U_ILLEGAL_ARGUMENT_ERROR. 130*0e209d39SAndroid Build Coastguard Worker * 131*0e209d39SAndroid Build Coastguard Worker * <p>This method clears the internal UErrorCode. 132*0e209d39SAndroid Build Coastguard Worker * 133*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 134*0e209d39SAndroid Build Coastguard Worker * @param tag the language tag, defined as IETF BCP 47 language tag, a 135*0e209d39SAndroid Build Coastguard Worker * const char * pointer (need not be terminated when 136*0e209d39SAndroid Build Coastguard Worker * the length is non-negative) 137*0e209d39SAndroid Build Coastguard Worker * @param length the length of the tag; if negative, then the tag need to be 138*0e209d39SAndroid Build Coastguard Worker * null terminated, 139*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 140*0e209d39SAndroid Build Coastguard Worker */ 141*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 142*0e209d39SAndroid Build Coastguard Worker ulocbld_setLanguageTag(ULocaleBuilder* builder, const char* tag, int32_t length); 143*0e209d39SAndroid Build Coastguard Worker 144*0e209d39SAndroid Build Coastguard Worker /** 145*0e209d39SAndroid Build Coastguard Worker * Sets the language. If <code>language</code> is the empty string, the 146*0e209d39SAndroid Build Coastguard Worker * language in this <code>ULocaleBuilder</code> is removed. Otherwise, the 147*0e209d39SAndroid Build Coastguard Worker * <code>language</code> must be well-formed, or else the ulocbld_buildLocaleID() 148*0e209d39SAndroid Build Coastguard Worker * and ulocbld_buildLanguageTag() methods will 149*0e209d39SAndroid Build Coastguard Worker * later report an U_ILLEGAL_ARGUMENT_ERROR. 150*0e209d39SAndroid Build Coastguard Worker * 151*0e209d39SAndroid Build Coastguard Worker * <p>The syntax of language value is defined as 152*0e209d39SAndroid Build Coastguard Worker * [unicode_language_subtag](http://www.unicode.org/reports/tr35/tr35.html#unicode_language_subtag). 153*0e209d39SAndroid Build Coastguard Worker * 154*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 155*0e209d39SAndroid Build Coastguard Worker * @param language the language, a const char * pointer (need not be terminated when 156*0e209d39SAndroid Build Coastguard Worker * the length is non-negative) 157*0e209d39SAndroid Build Coastguard Worker * @param length the length of the language; if negative, then the language need to be 158*0e209d39SAndroid Build Coastguard Worker * null terminated, 159*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 160*0e209d39SAndroid Build Coastguard Worker */ 161*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 162*0e209d39SAndroid Build Coastguard Worker ulocbld_setLanguage(ULocaleBuilder* builder, const char* language, int32_t length); 163*0e209d39SAndroid Build Coastguard Worker 164*0e209d39SAndroid Build Coastguard Worker /** 165*0e209d39SAndroid Build Coastguard Worker * Sets the script. If <code>script</code> is the empty string, the script in 166*0e209d39SAndroid Build Coastguard Worker * this <code>ULocaleBuilder</code> is removed. 167*0e209d39SAndroid Build Coastguard Worker * Otherwise, the <code>script</code> must be well-formed, or else the 168*0e209d39SAndroid Build Coastguard Worker * ulocbld_buildLocaleID() and ulocbld_buildLanguageTag() methods will later 169*0e209d39SAndroid Build Coastguard Worker * report an U_ILLEGAL_ARGUMENT_ERROR. 170*0e209d39SAndroid Build Coastguard Worker * 171*0e209d39SAndroid Build Coastguard Worker * <p>The script value is a four-letter script code as 172*0e209d39SAndroid Build Coastguard Worker * [unicode_script_subtag](http://www.unicode.org/reports/tr35/tr35.html#unicode_script_subtag) 173*0e209d39SAndroid Build Coastguard Worker * defined by ISO 15924 174*0e209d39SAndroid Build Coastguard Worker * 175*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 176*0e209d39SAndroid Build Coastguard Worker * @param script the script, a const char * pointer (need not be terminated when 177*0e209d39SAndroid Build Coastguard Worker * the length is non-negative) 178*0e209d39SAndroid Build Coastguard Worker * @param length the length of the script; if negative, then the script need to be 179*0e209d39SAndroid Build Coastguard Worker * null terminated, 180*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 181*0e209d39SAndroid Build Coastguard Worker */ 182*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 183*0e209d39SAndroid Build Coastguard Worker ulocbld_setScript(ULocaleBuilder* builder, const char* script, int32_t length); 184*0e209d39SAndroid Build Coastguard Worker 185*0e209d39SAndroid Build Coastguard Worker /** 186*0e209d39SAndroid Build Coastguard Worker * Sets the region. If region is the empty string, the region in this 187*0e209d39SAndroid Build Coastguard Worker * <code>ULocaleBuilder</code> is removed. Otherwise, the <code>region</code> 188*0e209d39SAndroid Build Coastguard Worker * must be well-formed, or else the ulocbld_buildLocaleID() and 189*0e209d39SAndroid Build Coastguard Worker * ulocbld_buildLanguageTag() methods will later report an 190*0e209d39SAndroid Build Coastguard Worker * U_ILLEGAL_ARGUMENT_ERROR. 191*0e209d39SAndroid Build Coastguard Worker * 192*0e209d39SAndroid Build Coastguard Worker * <p>The region value is defined by 193*0e209d39SAndroid Build Coastguard Worker * [unicode_region_subtag](http://www.unicode.org/reports/tr35/tr35.html#unicode_region_subtag) 194*0e209d39SAndroid Build Coastguard Worker * as a two-letter ISO 3166 code or a three-digit UN M.49 area code. 195*0e209d39SAndroid Build Coastguard Worker * 196*0e209d39SAndroid Build Coastguard Worker * <p>The region value in the <code>Locale</code> created by the 197*0e209d39SAndroid Build Coastguard Worker * <code>ULocaleBuilder</code> is always normalized to upper case. 198*0e209d39SAndroid Build Coastguard Worker * 199*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 200*0e209d39SAndroid Build Coastguard Worker * @param region the region, a const char * pointer (need not be terminated when 201*0e209d39SAndroid Build Coastguard Worker * the length is non-negative) 202*0e209d39SAndroid Build Coastguard Worker * @param length the length of the region; if negative, then the region need to be 203*0e209d39SAndroid Build Coastguard Worker * null terminated, 204*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 205*0e209d39SAndroid Build Coastguard Worker */ 206*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 207*0e209d39SAndroid Build Coastguard Worker ulocbld_setRegion(ULocaleBuilder* builder, const char* region, int32_t length); 208*0e209d39SAndroid Build Coastguard Worker 209*0e209d39SAndroid Build Coastguard Worker /** 210*0e209d39SAndroid Build Coastguard Worker * Sets the variant. If variant is the empty string, the variant in this 211*0e209d39SAndroid Build Coastguard Worker * <code>ULocaleBuilder</code> is removed. Otherwise, the <code>variant</code> 212*0e209d39SAndroid Build Coastguard Worker * must be well-formed, or else the ulocbld_buildLocaleID() and 213*0e209d39SAndroid Build Coastguard Worker * ulocbld_buildLanguageTag() methods will later report an 214*0e209d39SAndroid Build Coastguard Worker * U_ILLEGAL_ARGUMENT_ERROR. 215*0e209d39SAndroid Build Coastguard Worker * 216*0e209d39SAndroid Build Coastguard Worker * <p><b>Note:</b> This method checks if <code>variant</code> 217*0e209d39SAndroid Build Coastguard Worker * satisfies the 218*0e209d39SAndroid Build Coastguard Worker * [unicode_variant_subtag](http://www.unicode.org/reports/tr35/tr35.html#unicode_variant_subtag) 219*0e209d39SAndroid Build Coastguard Worker * syntax requirements, and normalizes the value to lowercase letters. However, 220*0e209d39SAndroid Build Coastguard Worker * the <code>Locale</code> class does not impose any syntactic 221*0e209d39SAndroid Build Coastguard Worker * restriction on variant. To set an ill-formed variant, use a Locale constructor. 222*0e209d39SAndroid Build Coastguard Worker * If there are multiple unicode_variant_subtag, the caller must concatenate 223*0e209d39SAndroid Build Coastguard Worker * them with '-' as separator (ex: "foobar-fibar"). 224*0e209d39SAndroid Build Coastguard Worker * 225*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 226*0e209d39SAndroid Build Coastguard Worker * @param variant the variant, a const char * pointer (need not be terminated when 227*0e209d39SAndroid Build Coastguard Worker * the length is non-negative) 228*0e209d39SAndroid Build Coastguard Worker * @param length the length of the variant; if negative, then the variant need to be 229*0e209d39SAndroid Build Coastguard Worker * null terminated, 230*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 231*0e209d39SAndroid Build Coastguard Worker */ 232*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 233*0e209d39SAndroid Build Coastguard Worker ulocbld_setVariant(ULocaleBuilder* builder, const char* variant, int32_t length); 234*0e209d39SAndroid Build Coastguard Worker 235*0e209d39SAndroid Build Coastguard Worker /** 236*0e209d39SAndroid Build Coastguard Worker * Sets the extension for the given key. If the value is the empty string, 237*0e209d39SAndroid Build Coastguard Worker * the extension is removed. Otherwise, the <code>key</code> and 238*0e209d39SAndroid Build Coastguard Worker * <code>value</code> must be well-formed, or else the ulocbld_buildLocaleID() 239*0e209d39SAndroid Build Coastguard Worker * and ulocbld_buildLanguageTag() methods will 240*0e209d39SAndroid Build Coastguard Worker * later report an U_ILLEGAL_ARGUMENT_ERROR. 241*0e209d39SAndroid Build Coastguard Worker * 242*0e209d39SAndroid Build Coastguard Worker * <p><b>Note:</b> The key ('u') is used for the Unicode locale extension. 243*0e209d39SAndroid Build Coastguard Worker * Setting a value for this key replaces any existing Unicode locale key/type 244*0e209d39SAndroid Build Coastguard Worker * pairs with those defined in the extension. 245*0e209d39SAndroid Build Coastguard Worker * 246*0e209d39SAndroid Build Coastguard Worker * <p><b>Note:</b> The key ('x') is used for the private use code. To be 247*0e209d39SAndroid Build Coastguard Worker * well-formed, the value for this key needs only to have subtags of one to 248*0e209d39SAndroid Build Coastguard Worker * eight alphanumeric characters, not two to eight as in the general case. 249*0e209d39SAndroid Build Coastguard Worker * 250*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 251*0e209d39SAndroid Build Coastguard Worker * @param key the extension key 252*0e209d39SAndroid Build Coastguard Worker * @param value the value, a const char * pointer (need not be terminated when 253*0e209d39SAndroid Build Coastguard Worker * the length is non-negative) 254*0e209d39SAndroid Build Coastguard Worker * @param length the length of the value; if negative, then the value need to be 255*0e209d39SAndroid Build Coastguard Worker * null terminated, 256*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 257*0e209d39SAndroid Build Coastguard Worker */ 258*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 259*0e209d39SAndroid Build Coastguard Worker ulocbld_setExtension(ULocaleBuilder* builder, char key, const char* value, int32_t length); 260*0e209d39SAndroid Build Coastguard Worker 261*0e209d39SAndroid Build Coastguard Worker /** 262*0e209d39SAndroid Build Coastguard Worker * Sets the Unicode locale keyword type for the given key. If the type 263*0e209d39SAndroid Build Coastguard Worker * StringPiece is constructed with a nullptr, the keyword is removed. 264*0e209d39SAndroid Build Coastguard Worker * If the type is the empty string, the keyword is set without type subtags. 265*0e209d39SAndroid Build Coastguard Worker * Otherwise, the key and type must be well-formed, or else the 266*0e209d39SAndroid Build Coastguard Worker * ulocbld_buildLocaleID() and ulocbld_buildLanguageTag() methods will later 267*0e209d39SAndroid Build Coastguard Worker * report an U_ILLEGAL_ARGUMENT_ERROR. 268*0e209d39SAndroid Build Coastguard Worker * 269*0e209d39SAndroid Build Coastguard Worker * <p>Keys and types are converted to lower case. 270*0e209d39SAndroid Build Coastguard Worker * 271*0e209d39SAndroid Build Coastguard Worker * <p><b>Note</b>:Setting the 'u' extension via {@link #ulocbld_setExtension} 272*0e209d39SAndroid Build Coastguard Worker * replaces all Unicode locale keywords with those defined in the 273*0e209d39SAndroid Build Coastguard Worker * extension. 274*0e209d39SAndroid Build Coastguard Worker * 275*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 276*0e209d39SAndroid Build Coastguard Worker * @param key the Unicode locale key, a const char * pointer (need not be 277*0e209d39SAndroid Build Coastguard Worker * terminated when the length is non-negative) 278*0e209d39SAndroid Build Coastguard Worker * @param keyLength the length of the key; if negative, then the key need to be 279*0e209d39SAndroid Build Coastguard Worker * null terminated, 280*0e209d39SAndroid Build Coastguard Worker * @param type the Unicode locale type, a const char * pointer (need not be 281*0e209d39SAndroid Build Coastguard Worker * terminated when the length is non-negative) 282*0e209d39SAndroid Build Coastguard Worker * @param typeLength the length of the type; if negative, then the type need to 283*0e209d39SAndroid Build Coastguard Worker * be null terminated, 284*0e209d39SAndroid Build Coastguard Worker * @return This builder. 285*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 286*0e209d39SAndroid Build Coastguard Worker */ 287*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 288*0e209d39SAndroid Build Coastguard Worker ulocbld_setUnicodeLocaleKeyword(ULocaleBuilder* builder, 289*0e209d39SAndroid Build Coastguard Worker const char* key, int32_t keyLength, const char* type, int32_t typeLength); 290*0e209d39SAndroid Build Coastguard Worker 291*0e209d39SAndroid Build Coastguard Worker /** 292*0e209d39SAndroid Build Coastguard Worker * Adds a unicode locale attribute, if not already present, otherwise 293*0e209d39SAndroid Build Coastguard Worker * has no effect. The attribute must not be empty string and must be 294*0e209d39SAndroid Build Coastguard Worker * well-formed or U_ILLEGAL_ARGUMENT_ERROR will be set to status 295*0e209d39SAndroid Build Coastguard Worker * during the ulocbld_buildLocaleID() and ulocbld_buildLanguageTag() calls. 296*0e209d39SAndroid Build Coastguard Worker * 297*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 298*0e209d39SAndroid Build Coastguard Worker * @param attribute the attribute, a const char * pointer (need not be 299*0e209d39SAndroid Build Coastguard Worker * terminated when the length is non-negative) 300*0e209d39SAndroid Build Coastguard Worker * @param length the length of the attribute; if negative, then the attribute 301*0e209d39SAndroid Build Coastguard Worker * need to be null terminated, 302*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 303*0e209d39SAndroid Build Coastguard Worker */ 304*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 305*0e209d39SAndroid Build Coastguard Worker ulocbld_addUnicodeLocaleAttribute( 306*0e209d39SAndroid Build Coastguard Worker ULocaleBuilder* builder, const char* attribute, int32_t length); 307*0e209d39SAndroid Build Coastguard Worker 308*0e209d39SAndroid Build Coastguard Worker /** 309*0e209d39SAndroid Build Coastguard Worker * Removes a unicode locale attribute, if present, otherwise has no 310*0e209d39SAndroid Build Coastguard Worker * effect. The attribute must not be empty string and must be well-formed 311*0e209d39SAndroid Build Coastguard Worker * or U_ILLEGAL_ARGUMENT_ERROR will be set to status during the ulocbld_buildLocaleID() 312*0e209d39SAndroid Build Coastguard Worker * and ulocbld_buildLanguageTag() calls. 313*0e209d39SAndroid Build Coastguard Worker * 314*0e209d39SAndroid Build Coastguard Worker * <p>Attribute comparison for removal is case-insensitive. 315*0e209d39SAndroid Build Coastguard Worker * 316*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 317*0e209d39SAndroid Build Coastguard Worker * @param attribute the attribute, a const char * pointer (need not be 318*0e209d39SAndroid Build Coastguard Worker * terminated when the length is non-negative) 319*0e209d39SAndroid Build Coastguard Worker * @param length the length of the attribute; if negative, then the attribute 320*0e209d39SAndroid Build Coastguard Worker * need to be null terminated, 321*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 322*0e209d39SAndroid Build Coastguard Worker */ 323*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 324*0e209d39SAndroid Build Coastguard Worker ulocbld_removeUnicodeLocaleAttribute( 325*0e209d39SAndroid Build Coastguard Worker ULocaleBuilder* builder, const char* attribute, int32_t length); 326*0e209d39SAndroid Build Coastguard Worker 327*0e209d39SAndroid Build Coastguard Worker /** 328*0e209d39SAndroid Build Coastguard Worker * Resets the builder to its initial, empty state. 329*0e209d39SAndroid Build Coastguard Worker * <p>This method clears the internal UErrorCode. 330*0e209d39SAndroid Build Coastguard Worker * 331*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 332*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 333*0e209d39SAndroid Build Coastguard Worker */ 334*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 335*0e209d39SAndroid Build Coastguard Worker ulocbld_clear(ULocaleBuilder* builder); 336*0e209d39SAndroid Build Coastguard Worker 337*0e209d39SAndroid Build Coastguard Worker /** 338*0e209d39SAndroid Build Coastguard Worker * Resets the extensions to their initial, empty state. 339*0e209d39SAndroid Build Coastguard Worker * Language, script, region and variant are unchanged. 340*0e209d39SAndroid Build Coastguard Worker * 341*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 342*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 343*0e209d39SAndroid Build Coastguard Worker */ 344*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 345*0e209d39SAndroid Build Coastguard Worker ulocbld_clearExtensions(ULocaleBuilder* builder); 346*0e209d39SAndroid Build Coastguard Worker 347*0e209d39SAndroid Build Coastguard Worker /** 348*0e209d39SAndroid Build Coastguard Worker * Build the LocaleID string from the fields set on this builder. 349*0e209d39SAndroid Build Coastguard Worker * If any set methods or during the ulocbld_buildLocaleID() call require memory 350*0e209d39SAndroid Build Coastguard Worker * allocation but fail U_MEMORY_ALLOCATION_ERROR will be set to status. 351*0e209d39SAndroid Build Coastguard Worker * If any of the fields set by the setters are not well-formed, the status 352*0e209d39SAndroid Build Coastguard Worker * will be set to U_ILLEGAL_ARGUMENT_ERROR. The state of the builder will 353*0e209d39SAndroid Build Coastguard Worker * not change after the ulocbld_buildLocaleID() call and the caller is 354*0e209d39SAndroid Build Coastguard Worker * free to keep using the same builder to build more locales. 355*0e209d39SAndroid Build Coastguard Worker * 356*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 357*0e209d39SAndroid Build Coastguard Worker * @param locale the locale id 358*0e209d39SAndroid Build Coastguard Worker * @param localeCapacity the size of the locale buffer to store the locale id 359*0e209d39SAndroid Build Coastguard Worker * @param err the error code 360*0e209d39SAndroid Build Coastguard Worker * @return the length of the locale id in buffer 361*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 362*0e209d39SAndroid Build Coastguard Worker */ 363*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 364*0e209d39SAndroid Build Coastguard Worker ulocbld_buildLocaleID(ULocaleBuilder* builder, char* locale, 365*0e209d39SAndroid Build Coastguard Worker int32_t localeCapacity, UErrorCode* err); 366*0e209d39SAndroid Build Coastguard Worker 367*0e209d39SAndroid Build Coastguard Worker /** 368*0e209d39SAndroid Build Coastguard Worker * Build the ULocale object from the fields set on this builder. 369*0e209d39SAndroid Build Coastguard Worker * If any set methods or during the ulocbld_buildULocale() call require memory 370*0e209d39SAndroid Build Coastguard Worker * allocation but fail U_MEMORY_ALLOCATION_ERROR will be set to status. 371*0e209d39SAndroid Build Coastguard Worker * If any of the fields set by the setters are not well-formed, the status 372*0e209d39SAndroid Build Coastguard Worker * will be set to U_ILLEGAL_ARGUMENT_ERROR. The state of the builder will 373*0e209d39SAndroid Build Coastguard Worker * not change after the ulocbld_buildULocale() call and the caller is 374*0e209d39SAndroid Build Coastguard Worker * free to keep using the same builder to build more locales. 375*0e209d39SAndroid Build Coastguard Worker * 376*0e209d39SAndroid Build Coastguard Worker * @param builder the builder. 377*0e209d39SAndroid Build Coastguard Worker * @param err the error code. 378*0e209d39SAndroid Build Coastguard Worker * @return the locale, a ULocale* pointer. The created ULocale must be 379*0e209d39SAndroid Build Coastguard Worker * destroyed by calling {@link ulocale_close}. 380*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 381*0e209d39SAndroid Build Coastguard Worker */ 382*0e209d39SAndroid Build Coastguard Worker U_CAPI ULocale* U_EXPORT2 383*0e209d39SAndroid Build Coastguard Worker ulocbld_buildULocale(ULocaleBuilder* builder, UErrorCode* err); 384*0e209d39SAndroid Build Coastguard Worker 385*0e209d39SAndroid Build Coastguard Worker /** 386*0e209d39SAndroid Build Coastguard Worker * Build the IETF BCP 47 language tag string from the fields set on this builder. 387*0e209d39SAndroid Build Coastguard Worker * If any set methods or during the ulocbld_buildLanguageTag() call require memory 388*0e209d39SAndroid Build Coastguard Worker * allocation but fail U_MEMORY_ALLOCATION_ERROR will be set to status. 389*0e209d39SAndroid Build Coastguard Worker * If any of the fields set by the setters are not well-formed, the status 390*0e209d39SAndroid Build Coastguard Worker * will be set to U_ILLEGAL_ARGUMENT_ERROR. The state of the builder will 391*0e209d39SAndroid Build Coastguard Worker * not change after the ulocbld_buildLanguageTag() call and the caller is free 392*0e209d39SAndroid Build Coastguard Worker * to keep using the same builder to build more locales. 393*0e209d39SAndroid Build Coastguard Worker * 394*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 395*0e209d39SAndroid Build Coastguard Worker * @param language the language tag 396*0e209d39SAndroid Build Coastguard Worker * @param languageCapacity the size of the language buffer to store the language 397*0e209d39SAndroid Build Coastguard Worker * tag 398*0e209d39SAndroid Build Coastguard Worker * @param err the error code 399*0e209d39SAndroid Build Coastguard Worker * @return the length of the language tag in buffer 400*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 401*0e209d39SAndroid Build Coastguard Worker */ 402*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 403*0e209d39SAndroid Build Coastguard Worker ulocbld_buildLanguageTag(ULocaleBuilder* builder, char* language, 404*0e209d39SAndroid Build Coastguard Worker int32_t languageCapacity, UErrorCode* err); 405*0e209d39SAndroid Build Coastguard Worker 406*0e209d39SAndroid Build Coastguard Worker /** 407*0e209d39SAndroid Build Coastguard Worker * Sets the UErrorCode if an error occurred while recording sets. 408*0e209d39SAndroid Build Coastguard Worker * Preserves older error codes in the outErrorCode. 409*0e209d39SAndroid Build Coastguard Worker * 410*0e209d39SAndroid Build Coastguard Worker * @param builder the builder 411*0e209d39SAndroid Build Coastguard Worker * @param outErrorCode Set to an error code that occurred while setting subtags. 412*0e209d39SAndroid Build Coastguard Worker * Unchanged if there is no such error or if outErrorCode 413*0e209d39SAndroid Build Coastguard Worker * already contained an error. 414*0e209d39SAndroid Build Coastguard Worker * @return true if U_FAILURE(*outErrorCode) 415*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 416*0e209d39SAndroid Build Coastguard Worker */ 417*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 418*0e209d39SAndroid Build Coastguard Worker ulocbld_copyErrorTo(const ULocaleBuilder* builder, UErrorCode *outErrorCode); 419*0e209d39SAndroid Build Coastguard Worker 420*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 421*0e209d39SAndroid Build Coastguard Worker 422*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 423*0e209d39SAndroid Build Coastguard Worker 424*0e209d39SAndroid Build Coastguard Worker /** 425*0e209d39SAndroid Build Coastguard Worker * \class LocalULocaleBuilderPointer 426*0e209d39SAndroid Build Coastguard Worker * "Smart pointer" class, closes a ULocaleBuilder via ulocbld_close(). 427*0e209d39SAndroid Build Coastguard Worker * For most methods see the LocalPointerBase base class. 428*0e209d39SAndroid Build Coastguard Worker * 429*0e209d39SAndroid Build Coastguard Worker * @see LocalPointerBase 430*0e209d39SAndroid Build Coastguard Worker * @see LocalPointer 431*0e209d39SAndroid Build Coastguard Worker * @draft ICU 74 432*0e209d39SAndroid Build Coastguard Worker */ 433*0e209d39SAndroid Build Coastguard Worker U_DEFINE_LOCAL_OPEN_POINTER(LocalULocaleBuilderPointer, ULocaleBuilder, ulocbld_close); 434*0e209d39SAndroid Build Coastguard Worker 435*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 436*0e209d39SAndroid Build Coastguard Worker 437*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */ 438*0e209d39SAndroid Build Coastguard Worker 439*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DRAFT_API */ 440*0e209d39SAndroid Build Coastguard Worker 441*0e209d39SAndroid Build Coastguard Worker #endif // __ULOCBUILDER_H__ 442