1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/unicode/plurfmt.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,610 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* Copyright (C) 2007-2013, International Business Machines Corporation and 1.7 +* others. All Rights Reserved. 1.8 +******************************************************************************* 1.9 +* 1.10 + 1.11 +* File PLURFMT.H 1.12 +******************************************************************************** 1.13 +*/ 1.14 + 1.15 +#ifndef PLURFMT 1.16 +#define PLURFMT 1.17 + 1.18 +#include "unicode/utypes.h" 1.19 + 1.20 +/** 1.21 + * \file 1.22 + * \brief C++ API: PluralFormat object 1.23 + */ 1.24 + 1.25 +#if !UCONFIG_NO_FORMATTING 1.26 + 1.27 +#include "unicode/messagepattern.h" 1.28 +#include "unicode/numfmt.h" 1.29 +#include "unicode/plurrule.h" 1.30 + 1.31 +U_NAMESPACE_BEGIN 1.32 + 1.33 +class Hashtable; 1.34 + 1.35 +/** 1.36 + * <p> 1.37 + * <code>PluralFormat</code> supports the creation of internationalized 1.38 + * messages with plural inflection. It is based on <i>plural 1.39 + * selection</i>, i.e. the caller specifies messages for each 1.40 + * plural case that can appear in the user's language and the 1.41 + * <code>PluralFormat</code> selects the appropriate message based on 1.42 + * the number. 1.43 + * </p> 1.44 + * <h4>The Problem of Plural Forms in Internationalized Messages</h4> 1.45 + * <p> 1.46 + * Different languages have different ways to inflect 1.47 + * plurals. Creating internationalized messages that include plural 1.48 + * forms is only feasible when the framework is able to handle plural 1.49 + * forms of <i>all</i> languages correctly. <code>ChoiceFormat</code> 1.50 + * doesn't handle this well, because it attaches a number interval to 1.51 + * each message and selects the message whose interval contains a 1.52 + * given number. This can only handle a finite number of 1.53 + * intervals. But in some languages, like Polish, one plural case 1.54 + * applies to infinitely many intervals (e.g., the plural case applies to 1.55 + * numbers ending with 2, 3, or 4 except those ending with 12, 13, or 1.56 + * 14). Thus <code>ChoiceFormat</code> is not adequate. 1.57 + * </p><p> 1.58 + * <code>PluralFormat</code> deals with this by breaking the problem 1.59 + * into two parts: 1.60 + * <ul> 1.61 + * <li>It uses <code>PluralRules</code> that can define more complex 1.62 + * conditions for a plural case than just a single interval. These plural 1.63 + * rules define both what plural cases exist in a language, and to 1.64 + * which numbers these cases apply. 1.65 + * <li>It provides predefined plural rules for many languages. Thus, the programmer 1.66 + * need not worry about the plural cases of a language and 1.67 + * does not have to define the plural cases; they can simply 1.68 + * use the predefined keywords. The whole plural formatting of messages can 1.69 + * be done using localized patterns from resource bundles. For predefined plural 1.70 + * rules, see the CLDR <i>Language Plural Rules</i> page at 1.71 + * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 1.72 + * </ul> 1.73 + * </p> 1.74 + * <h4>Usage of <code>PluralFormat</code></h4> 1.75 + * <p>Note: Typically, plural formatting is done via <code>MessageFormat</code> 1.76 + * with a <code>plural</code> argument type, 1.77 + * rather than using a stand-alone <code>PluralFormat</code>. 1.78 + * </p><p> 1.79 + * This discussion assumes that you use <code>PluralFormat</code> with 1.80 + * a predefined set of plural rules. You can create one using one of 1.81 + * the constructors that takes a <code>locale</code> object. To 1.82 + * specify the message pattern, you can either pass it to the 1.83 + * constructor or set it explicitly using the 1.84 + * <code>applyPattern()</code> method. The <code>format()</code> 1.85 + * method takes a number object and selects the message of the 1.86 + * matching plural case. This message will be returned. 1.87 + * </p> 1.88 + * <h5>Patterns and Their Interpretation</h5> 1.89 + * <p> 1.90 + * The pattern text defines the message output for each plural case of the 1.91 + * specified locale. Syntax: 1.92 + * <pre> 1.93 + * pluralStyle = [offsetValue] (selector '{' message '}')+ 1.94 + * offsetValue = "offset:" number 1.95 + * selector = explicitValue | keyword 1.96 + * explicitValue = '=' number // adjacent, no white space in between 1.97 + * keyword = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+ 1.98 + * message: see {@link MessageFormat} 1.99 + * </pre> 1.100 + * Pattern_White_Space between syntax elements is ignored, except 1.101 + * between the {curly braces} and their sub-message, 1.102 + * and between the '=' and the number of an explicitValue. 1.103 + * 1.104 + * </p><p> 1.105 + * There are 6 predefined casekeyword in CLDR/ICU - 'zero', 'one', 'two', 'few', 'many' and 1.106 + * 'other'. You always have to define a message text for the default plural case 1.107 + * <code>other</code> which is contained in every rule set. 1.108 + * If you do not specify a message text for a particular plural case, the 1.109 + * message text of the plural case <code>other</code> gets assigned to this 1.110 + * plural case. 1.111 + * </p><p> 1.112 + * When formatting, the input number is first matched against the explicitValue clauses. 1.113 + * If there is no exact-number match, then a keyword is selected by calling 1.114 + * the <code>PluralRules</code> with the input number <em>minus the offset</em>. 1.115 + * (The offset defaults to 0 if it is omitted from the pattern string.) 1.116 + * If there is no clause with that keyword, then the "other" clauses is returned. 1.117 + * </p><p> 1.118 + * An unquoted pound sign (<code>#</code>) in the selected sub-message 1.119 + * itself (i.e., outside of arguments nested in the sub-message) 1.120 + * is replaced by the input number minus the offset. 1.121 + * The number-minus-offset value is formatted using a 1.122 + * <code>NumberFormat</code> for the <code>PluralFormat</code>'s locale. If you 1.123 + * need special number formatting, you have to use a <code>MessageFormat</code> 1.124 + * and explicitly specify a <code>NumberFormat</code> argument. 1.125 + * <strong>Note:</strong> That argument is formatting without subtracting the offset! 1.126 + * If you need a custom format and have a non-zero offset, then you need to pass the 1.127 + * number-minus-offset value as a separate parameter. 1.128 + * </p> 1.129 + * For a usage example, see the {@link MessageFormat} class documentation. 1.130 + * 1.131 + * <h4>Defining Custom Plural Rules</h4> 1.132 + * <p>If you need to use <code>PluralFormat</code> with custom rules, you can 1.133 + * create a <code>PluralRules</code> object and pass it to 1.134 + * <code>PluralFormat</code>'s constructor. If you also specify a locale in this 1.135 + * constructor, this locale will be used to format the number in the message 1.136 + * texts. 1.137 + * </p><p> 1.138 + * For more information about <code>PluralRules</code>, see 1.139 + * {@link PluralRules}. 1.140 + * </p> 1.141 + * 1.142 + * ported from Java 1.143 + * @stable ICU 4.0 1.144 + */ 1.145 + 1.146 +class U_I18N_API PluralFormat : public Format { 1.147 +public: 1.148 + 1.149 + /** 1.150 + * Creates a new cardinal-number <code>PluralFormat</code> for the default locale. 1.151 + * This locale will be used to get the set of plural rules and for standard 1.152 + * number formatting. 1.153 + * @param status output param set to success/failure code on exit, which 1.154 + * must not indicate a failure before the function call. 1.155 + * @stable ICU 4.0 1.156 + */ 1.157 + PluralFormat(UErrorCode& status); 1.158 + 1.159 + /** 1.160 + * Creates a new cardinal-number <code>PluralFormat</code> for a given locale. 1.161 + * @param locale the <code>PluralFormat</code> will be configured with 1.162 + * rules for this locale. This locale will also be used for 1.163 + * standard number formatting. 1.164 + * @param status output param set to success/failure code on exit, which 1.165 + * must not indicate a failure before the function call. 1.166 + * @stable ICU 4.0 1.167 + */ 1.168 + PluralFormat(const Locale& locale, UErrorCode& status); 1.169 + 1.170 + /** 1.171 + * Creates a new <code>PluralFormat</code> for a given set of rules. 1.172 + * The standard number formatting will be done using the default locale. 1.173 + * @param rules defines the behavior of the <code>PluralFormat</code> 1.174 + * object. 1.175 + * @param status output param set to success/failure code on exit, which 1.176 + * must not indicate a failure before the function call. 1.177 + * @stable ICU 4.0 1.178 + */ 1.179 + PluralFormat(const PluralRules& rules, UErrorCode& status); 1.180 + 1.181 + /** 1.182 + * Creates a new <code>PluralFormat</code> for a given set of rules. 1.183 + * The standard number formatting will be done using the given locale. 1.184 + * @param locale the default number formatting will be done using this 1.185 + * locale. 1.186 + * @param rules defines the behavior of the <code>PluralFormat</code> 1.187 + * object. 1.188 + * @param status output param set to success/failure code on exit, which 1.189 + * must not indicate a failure before the function call. 1.190 + * @stable ICU 4.0 1.191 + * <p> 1.192 + * <h4>Sample code</h4> 1.193 + * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample1 1.194 + * \snippet samples/plurfmtsample/plurfmtsample.cpp PluralFormatExample 1.195 + * <p> 1.196 + */ 1.197 + PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status); 1.198 + 1.199 + /** 1.200 + * Creates a new <code>PluralFormat</code> for the plural type. 1.201 + * The standard number formatting will be done using the given locale. 1.202 + * @param locale the default number formatting will be done using this 1.203 + * locale. 1.204 + * @param type The plural type (e.g., cardinal or ordinal). 1.205 + * @param status output param set to success/failure code on exit, which 1.206 + * must not indicate a failure before the function call. 1.207 + * @stable ICU 50 1.208 + */ 1.209 + PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status); 1.210 + 1.211 + /** 1.212 + * Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string. 1.213 + * The default locale will be used to get the set of plural rules and for 1.214 + * standard number formatting. 1.215 + * @param pattern the pattern for this <code>PluralFormat</code>. 1.216 + * errors are returned to status if the pattern is invalid. 1.217 + * @param status output param set to success/failure code on exit, which 1.218 + * must not indicate a failure before the function call. 1.219 + * @stable ICU 4.0 1.220 + */ 1.221 + PluralFormat(const UnicodeString& pattern, UErrorCode& status); 1.222 + 1.223 + /** 1.224 + * Creates a new cardinal-number <code>PluralFormat</code> for a given pattern string and 1.225 + * locale. 1.226 + * The locale will be used to get the set of plural rules and for 1.227 + * standard number formatting. 1.228 + * @param locale the <code>PluralFormat</code> will be configured with 1.229 + * rules for this locale. This locale will also be used for 1.230 + * standard number formatting. 1.231 + * @param pattern the pattern for this <code>PluralFormat</code>. 1.232 + * errors are returned to status if the pattern is invalid. 1.233 + * @param status output param set to success/failure code on exit, which 1.234 + * must not indicate a failure before the function call. 1.235 + * @stable ICU 4.0 1.236 + */ 1.237 + PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status); 1.238 + 1.239 + /** 1.240 + * Creates a new <code>PluralFormat</code> for a given set of rules, a 1.241 + * pattern and a locale. 1.242 + * @param rules defines the behavior of the <code>PluralFormat</code> 1.243 + * object. 1.244 + * @param pattern the pattern for this <code>PluralFormat</code>. 1.245 + * errors are returned to status if the pattern is invalid. 1.246 + * @param status output param set to success/failure code on exit, which 1.247 + * must not indicate a failure before the function call. 1.248 + * @stable ICU 4.0 1.249 + */ 1.250 + PluralFormat(const PluralRules& rules, 1.251 + const UnicodeString& pattern, 1.252 + UErrorCode& status); 1.253 + 1.254 + /** 1.255 + * Creates a new <code>PluralFormat</code> for a given set of rules, a 1.256 + * pattern and a locale. 1.257 + * @param locale the <code>PluralFormat</code> will be configured with 1.258 + * rules for this locale. This locale will also be used for 1.259 + * standard number formatting. 1.260 + * @param rules defines the behavior of the <code>PluralFormat</code> 1.261 + * object. 1.262 + * @param pattern the pattern for this <code>PluralFormat</code>. 1.263 + * errors are returned to status if the pattern is invalid. 1.264 + * @param status output param set to success/failure code on exit, which 1.265 + * must not indicate a failure before the function call. 1.266 + * @stable ICU 4.0 1.267 + */ 1.268 + PluralFormat(const Locale& locale, 1.269 + const PluralRules& rules, 1.270 + const UnicodeString& pattern, 1.271 + UErrorCode& status); 1.272 + 1.273 + /** 1.274 + * Creates a new <code>PluralFormat</code> for a plural type, a 1.275 + * pattern and a locale. 1.276 + * @param locale the <code>PluralFormat</code> will be configured with 1.277 + * rules for this locale. This locale will also be used for 1.278 + * standard number formatting. 1.279 + * @param type The plural type (e.g., cardinal or ordinal). 1.280 + * @param pattern the pattern for this <code>PluralFormat</code>. 1.281 + * errors are returned to status if the pattern is invalid. 1.282 + * @param status output param set to success/failure code on exit, which 1.283 + * must not indicate a failure before the function call. 1.284 + * @stable ICU 50 1.285 + */ 1.286 + PluralFormat(const Locale& locale, 1.287 + UPluralType type, 1.288 + const UnicodeString& pattern, 1.289 + UErrorCode& status); 1.290 + 1.291 + /** 1.292 + * copy constructor. 1.293 + * @stable ICU 4.0 1.294 + */ 1.295 + PluralFormat(const PluralFormat& other); 1.296 + 1.297 + /** 1.298 + * Destructor. 1.299 + * @stable ICU 4.0 1.300 + */ 1.301 + virtual ~PluralFormat(); 1.302 + 1.303 + /** 1.304 + * Sets the pattern used by this plural format. 1.305 + * The method parses the pattern and creates a map of format strings 1.306 + * for the plural rules. 1.307 + * Patterns and their interpretation are specified in the class description. 1.308 + * 1.309 + * @param pattern the pattern for this plural format 1.310 + * errors are returned to status if the pattern is invalid. 1.311 + * @param status output param set to success/failure code on exit, which 1.312 + * must not indicate a failure before the function call. 1.313 + * @stable ICU 4.0 1.314 + */ 1.315 + void applyPattern(const UnicodeString& pattern, UErrorCode& status); 1.316 + 1.317 + 1.318 + using Format::format; 1.319 + 1.320 + /** 1.321 + * Formats a plural message for a given number. 1.322 + * 1.323 + * @param number a number for which the plural message should be formatted 1.324 + * for. If no pattern has been applied to this 1.325 + * <code>PluralFormat</code> object yet, the formatted number 1.326 + * will be returned. 1.327 + * @param status output param set to success/failure code on exit, which 1.328 + * must not indicate a failure before the function call. 1.329 + * @return the string containing the formatted plural message. 1.330 + * @stable ICU 4.0 1.331 + */ 1.332 + UnicodeString format(int32_t number, UErrorCode& status) const; 1.333 + 1.334 + /** 1.335 + * Formats a plural message for a given number. 1.336 + * 1.337 + * @param number a number for which the plural message should be formatted 1.338 + * for. If no pattern has been applied to this 1.339 + * PluralFormat object yet, the formatted number 1.340 + * will be returned. 1.341 + * @param status output param set to success or failure code on exit, which 1.342 + * must not indicate a failure before the function call. 1.343 + * @return the string containing the formatted plural message. 1.344 + * @stable ICU 4.0 1.345 + */ 1.346 + UnicodeString format(double number, UErrorCode& status) const; 1.347 + 1.348 + /** 1.349 + * Formats a plural message for a given number. 1.350 + * 1.351 + * @param number a number for which the plural message should be formatted 1.352 + * for. If no pattern has been applied to this 1.353 + * <code>PluralFormat</code> object yet, the formatted number 1.354 + * will be returned. 1.355 + * @param appendTo output parameter to receive result. 1.356 + * result is appended to existing contents. 1.357 + * @param pos On input: an alignment field, if desired. 1.358 + * On output: the offsets of the alignment field. 1.359 + * @param status output param set to success/failure code on exit, which 1.360 + * must not indicate a failure before the function call. 1.361 + * @return the string containing the formatted plural message. 1.362 + * @stable ICU 4.0 1.363 + */ 1.364 + UnicodeString& format(int32_t number, 1.365 + UnicodeString& appendTo, 1.366 + FieldPosition& pos, 1.367 + UErrorCode& status) const; 1.368 + 1.369 + /** 1.370 + * Formats a plural message for a given number. 1.371 + * 1.372 + * @param number a number for which the plural message should be formatted 1.373 + * for. If no pattern has been applied to this 1.374 + * PluralFormat object yet, the formatted number 1.375 + * will be returned. 1.376 + * @param appendTo output parameter to receive result. 1.377 + * result is appended to existing contents. 1.378 + * @param pos On input: an alignment field, if desired. 1.379 + * On output: the offsets of the alignment field. 1.380 + * @param status output param set to success/failure code on exit, which 1.381 + * must not indicate a failure before the function call. 1.382 + * @return the string containing the formatted plural message. 1.383 + * @stable ICU 4.0 1.384 + */ 1.385 + UnicodeString& format(double number, 1.386 + UnicodeString& appendTo, 1.387 + FieldPosition& pos, 1.388 + UErrorCode& status) const; 1.389 + 1.390 +#ifndef U_HIDE_DEPRECATED_API 1.391 + /** 1.392 + * Sets the locale used by this <code>PluraFormat</code> object. 1.393 + * Note: Calling this method resets this <code>PluraFormat</code> object, 1.394 + * i.e., a pattern that was applied previously will be removed, 1.395 + * and the NumberFormat is set to the default number format for 1.396 + * the locale. The resulting format behaves the same as one 1.397 + * constructed from {@link #PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status)} 1.398 + * with UPLURAL_TYPE_CARDINAL. 1.399 + * @param locale the <code>locale</code> to use to configure the formatter. 1.400 + * @param status output param set to success/failure code on exit, which 1.401 + * must not indicate a failure before the function call. 1.402 + * @deprecated ICU 50 This method clears the pattern and might create 1.403 + * a different kind of PluralRules instance; 1.404 + * use one of the constructors to create a new instance instead. 1.405 + */ 1.406 + void setLocale(const Locale& locale, UErrorCode& status); 1.407 +#endif /* U_HIDE_DEPRECATED_API */ 1.408 + 1.409 + /** 1.410 + * Sets the number format used by this formatter. You only need to 1.411 + * call this if you want a different number format than the default 1.412 + * formatter for the locale. 1.413 + * @param format the number format to use. 1.414 + * @param status output param set to success/failure code on exit, which 1.415 + * must not indicate a failure before the function call. 1.416 + * @stable ICU 4.0 1.417 + */ 1.418 + void setNumberFormat(const NumberFormat* format, UErrorCode& status); 1.419 + 1.420 + /** 1.421 + * Assignment operator 1.422 + * 1.423 + * @param other the PluralFormat object to copy from. 1.424 + * @stable ICU 4.0 1.425 + */ 1.426 + PluralFormat& operator=(const PluralFormat& other); 1.427 + 1.428 + /** 1.429 + * Return true if another object is semantically equal to this one. 1.430 + * 1.431 + * @param other the PluralFormat object to be compared with. 1.432 + * @return true if other is semantically equal to this. 1.433 + * @stable ICU 4.0 1.434 + */ 1.435 + virtual UBool operator==(const Format& other) const; 1.436 + 1.437 + /** 1.438 + * Return true if another object is semantically unequal to this one. 1.439 + * 1.440 + * @param other the PluralFormat object to be compared with. 1.441 + * @return true if other is semantically unequal to this. 1.442 + * @stable ICU 4.0 1.443 + */ 1.444 + virtual UBool operator!=(const Format& other) const; 1.445 + 1.446 + /** 1.447 + * Clones this Format object polymorphically. The caller owns the 1.448 + * result and should delete it when done. 1.449 + * @stable ICU 4.0 1.450 + */ 1.451 + virtual Format* clone(void) const; 1.452 + 1.453 + /** 1.454 + * Formats a plural message for a number taken from a Formattable object. 1.455 + * 1.456 + * @param obj The object containing a number for which the 1.457 + * plural message should be formatted. 1.458 + * The object must be of a numeric type. 1.459 + * @param appendTo output parameter to receive result. 1.460 + * Result is appended to existing contents. 1.461 + * @param pos On input: an alignment field, if desired. 1.462 + * On output: the offsets of the alignment field. 1.463 + * @param status output param filled with success/failure status. 1.464 + * @return Reference to 'appendTo' parameter. 1.465 + * @stable ICU 4.0 1.466 + */ 1.467 + UnicodeString& format(const Formattable& obj, 1.468 + UnicodeString& appendTo, 1.469 + FieldPosition& pos, 1.470 + UErrorCode& status) const; 1.471 + 1.472 + /** 1.473 + * Returns the pattern from applyPattern() or constructor(). 1.474 + * 1.475 + * @param appendTo output parameter to receive result. 1.476 + * Result is appended to existing contents. 1.477 + * @return the UnicodeString with inserted pattern. 1.478 + * @stable ICU 4.0 1.479 + */ 1.480 + UnicodeString& toPattern(UnicodeString& appendTo); 1.481 + 1.482 + /** 1.483 + * This method is not yet supported by <code>PluralFormat</code>. 1.484 + * <P> 1.485 + * Before calling, set parse_pos.index to the offset you want to start 1.486 + * parsing at in the source. After calling, parse_pos.index is the end of 1.487 + * the text you parsed. If error occurs, index is unchanged. 1.488 + * <P> 1.489 + * When parsing, leading whitespace is discarded (with a successful parse), 1.490 + * while trailing whitespace is left as is. 1.491 + * <P> 1.492 + * See Format::parseObject() for more. 1.493 + * 1.494 + * @param source The string to be parsed into an object. 1.495 + * @param result Formattable to be set to the parse result. 1.496 + * If parse fails, return contents are undefined. 1.497 + * @param parse_pos The position to start parsing at. Upon return 1.498 + * this param is set to the position after the 1.499 + * last character successfully parsed. If the 1.500 + * source is not parsed successfully, this param 1.501 + * will remain unchanged. 1.502 + * @stable ICU 4.0 1.503 + */ 1.504 + virtual void parseObject(const UnicodeString& source, 1.505 + Formattable& result, 1.506 + ParsePosition& parse_pos) const; 1.507 + 1.508 + /** 1.509 + * ICU "poor man's RTTI", returns a UClassID for this class. 1.510 + * 1.511 + * @stable ICU 4.0 1.512 + * 1.513 + */ 1.514 + static UClassID U_EXPORT2 getStaticClassID(void); 1.515 + 1.516 + /** 1.517 + * ICU "poor man's RTTI", returns a UClassID for the actual class. 1.518 + * 1.519 + * @stable ICU 4.0 1.520 + */ 1.521 + virtual UClassID getDynamicClassID() const; 1.522 + 1.523 +#if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400) 1.524 +// Work around a compiler bug on xlC 11.1 on AIX 7.1 that would 1.525 +// prevent PluralSelectorAdapter from implementing private PluralSelector. 1.526 +// xlC error message: 1.527 +// 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed. 1.528 +public: 1.529 +#else 1.530 +private: 1.531 +#endif 1.532 + /** 1.533 + * @internal 1.534 + */ 1.535 + class U_I18N_API PluralSelector : public UMemory { 1.536 + public: 1.537 + virtual ~PluralSelector(); 1.538 + /** 1.539 + * Given a number, returns the appropriate PluralFormat keyword. 1.540 + * 1.541 + * @param context worker object for the selector. 1.542 + * @param number The number to be plural-formatted. 1.543 + * @param ec Error code. 1.544 + * @return The selected PluralFormat keyword. 1.545 + * @internal 1.546 + */ 1.547 + virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0; 1.548 + }; 1.549 + 1.550 + /** 1.551 + * @internal 1.552 + */ 1.553 + class U_I18N_API PluralSelectorAdapter : public PluralSelector { 1.554 + public: 1.555 + PluralSelectorAdapter() : pluralRules(NULL) { 1.556 + } 1.557 + 1.558 + virtual ~PluralSelectorAdapter(); 1.559 + 1.560 + virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const; /**< @internal */ 1.561 + 1.562 + void reset(); 1.563 + 1.564 + PluralRules* pluralRules; 1.565 + }; 1.566 + 1.567 +#if defined(__xlC__) 1.568 +// End of xlC bug workaround, keep remaining definitions private. 1.569 +private: 1.570 +#endif 1.571 + Locale locale; 1.572 + MessagePattern msgPattern; 1.573 + NumberFormat* numberFormat; 1.574 + double offset; 1.575 + PluralSelectorAdapter pluralRulesWrapper; 1.576 + 1.577 + PluralFormat(); // default constructor not implemented 1.578 + void init(const PluralRules* rules, UPluralType type, UErrorCode& status); 1.579 + /** 1.580 + * Copies dynamically allocated values (pointer fields). 1.581 + * Others are copied using their copy constructors and assignment operators. 1.582 + */ 1.583 + void copyObjects(const PluralFormat& other); 1.584 + 1.585 + UnicodeString& format(const Formattable& numberObject, double number, 1.586 + UnicodeString& appendTo, 1.587 + FieldPosition& pos, 1.588 + UErrorCode& status) const; /**< @internal */ 1.589 + 1.590 + /** 1.591 + * Finds the PluralFormat sub-message for the given number, or the "other" sub-message. 1.592 + * @param pattern A MessagePattern. 1.593 + * @param partIndex the index of the first PluralFormat argument style part. 1.594 + * @param selector the PluralSelector for mapping the number (minus offset) to a keyword. 1.595 + * @param context worker object for the selector. 1.596 + * @param number a number to be matched to one of the PluralFormat argument's explicit values, 1.597 + * or mapped via the PluralSelector. 1.598 + * @param ec ICU error code. 1.599 + * @return the sub-message start part index. 1.600 + */ 1.601 + static int32_t findSubMessage( 1.602 + const MessagePattern& pattern, int32_t partIndex, 1.603 + const PluralSelector& selector, void *context, double number, UErrorCode& ec); /**< @internal */ 1.604 + 1.605 + friend class MessageFormat; 1.606 +}; 1.607 + 1.608 +U_NAMESPACE_END 1.609 + 1.610 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.611 + 1.612 +#endif // _PLURFMT 1.613 +//eof