1*0e209d39SAndroid Build Coastguard Worker // © 2016 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 /******************************************************************** 4*0e209d39SAndroid Build Coastguard Worker * COPYRIGHT: 5*0e209d39SAndroid Build Coastguard Worker * Copyright (c) 1997-2011, International Business Machines Corporation and 6*0e209d39SAndroid Build Coastguard Worker * others. All Rights Reserved. 7*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2010 , Yahoo! Inc. 8*0e209d39SAndroid Build Coastguard Worker ******************************************************************** 9*0e209d39SAndroid Build Coastguard Worker * 10*0e209d39SAndroid Build Coastguard Worker * File SELFMT.H 11*0e209d39SAndroid Build Coastguard Worker * 12*0e209d39SAndroid Build Coastguard Worker * Modification History: 13*0e209d39SAndroid Build Coastguard Worker * 14*0e209d39SAndroid Build Coastguard Worker * Date Name Description 15*0e209d39SAndroid Build Coastguard Worker * 11/11/09 kirtig Finished first cut of implementation. 16*0e209d39SAndroid Build Coastguard Worker ********************************************************************/ 17*0e209d39SAndroid Build Coastguard Worker 18*0e209d39SAndroid Build Coastguard Worker #ifndef SELFMT 19*0e209d39SAndroid Build Coastguard Worker #define SELFMT 20*0e209d39SAndroid Build Coastguard Worker 21*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 22*0e209d39SAndroid Build Coastguard Worker 23*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 24*0e209d39SAndroid Build Coastguard Worker 25*0e209d39SAndroid Build Coastguard Worker #include "unicode/messagepattern.h" 26*0e209d39SAndroid Build Coastguard Worker #include "unicode/numfmt.h" 27*0e209d39SAndroid Build Coastguard Worker 28*0e209d39SAndroid Build Coastguard Worker /** 29*0e209d39SAndroid Build Coastguard Worker * \file 30*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: SelectFormat object 31*0e209d39SAndroid Build Coastguard Worker */ 32*0e209d39SAndroid Build Coastguard Worker 33*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING 34*0e209d39SAndroid Build Coastguard Worker 35*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 36*0e209d39SAndroid Build Coastguard Worker 37*0e209d39SAndroid Build Coastguard Worker class MessageFormat; 38*0e209d39SAndroid Build Coastguard Worker 39*0e209d39SAndroid Build Coastguard Worker /** 40*0e209d39SAndroid Build Coastguard Worker * <p><code>SelectFormat</code> supports the creation of internationalized 41*0e209d39SAndroid Build Coastguard Worker * messages by selecting phrases based on keywords. The pattern specifies 42*0e209d39SAndroid Build Coastguard Worker * how to map keywords to phrases and provides a default phrase. The 43*0e209d39SAndroid Build Coastguard Worker * object provided to the format method is a string that's matched 44*0e209d39SAndroid Build Coastguard Worker * against the keywords. If there is a match, the corresponding phrase 45*0e209d39SAndroid Build Coastguard Worker * is selected; otherwise, the default phrase is used.</p> 46*0e209d39SAndroid Build Coastguard Worker * 47*0e209d39SAndroid Build Coastguard Worker * <h4>Using <code>SelectFormat</code> for Gender Agreement</h4> 48*0e209d39SAndroid Build Coastguard Worker * 49*0e209d39SAndroid Build Coastguard Worker * <p>Note: Typically, select formatting is done via <code>MessageFormat</code> 50*0e209d39SAndroid Build Coastguard Worker * with a <code>select</code> argument type, 51*0e209d39SAndroid Build Coastguard Worker * rather than using a stand-alone <code>SelectFormat</code>.</p> 52*0e209d39SAndroid Build Coastguard Worker * 53*0e209d39SAndroid Build Coastguard Worker * <p>The main use case for the select format is gender based inflection. 54*0e209d39SAndroid Build Coastguard Worker * When names or nouns are inserted into sentences, their gender can affect pronouns, 55*0e209d39SAndroid Build Coastguard Worker * verb forms, articles, and adjectives. Special care needs to be 56*0e209d39SAndroid Build Coastguard Worker * taken for the case where the gender cannot be determined. 57*0e209d39SAndroid Build Coastguard Worker * The impact varies between languages:</p> 58*0e209d39SAndroid Build Coastguard Worker * \htmlonly 59*0e209d39SAndroid Build Coastguard Worker * <ul> 60*0e209d39SAndroid Build Coastguard Worker * <li>English has three genders, and unknown gender is handled as a special 61*0e209d39SAndroid Build Coastguard Worker * case. Names use the gender of the named person (if known), nouns referring 62*0e209d39SAndroid Build Coastguard Worker * to people use natural gender, and inanimate objects are usually neutral. 63*0e209d39SAndroid Build Coastguard Worker * The gender only affects pronouns: "he", "she", "it", "they". 64*0e209d39SAndroid Build Coastguard Worker * 65*0e209d39SAndroid Build Coastguard Worker * <li>German differs from English in that the gender of nouns is rather 66*0e209d39SAndroid Build Coastguard Worker * arbitrary, even for nouns referring to people ("Mädchen", girl, is neutral). 67*0e209d39SAndroid Build Coastguard Worker * The gender affects pronouns ("er", "sie", "es"), articles ("der", "die", 68*0e209d39SAndroid Build Coastguard Worker * "das"), and adjective forms ("guter Mann", "gute Frau", "gutes Mädchen"). 69*0e209d39SAndroid Build Coastguard Worker * 70*0e209d39SAndroid Build Coastguard Worker * <li>French has only two genders; as in German the gender of nouns 71*0e209d39SAndroid Build Coastguard Worker * is rather arbitrary - for sun and moon, the genders 72*0e209d39SAndroid Build Coastguard Worker * are the opposite of those in German. The gender affects 73*0e209d39SAndroid Build Coastguard Worker * pronouns ("il", "elle"), articles ("le", "la"), 74*0e209d39SAndroid Build Coastguard Worker * adjective forms ("bon", "bonne"), and sometimes 75*0e209d39SAndroid Build Coastguard Worker * verb forms ("allé", "allée"). 76*0e209d39SAndroid Build Coastguard Worker * 77*0e209d39SAndroid Build Coastguard Worker * <li>Polish distinguishes five genders (or noun classes), 78*0e209d39SAndroid Build Coastguard Worker * human masculine, animate non-human masculine, inanimate masculine, 79*0e209d39SAndroid Build Coastguard Worker * feminine, and neuter. 80*0e209d39SAndroid Build Coastguard Worker * </ul> 81*0e209d39SAndroid Build Coastguard Worker * \endhtmlonly 82*0e209d39SAndroid Build Coastguard Worker * <p>Some other languages have noun classes that are not related to gender, 83*0e209d39SAndroid Build Coastguard Worker * but similar in grammatical use. 84*0e209d39SAndroid Build Coastguard Worker * Some African languages have around 20 noun classes.</p> 85*0e209d39SAndroid Build Coastguard Worker * 86*0e209d39SAndroid Build Coastguard Worker * <p><b>Note:</b>For the gender of a <i>person</i> in a given sentence, 87*0e209d39SAndroid Build Coastguard Worker * we usually need to distinguish only between female, male and other/unknown.</p> 88*0e209d39SAndroid Build Coastguard Worker * 89*0e209d39SAndroid Build Coastguard Worker * <p>To enable localizers to create sentence patterns that take their 90*0e209d39SAndroid Build Coastguard Worker * language's gender dependencies into consideration, software has to provide 91*0e209d39SAndroid Build Coastguard Worker * information about the gender associated with a noun or name to 92*0e209d39SAndroid Build Coastguard Worker * <code>MessageFormat</code>. 93*0e209d39SAndroid Build Coastguard Worker * Two main cases can be distinguished:</p> 94*0e209d39SAndroid Build Coastguard Worker * 95*0e209d39SAndroid Build Coastguard Worker * <ul> 96*0e209d39SAndroid Build Coastguard Worker * <li>For people, natural gender information should be maintained for each person. 97*0e209d39SAndroid Build Coastguard Worker * Keywords like "male", "female", "mixed" (for groups of people) 98*0e209d39SAndroid Build Coastguard Worker * and "unknown" could be used. 99*0e209d39SAndroid Build Coastguard Worker * 100*0e209d39SAndroid Build Coastguard Worker * <li>For nouns, grammatical gender information should be maintained for 101*0e209d39SAndroid Build Coastguard Worker * each noun and per language, e.g., in resource bundles. 102*0e209d39SAndroid Build Coastguard Worker * The keywords "masculine", "feminine", and "neuter" are commonly used, 103*0e209d39SAndroid Build Coastguard Worker * but some languages may require other keywords. 104*0e209d39SAndroid Build Coastguard Worker * </ul> 105*0e209d39SAndroid Build Coastguard Worker * 106*0e209d39SAndroid Build Coastguard Worker * <p>The resulting keyword is provided to <code>MessageFormat</code> as a 107*0e209d39SAndroid Build Coastguard Worker * parameter separate from the name or noun it's associated with. For example, 108*0e209d39SAndroid Build Coastguard Worker * to generate a message such as "Jean went to Paris", three separate arguments 109*0e209d39SAndroid Build Coastguard Worker * would be provided: The name of the person as argument 0, the gender of 110*0e209d39SAndroid Build Coastguard Worker * the person as argument 1, and the name of the city as argument 2. 111*0e209d39SAndroid Build Coastguard Worker * The sentence pattern for English, where the gender of the person has 112*0e209d39SAndroid Build Coastguard Worker * no impact on this simple sentence, would not refer to argument 1 at all:</p> 113*0e209d39SAndroid Build Coastguard Worker * 114*0e209d39SAndroid Build Coastguard Worker * <pre>{0} went to {2}.</pre> 115*0e209d39SAndroid Build Coastguard Worker * 116*0e209d39SAndroid Build Coastguard Worker * <p><b>Note:</b> The entire sentence should be included (and partially repeated) 117*0e209d39SAndroid Build Coastguard Worker * inside each phrase. Otherwise translators would have to be trained on how to 118*0e209d39SAndroid Build Coastguard Worker * move bits of the sentence in and out of the select argument of a message. 119*0e209d39SAndroid Build Coastguard Worker * (The examples below do not follow this recommendation!)</p> 120*0e209d39SAndroid Build Coastguard Worker * 121*0e209d39SAndroid Build Coastguard Worker * <p>The sentence pattern for French, where the gender of the person affects 122*0e209d39SAndroid Build Coastguard Worker * the form of the participle, uses a select format based on argument 1:</p> 123*0e209d39SAndroid Build Coastguard Worker * 124*0e209d39SAndroid Build Coastguard Worker * \htmlonly<pre>{0} est {1, select, female {allée} other {allé}} à {2}.</pre>\endhtmlonly 125*0e209d39SAndroid Build Coastguard Worker * 126*0e209d39SAndroid Build Coastguard Worker * <p>Patterns can be nested, so that it's possible to handle interactions of 127*0e209d39SAndroid Build Coastguard Worker * number and gender where necessary. For example, if the above sentence should 128*0e209d39SAndroid Build Coastguard Worker * allow for the names of several people to be inserted, the following sentence 129*0e209d39SAndroid Build Coastguard Worker * pattern can be used (with argument 0 the list of people's names, 130*0e209d39SAndroid Build Coastguard Worker * argument 1 the number of people, argument 2 their combined gender, and 131*0e209d39SAndroid Build Coastguard Worker * argument 3 the city name):</p> 132*0e209d39SAndroid Build Coastguard Worker * 133*0e209d39SAndroid Build Coastguard Worker * \htmlonly 134*0e209d39SAndroid Build Coastguard Worker * <pre>{0} {1, plural, 135*0e209d39SAndroid Build Coastguard Worker * one {est {2, select, female {allée} other {allé}}} 136*0e209d39SAndroid Build Coastguard Worker * other {sont {2, select, female {allées} other {allés}}} 137*0e209d39SAndroid Build Coastguard Worker * }à {3}.</pre> 138*0e209d39SAndroid Build Coastguard Worker * \endhtmlonly 139*0e209d39SAndroid Build Coastguard Worker * 140*0e209d39SAndroid Build Coastguard Worker * <h4>Patterns and Their Interpretation</h4> 141*0e209d39SAndroid Build Coastguard Worker * 142*0e209d39SAndroid Build Coastguard Worker * <p>The <code>SelectFormat</code> pattern string defines the phrase output 143*0e209d39SAndroid Build Coastguard Worker * for each user-defined keyword. 144*0e209d39SAndroid Build Coastguard Worker * The pattern is a sequence of (keyword, message) pairs. 145*0e209d39SAndroid Build Coastguard Worker * A keyword is a "pattern identifier": [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+</p> 146*0e209d39SAndroid Build Coastguard Worker * 147*0e209d39SAndroid Build Coastguard Worker * <p>Each message is a MessageFormat pattern string enclosed in {curly braces}.</p> 148*0e209d39SAndroid Build Coastguard Worker * 149*0e209d39SAndroid Build Coastguard Worker * <p>You always have to define a phrase for the default keyword 150*0e209d39SAndroid Build Coastguard Worker * <code>other</code>; this phrase is returned when the keyword 151*0e209d39SAndroid Build Coastguard Worker * provided to 152*0e209d39SAndroid Build Coastguard Worker * the <code>format</code> method matches no other keyword. 153*0e209d39SAndroid Build Coastguard Worker * If a pattern does not provide a phrase for <code>other</code>, the method 154*0e209d39SAndroid Build Coastguard Worker * it's provided to returns the error <code>U_DEFAULT_KEYWORD_MISSING</code>. 155*0e209d39SAndroid Build Coastguard Worker * <br> 156*0e209d39SAndroid Build Coastguard Worker * Pattern_White_Space between keywords and messages is ignored. 157*0e209d39SAndroid Build Coastguard Worker * Pattern_White_Space within a message is preserved and output.</p> 158*0e209d39SAndroid Build Coastguard Worker * 159*0e209d39SAndroid Build Coastguard Worker * <p><pre>Example: 160*0e209d39SAndroid Build Coastguard Worker * \htmlonly 161*0e209d39SAndroid Build Coastguard Worker * 162*0e209d39SAndroid Build Coastguard Worker * UErrorCode status = U_ZERO_ERROR; 163*0e209d39SAndroid Build Coastguard Worker * MessageFormat *msgFmt = new MessageFormat(UnicodeString("{0} est {1, select, female {allée} other {allé}} à Paris."), Locale("fr"), status); 164*0e209d39SAndroid Build Coastguard Worker * if (U_FAILURE(status)) { 165*0e209d39SAndroid Build Coastguard Worker * return; 166*0e209d39SAndroid Build Coastguard Worker * } 167*0e209d39SAndroid Build Coastguard Worker * FieldPosition ignore(FieldPosition::DONT_CARE); 168*0e209d39SAndroid Build Coastguard Worker * UnicodeString result; 169*0e209d39SAndroid Build Coastguard Worker * 170*0e209d39SAndroid Build Coastguard Worker * char* str1= "Kirti,female"; 171*0e209d39SAndroid Build Coastguard Worker * Formattable args1[] = {"Kirti","female"}; 172*0e209d39SAndroid Build Coastguard Worker * msgFmt->format(args1, 2, result, ignore, status); 173*0e209d39SAndroid Build Coastguard Worker * cout << "Input is " << str1 << " and result is: " << result << endl; 174*0e209d39SAndroid Build Coastguard Worker * delete msgFmt; 175*0e209d39SAndroid Build Coastguard Worker * 176*0e209d39SAndroid Build Coastguard Worker * \endhtmlonly 177*0e209d39SAndroid Build Coastguard Worker * </pre> 178*0e209d39SAndroid Build Coastguard Worker * </p> 179*0e209d39SAndroid Build Coastguard Worker * 180*0e209d39SAndroid Build Coastguard Worker * Produces the output:<br> 181*0e209d39SAndroid Build Coastguard Worker * \htmlonly 182*0e209d39SAndroid Build Coastguard Worker * <code>Kirti est allée à Paris.</code> 183*0e209d39SAndroid Build Coastguard Worker * \endhtmlonly 184*0e209d39SAndroid Build Coastguard Worker * 185*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 186*0e209d39SAndroid Build Coastguard Worker */ 187*0e209d39SAndroid Build Coastguard Worker 188*0e209d39SAndroid Build Coastguard Worker class U_I18N_API SelectFormat : public Format { 189*0e209d39SAndroid Build Coastguard Worker public: 190*0e209d39SAndroid Build Coastguard Worker 191*0e209d39SAndroid Build Coastguard Worker /** 192*0e209d39SAndroid Build Coastguard Worker * Creates a new <code>SelectFormat</code> for a given pattern string. 193*0e209d39SAndroid Build Coastguard Worker * @param pattern the pattern for this <code>SelectFormat</code>. 194*0e209d39SAndroid Build Coastguard Worker * errors are returned to status if the pattern is invalid. 195*0e209d39SAndroid Build Coastguard Worker * @param status output param set to success/failure code on exit, which 196*0e209d39SAndroid Build Coastguard Worker * must not indicate a failure before the function call. 197*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 198*0e209d39SAndroid Build Coastguard Worker */ 199*0e209d39SAndroid Build Coastguard Worker SelectFormat(const UnicodeString& pattern, UErrorCode& status); 200*0e209d39SAndroid Build Coastguard Worker 201*0e209d39SAndroid Build Coastguard Worker /** 202*0e209d39SAndroid Build Coastguard Worker * copy constructor. 203*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 204*0e209d39SAndroid Build Coastguard Worker */ 205*0e209d39SAndroid Build Coastguard Worker SelectFormat(const SelectFormat& other); 206*0e209d39SAndroid Build Coastguard Worker 207*0e209d39SAndroid Build Coastguard Worker /** 208*0e209d39SAndroid Build Coastguard Worker * Destructor. 209*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 210*0e209d39SAndroid Build Coastguard Worker */ 211*0e209d39SAndroid Build Coastguard Worker virtual ~SelectFormat(); 212*0e209d39SAndroid Build Coastguard Worker 213*0e209d39SAndroid Build Coastguard Worker /** 214*0e209d39SAndroid Build Coastguard Worker * Sets the pattern used by this select format. 215*0e209d39SAndroid Build Coastguard Worker * for the keyword rules. 216*0e209d39SAndroid Build Coastguard Worker * Patterns and their interpretation are specified in the class description. 217*0e209d39SAndroid Build Coastguard Worker * 218*0e209d39SAndroid Build Coastguard Worker * @param pattern the pattern for this select format 219*0e209d39SAndroid Build Coastguard Worker * errors are returned to status if the pattern is invalid. 220*0e209d39SAndroid Build Coastguard Worker * @param status output param set to success/failure code on exit, which 221*0e209d39SAndroid Build Coastguard Worker * must not indicate a failure before the function call. 222*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 223*0e209d39SAndroid Build Coastguard Worker */ 224*0e209d39SAndroid Build Coastguard Worker void applyPattern(const UnicodeString& pattern, UErrorCode& status); 225*0e209d39SAndroid Build Coastguard Worker 226*0e209d39SAndroid Build Coastguard Worker 227*0e209d39SAndroid Build Coastguard Worker using Format::format; 228*0e209d39SAndroid Build Coastguard Worker 229*0e209d39SAndroid Build Coastguard Worker /** 230*0e209d39SAndroid Build Coastguard Worker * Selects the phrase for the given keyword 231*0e209d39SAndroid Build Coastguard Worker * 232*0e209d39SAndroid Build Coastguard Worker * @param keyword The keyword that is used to select an alternative. 233*0e209d39SAndroid Build Coastguard Worker * @param appendTo output parameter to receive result. 234*0e209d39SAndroid Build Coastguard Worker * result is appended to existing contents. 235*0e209d39SAndroid Build Coastguard Worker * @param pos On input: an alignment field, if desired. 236*0e209d39SAndroid Build Coastguard Worker * On output: the offsets of the alignment field. 237*0e209d39SAndroid Build Coastguard Worker * @param status output param set to success/failure code on exit, which 238*0e209d39SAndroid Build Coastguard Worker * must not indicate a failure before the function call. 239*0e209d39SAndroid Build Coastguard Worker * @return Reference to 'appendTo' parameter. 240*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 241*0e209d39SAndroid Build Coastguard Worker */ 242*0e209d39SAndroid Build Coastguard Worker UnicodeString& format(const UnicodeString& keyword, 243*0e209d39SAndroid Build Coastguard Worker UnicodeString& appendTo, 244*0e209d39SAndroid Build Coastguard Worker FieldPosition& pos, 245*0e209d39SAndroid Build Coastguard Worker UErrorCode& status) const; 246*0e209d39SAndroid Build Coastguard Worker 247*0e209d39SAndroid Build Coastguard Worker /** 248*0e209d39SAndroid Build Coastguard Worker * Assignment operator 249*0e209d39SAndroid Build Coastguard Worker * 250*0e209d39SAndroid Build Coastguard Worker * @param other the SelectFormat object to copy from. 251*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 252*0e209d39SAndroid Build Coastguard Worker */ 253*0e209d39SAndroid Build Coastguard Worker SelectFormat& operator=(const SelectFormat& other); 254*0e209d39SAndroid Build Coastguard Worker 255*0e209d39SAndroid Build Coastguard Worker /** 256*0e209d39SAndroid Build Coastguard Worker * Return true if another object is semantically equal to this one. 257*0e209d39SAndroid Build Coastguard Worker * 258*0e209d39SAndroid Build Coastguard Worker * @param other the SelectFormat object to be compared with. 259*0e209d39SAndroid Build Coastguard Worker * @return true if other is semantically equal to this. 260*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 261*0e209d39SAndroid Build Coastguard Worker */ 262*0e209d39SAndroid Build Coastguard Worker virtual bool operator==(const Format& other) const override; 263*0e209d39SAndroid Build Coastguard Worker 264*0e209d39SAndroid Build Coastguard Worker /** 265*0e209d39SAndroid Build Coastguard Worker * Return true if another object is semantically unequal to this one. 266*0e209d39SAndroid Build Coastguard Worker * 267*0e209d39SAndroid Build Coastguard Worker * @param other the SelectFormat object to be compared with. 268*0e209d39SAndroid Build Coastguard Worker * @return true if other is semantically unequal to this. 269*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 270*0e209d39SAndroid Build Coastguard Worker */ 271*0e209d39SAndroid Build Coastguard Worker virtual bool operator!=(const Format& other) const; 272*0e209d39SAndroid Build Coastguard Worker 273*0e209d39SAndroid Build Coastguard Worker /** 274*0e209d39SAndroid Build Coastguard Worker * Clones this Format object polymorphically. The caller owns the 275*0e209d39SAndroid Build Coastguard Worker * result and should delete it when done. 276*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 277*0e209d39SAndroid Build Coastguard Worker */ 278*0e209d39SAndroid Build Coastguard Worker virtual SelectFormat* clone() const override; 279*0e209d39SAndroid Build Coastguard Worker 280*0e209d39SAndroid Build Coastguard Worker /** 281*0e209d39SAndroid Build Coastguard Worker * Format an object to produce a string. 282*0e209d39SAndroid Build Coastguard Worker * This method handles keyword strings. 283*0e209d39SAndroid Build Coastguard Worker * If the Formattable object is not a <code>UnicodeString</code>, 284*0e209d39SAndroid Build Coastguard Worker * then it returns a failing UErrorCode. 285*0e209d39SAndroid Build Coastguard Worker * 286*0e209d39SAndroid Build Coastguard Worker * @param obj A keyword string that is used to select an alternative. 287*0e209d39SAndroid Build Coastguard Worker * @param appendTo output parameter to receive result. 288*0e209d39SAndroid Build Coastguard Worker * Result is appended to existing contents. 289*0e209d39SAndroid Build Coastguard Worker * @param pos On input: an alignment field, if desired. 290*0e209d39SAndroid Build Coastguard Worker * On output: the offsets of the alignment field. 291*0e209d39SAndroid Build Coastguard Worker * @param status output param filled with success/failure status. 292*0e209d39SAndroid Build Coastguard Worker * @return Reference to 'appendTo' parameter. 293*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 294*0e209d39SAndroid Build Coastguard Worker */ 295*0e209d39SAndroid Build Coastguard Worker UnicodeString& format(const Formattable& obj, 296*0e209d39SAndroid Build Coastguard Worker UnicodeString& appendTo, 297*0e209d39SAndroid Build Coastguard Worker FieldPosition& pos, 298*0e209d39SAndroid Build Coastguard Worker UErrorCode& status) const override; 299*0e209d39SAndroid Build Coastguard Worker 300*0e209d39SAndroid Build Coastguard Worker /** 301*0e209d39SAndroid Build Coastguard Worker * Returns the pattern from applyPattern() or constructor. 302*0e209d39SAndroid Build Coastguard Worker * 303*0e209d39SAndroid Build Coastguard Worker * @param appendTo output parameter to receive result. 304*0e209d39SAndroid Build Coastguard Worker * Result is appended to existing contents. 305*0e209d39SAndroid Build Coastguard Worker * @return the UnicodeString with inserted pattern. 306*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 307*0e209d39SAndroid Build Coastguard Worker */ 308*0e209d39SAndroid Build Coastguard Worker UnicodeString& toPattern(UnicodeString& appendTo); 309*0e209d39SAndroid Build Coastguard Worker 310*0e209d39SAndroid Build Coastguard Worker /** 311*0e209d39SAndroid Build Coastguard Worker * This method is not yet supported by <code>SelectFormat</code>. 312*0e209d39SAndroid Build Coastguard Worker * <P> 313*0e209d39SAndroid Build Coastguard Worker * Before calling, set parse_pos.index to the offset you want to start 314*0e209d39SAndroid Build Coastguard Worker * parsing at in the source. After calling, parse_pos.index is the end of 315*0e209d39SAndroid Build Coastguard Worker * the text you parsed. If error occurs, index is unchanged. 316*0e209d39SAndroid Build Coastguard Worker * <P> 317*0e209d39SAndroid Build Coastguard Worker * When parsing, leading whitespace is discarded (with a successful parse), 318*0e209d39SAndroid Build Coastguard Worker * while trailing whitespace is left as is. 319*0e209d39SAndroid Build Coastguard Worker * <P> 320*0e209d39SAndroid Build Coastguard Worker * See Format::parseObject() for more. 321*0e209d39SAndroid Build Coastguard Worker * 322*0e209d39SAndroid Build Coastguard Worker * @param source The string to be parsed into an object. 323*0e209d39SAndroid Build Coastguard Worker * @param result Formattable to be set to the parse result. 324*0e209d39SAndroid Build Coastguard Worker * If parse fails, return contents are undefined. 325*0e209d39SAndroid Build Coastguard Worker * @param parse_pos The position to start parsing at. Upon return 326*0e209d39SAndroid Build Coastguard Worker * this param is set to the position after the 327*0e209d39SAndroid Build Coastguard Worker * last character successfully parsed. If the 328*0e209d39SAndroid Build Coastguard Worker * source is not parsed successfully, this param 329*0e209d39SAndroid Build Coastguard Worker * will remain unchanged. 330*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 331*0e209d39SAndroid Build Coastguard Worker */ 332*0e209d39SAndroid Build Coastguard Worker virtual void parseObject(const UnicodeString& source, 333*0e209d39SAndroid Build Coastguard Worker Formattable& result, 334*0e209d39SAndroid Build Coastguard Worker ParsePosition& parse_pos) const override; 335*0e209d39SAndroid Build Coastguard Worker 336*0e209d39SAndroid Build Coastguard Worker /** 337*0e209d39SAndroid Build Coastguard Worker * ICU "poor man's RTTI", returns a UClassID for this class. 338*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 339*0e209d39SAndroid Build Coastguard Worker */ 340*0e209d39SAndroid Build Coastguard Worker static UClassID U_EXPORT2 getStaticClassID(); 341*0e209d39SAndroid Build Coastguard Worker 342*0e209d39SAndroid Build Coastguard Worker /** 343*0e209d39SAndroid Build Coastguard Worker * ICU "poor man's RTTI", returns a UClassID for the actual class. 344*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 345*0e209d39SAndroid Build Coastguard Worker */ 346*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override; 347*0e209d39SAndroid Build Coastguard Worker 348*0e209d39SAndroid Build Coastguard Worker private: 349*0e209d39SAndroid Build Coastguard Worker friend class MessageFormat; 350*0e209d39SAndroid Build Coastguard Worker 351*0e209d39SAndroid Build Coastguard Worker SelectFormat() = delete; // default constructor not implemented. 352*0e209d39SAndroid Build Coastguard Worker 353*0e209d39SAndroid Build Coastguard Worker /** 354*0e209d39SAndroid Build Coastguard Worker * Finds the SelectFormat sub-message for the given keyword, or the "other" sub-message. 355*0e209d39SAndroid Build Coastguard Worker * @param pattern A MessagePattern. 356*0e209d39SAndroid Build Coastguard Worker * @param partIndex the index of the first SelectFormat argument style part. 357*0e209d39SAndroid Build Coastguard Worker * @param keyword a keyword to be matched to one of the SelectFormat argument's keywords. 358*0e209d39SAndroid Build Coastguard Worker * @param ec Error code. 359*0e209d39SAndroid Build Coastguard Worker * @return the sub-message start part index. 360*0e209d39SAndroid Build Coastguard Worker */ 361*0e209d39SAndroid Build Coastguard Worker static int32_t findSubMessage(const MessagePattern& pattern, int32_t partIndex, 362*0e209d39SAndroid Build Coastguard Worker const UnicodeString& keyword, UErrorCode& ec); 363*0e209d39SAndroid Build Coastguard Worker 364*0e209d39SAndroid Build Coastguard Worker MessagePattern msgPattern; 365*0e209d39SAndroid Build Coastguard Worker }; 366*0e209d39SAndroid Build Coastguard Worker 367*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 368*0e209d39SAndroid Build Coastguard Worker 369*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */ 370*0e209d39SAndroid Build Coastguard Worker 371*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */ 372*0e209d39SAndroid Build Coastguard Worker 373*0e209d39SAndroid Build Coastguard Worker #endif // _SELFMT 374*0e209d39SAndroid Build Coastguard Worker //eof 375