|
|
|||
File indexing completed on 2026-01-04 10:00:24
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************* 0005 * Copyright (C) 1997-2015, International Business Machines Corporation and others. 0006 * All Rights Reserved. 0007 ******************************************************************************* 0008 */ 0009 0010 #ifndef RBNF_H 0011 #define RBNF_H 0012 0013 #include "unicode/utypes.h" 0014 0015 #if U_SHOW_CPLUSPLUS_API 0016 0017 /** 0018 * \file 0019 * \brief C++ API: Rule Based Number Format 0020 */ 0021 0022 /** 0023 * \def U_HAVE_RBNF 0024 * This will be 0 if RBNF support is not included in ICU 0025 * and 1 if it is. 0026 * 0027 * @stable ICU 2.4 0028 */ 0029 #if UCONFIG_NO_FORMATTING 0030 #define U_HAVE_RBNF 0 0031 #else 0032 #define U_HAVE_RBNF 1 0033 0034 #include "unicode/dcfmtsym.h" 0035 #include "unicode/fmtable.h" 0036 #include "unicode/locid.h" 0037 #include "unicode/numfmt.h" 0038 #include "unicode/unistr.h" 0039 #include "unicode/strenum.h" 0040 #include "unicode/brkiter.h" 0041 #include "unicode/upluralrules.h" 0042 0043 U_NAMESPACE_BEGIN 0044 0045 class NFRule; 0046 class NFRuleSet; 0047 class LocalizationInfo; 0048 class PluralFormat; 0049 class RuleBasedCollator; 0050 0051 /** 0052 * Tags for the predefined rulesets. 0053 * 0054 * @stable ICU 2.2 0055 */ 0056 enum URBNFRuleSetTag { 0057 /** 0058 * Requests predefined ruleset for spelling out numeric values in words. 0059 * @stable ICU 2.2 0060 */ 0061 URBNF_SPELLOUT, 0062 /** 0063 * Requests predefined ruleset for the ordinal form of a number. 0064 * @stable ICU 2.2 0065 */ 0066 URBNF_ORDINAL, 0067 #ifndef U_HIDE_DEPRECATED_API 0068 /** 0069 * Requests predefined ruleset for formatting a value as a duration in hours, minutes, and seconds. 0070 * @deprecated ICU 74 Use MeasureFormat instead. 0071 */ 0072 URBNF_DURATION, 0073 #endif // U_HIDE_DERECATED_API 0074 /** 0075 * Requests predefined ruleset for various non-place-value numbering systems. 0076 * WARNING: The same resource contains rule sets for a variety of different numbering systems. 0077 * You need to call setDefaultRuleSet() on the formatter to choose the actual numbering system. 0078 * @stable ICU 2.2 0079 */ 0080 URBNF_NUMBERING_SYSTEM = 3, 0081 #ifndef U_HIDE_DEPRECATED_API 0082 /** 0083 * One more than the highest normal URBNFRuleSetTag value. 0084 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 0085 */ 0086 URBNF_COUNT 0087 #endif // U_HIDE_DEPRECATED_API 0088 }; 0089 0090 /** 0091 * The RuleBasedNumberFormat class formats numbers according to a set of rules. This number formatter is 0092 * typically used for spelling out numeric values in words (e.g., 25,3476 as 0093 * "twenty-five thousand three hundred seventy-six" or "vingt-cinq mille trois 0094 * cents soixante-seize" or 0095 * "fünfundzwanzigtausenddreihundertsechsundsiebzig"), but can also be used for 0096 * other complicated formatting tasks, such as formatting a number of seconds as hours, 0097 * minutes and seconds (e.g., 3,730 as "1:02:10"). 0098 * 0099 * <p>The resources contain three predefined formatters for each locale: spellout, which 0100 * spells out a value in words (123 is "one hundred twenty-three"); ordinal, which 0101 * appends an ordinal suffix to the end of a numeral (123 is "123rd"); and 0102 * duration, which shows a duration in seconds as hours, minutes, and seconds (123 is 0103 * "2:03"). The client can also define more specialized <tt>RuleBasedNumberFormat</tt>s 0104 * by supplying programmer-defined rule sets.</p> 0105 * 0106 * <p>The behavior of a <tt>RuleBasedNumberFormat</tt> is specified by a textual description 0107 * that is either passed to the constructor as a <tt>String</tt> or loaded from a resource 0108 * bundle. In its simplest form, the description consists of a semicolon-delimited list of <em>rules.</em> 0109 * Each rule has a string of output text and a value or range of values it is applicable to. 0110 * In a typical spellout rule set, the first twenty rules are the words for the numbers from 0111 * 0 to 19:</p> 0112 * 0113 * <pre>zero; one; two; three; four; five; six; seven; eight; nine; 0114 * ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen; seventeen; eighteen; nineteen;</pre> 0115 * 0116 * <p>For larger numbers, we can use the preceding set of rules to format the ones place, and 0117 * we only have to supply the words for the multiples of 10:</p> 0118 * 0119 * <pre> 20: twenty[->>]; 0120 * 30: thirty[->>]; 0121 * 40: forty[->>]; 0122 * 50: fifty[->>]; 0123 * 60: sixty[->>]; 0124 * 70: seventy[->>]; 0125 * 80: eighty[->>]; 0126 * 90: ninety[->>];</pre> 0127 * 0128 * <p>In these rules, the <em>base value</em> is spelled out explicitly and set off from the 0129 * rule's output text with a colon. The rules are in a sorted list, and a rule is applicable 0130 * to all numbers from its own base value to one less than the next rule's base value. The 0131 * ">>" token is called a <em>substitution</em> and tells the formatter to 0132 * isolate the number's ones digit, format it using this same set of rules, and place the 0133 * result at the position of the ">>" token. Text in brackets is omitted if 0134 * the number being formatted is an even multiple of 10 (the hyphen is a literal hyphen; 24 0135 * is "twenty-four," not "twenty four").</p> 0136 * 0137 * <p>For even larger numbers, we can actually look up several parts of the number in the 0138 * list:</p> 0139 * 0140 * <pre>100: << hundred[ >>];</pre> 0141 * 0142 * <p>The "<<" represents a new kind of substitution. The << isolates 0143 * the hundreds digit (and any digits to its left), formats it using this same rule set, and 0144 * places the result where the "<<" was. Notice also that the meaning of 0145 * >> has changed: it now refers to both the tens and the ones digits. The meaning of 0146 * both substitutions depends on the rule's base value. The base value determines the rule's <em>divisor,</em> 0147 * which is the highest power of 10 that is less than or equal to the base value (the user 0148 * can change this). To fill in the substitutions, the formatter divides the number being 0149 * formatted by the divisor. The integral quotient is used to fill in the << 0150 * substitution, and the remainder is used to fill in the >> substitution. The meaning 0151 * of the brackets changes similarly: text in brackets is omitted if the value being 0152 * formatted is an even multiple of the rule's divisor. The rules are applied recursively, so 0153 * if a substitution is filled in with text that includes another substitution, that 0154 * substitution is also filled in.</p> 0155 * 0156 * <p>This rule covers values up to 999, at which point we add another rule:</p> 0157 * 0158 * <pre>1000: << thousand[ >>];</pre> 0159 * 0160 * <p>Again, the meanings of the brackets and substitution tokens shift because the rule's 0161 * base value is a higher power of 10, changing the rule's divisor. This rule can actually be 0162 * used all the way up to 999,999. This allows us to finish out the rules as follows:</p> 0163 * 0164 * <pre> 1,000,000: << million[ >>]; 0165 * 1,000,000,000: << billion[ >>]; 0166 * 1,000,000,000,000: << trillion[ >>]; 0167 * 1,000,000,000,000,000: OUT OF RANGE!;</pre> 0168 * 0169 * <p>Commas, periods, and spaces can be used in the base values to improve legibility and 0170 * are ignored by the rule parser. The last rule in the list is customarily treated as an 0171 * "overflow rule," applying to everything from its base value on up, and often (as 0172 * in this example) being used to print out an error message or default representation. 0173 * Notice also that the size of the major groupings in large numbers is controlled by the 0174 * spacing of the rules: because in English we group numbers by thousand, the higher rules 0175 * are separated from each other by a factor of 1,000.</p> 0176 * 0177 * <p>To see how these rules actually work in practice, consider the following example: 0178 * Formatting 25,430 with this rule set would work like this:</p> 0179 * 0180 * <table border="0" width="100%"> 0181 * <tr> 0182 * <td><strong><< thousand >></strong></td> 0183 * <td>[the rule whose base value is 1,000 is applicable to 25,340]</td> 0184 * </tr> 0185 * <tr> 0186 * <td><strong>twenty->></strong> thousand >></td> 0187 * <td>[25,340 over 1,000 is 25. The rule for 20 applies.]</td> 0188 * </tr> 0189 * <tr> 0190 * <td>twenty-<strong>five</strong> thousand >></td> 0191 * <td>[25 mod 10 is 5. The rule for 5 is "five."</td> 0192 * </tr> 0193 * <tr> 0194 * <td>twenty-five thousand <strong><< hundred >></strong></td> 0195 * <td>[25,340 mod 1,000 is 340. The rule for 100 applies.]</td> 0196 * </tr> 0197 * <tr> 0198 * <td>twenty-five thousand <strong>three</strong> hundred >></td> 0199 * <td>[340 over 100 is 3. The rule for 3 is "three."]</td> 0200 * </tr> 0201 * <tr> 0202 * <td>twenty-five thousand three hundred <strong>forty</strong></td> 0203 * <td>[340 mod 100 is 40. The rule for 40 applies. Since 40 divides 0204 * evenly by 10, the hyphen and substitution in the brackets are omitted.]</td> 0205 * </tr> 0206 * </table> 0207 * 0208 * <p>The above syntax suffices only to format positive integers. To format negative numbers, 0209 * we add a special rule:</p> 0210 * 0211 * <pre>-x: minus >>;</pre> 0212 * 0213 * <p>This is called a <em>negative-number rule,</em> and is identified by "-x" 0214 * where the base value would be. This rule is used to format all negative numbers. the 0215 * >> token here means "find the number's absolute value, format it with these 0216 * rules, and put the result here."</p> 0217 * 0218 * <p>We also add a special rule called a <em>fraction rule </em>for numbers with fractional 0219 * parts:</p> 0220 * 0221 * <pre>x.x: << point >>;</pre> 0222 * 0223 * <p>This rule is used for all positive non-integers (negative non-integers pass through the 0224 * negative-number rule first and then through this rule). Here, the << token refers to 0225 * the number's integral part, and the >> to the number's fractional part. The 0226 * fractional part is formatted as a series of single-digit numbers (e.g., 123.456 would be 0227 * formatted as "one hundred twenty-three point four five six").</p> 0228 * 0229 * <p>To see how this rule syntax is applied to various languages, examine the resource data.</p> 0230 * 0231 * <p>There is actually much more flexibility built into the rule language than the 0232 * description above shows. A formatter may own multiple rule sets, which can be selected by 0233 * the caller, and which can use each other to fill in their substitutions. Substitutions can 0234 * also be filled in with digits, using a DecimalFormat object. There is syntax that can be 0235 * used to alter a rule's divisor in various ways. And there is provision for much more 0236 * flexible fraction handling. A complete description of the rule syntax follows:</p> 0237 * 0238 * <hr> 0239 * 0240 * <p>The description of a <tt>RuleBasedNumberFormat</tt>'s behavior consists of one or more <em>rule 0241 * sets.</em> Each rule set consists of a name, a colon, and a list of <em>rules.</em> A rule 0242 * set name must begin with a % sign. Rule sets with names that begin with a single % sign 0243 * are <em>public:</em> the caller can specify that they be used to format and parse numbers. 0244 * Rule sets with names that begin with %% are <em>private:</em> they exist only for the use 0245 * of other rule sets. If a formatter only has one rule set, the name may be omitted.</p> 0246 * 0247 * <p>The user can also specify a special "rule set" named <tt>%%lenient-parse</tt>. 0248 * The body of <tt>%%lenient-parse</tt> isn't a set of number-formatting rules, but a <tt>RuleBasedCollator</tt> 0249 * description which is used to define equivalences for lenient parsing. For more information 0250 * on the syntax, see <tt>RuleBasedCollator</tt>. For more information on lenient parsing, 0251 * see <tt>setLenientParse()</tt>. <em>Note:</em> symbols that have syntactic meaning 0252 * in collation rules, such as '&', have no particular meaning when appearing outside 0253 * of the <tt>lenient-parse</tt> rule set.</p> 0254 * 0255 * <p>The body of a rule set consists of an ordered, semicolon-delimited list of <em>rules.</em> 0256 * Internally, every rule has a base value, a divisor, rule text, and zero, one, or two <em>substitutions.</em> 0257 * These parameters are controlled by the description syntax, which consists of a <em>rule 0258 * descriptor,</em> a colon, and a <em>rule body.</em></p> 0259 * 0260 * <p>A rule descriptor can take one of the following forms (text in <em>italics</em> is the 0261 * name of a token):</p> 0262 * 0263 * <table border="0" width="100%"> 0264 * <tr> 0265 * <td><em>bv</em>:</td> 0266 * <td><em>bv</em> specifies the rule's base value. <em>bv</em> is a decimal 0267 * number expressed using ASCII digits. <em>bv</em> may contain spaces, period, and commas, 0268 * which are ignored. The rule's divisor is the highest power of 10 less than or equal to 0269 * the base value.</td> 0270 * </tr> 0271 * <tr> 0272 * <td><em>bv</em>/<em>rad</em>:</td> 0273 * <td><em>bv</em> specifies the rule's base value. The rule's divisor is the 0274 * highest power of <em>rad</em> less than or equal to the base value.</td> 0275 * </tr> 0276 * <tr> 0277 * <td><em>bv</em>>:</td> 0278 * <td><em>bv</em> specifies the rule's base value. To calculate the divisor, 0279 * let the radix be 10, and the exponent be the highest exponent of the radix that yields a 0280 * result less than or equal to the base value. Every > character after the base value 0281 * decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix 0282 * raised to the power of the exponent; otherwise, the divisor is 1.</td> 0283 * </tr> 0284 * <tr> 0285 * <td><em>bv</em>/<em>rad</em>>:</td> 0286 * <td><em>bv</em> specifies the rule's base value. To calculate the divisor, 0287 * let the radix be <em>rad</em>, and the exponent be the highest exponent of the radix that 0288 * yields a result less than or equal to the base value. Every > character after the radix 0289 * decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix 0290 * raised to the power of the exponent; otherwise, the divisor is 1.</td> 0291 * </tr> 0292 * <tr> 0293 * <td>-x:</td> 0294 * <td>The rule is a negative-number rule.</td> 0295 * </tr> 0296 * <tr> 0297 * <td>x.x:</td> 0298 * <td>The rule is an <em>improper fraction rule</em>. If the full stop in 0299 * the middle of the rule name is replaced with the decimal point 0300 * that is used in the language or DecimalFormatSymbols, then that rule will 0301 * have precedence when formatting and parsing this rule. For example, some 0302 * languages use the comma, and can thus be written as x,x instead. For example, 0303 * you can use "x.x: << point >>;x,x: << comma >>;" to 0304 * handle the decimal point that matches the language's natural spelling of 0305 * the punctuation of either the full stop or comma.</td> 0306 * </tr> 0307 * <tr> 0308 * <td>0.x:</td> 0309 * <td>The rule is a <em>proper fraction rule</em>. If the full stop in 0310 * the middle of the rule name is replaced with the decimal point 0311 * that is used in the language or DecimalFormatSymbols, then that rule will 0312 * have precedence when formatting and parsing this rule. For example, some 0313 * languages use the comma, and can thus be written as 0,x instead. For example, 0314 * you can use "0.x: point >>;0,x: comma >>;" to 0315 * handle the decimal point that matches the language's natural spelling of 0316 * the punctuation of either the full stop or comma.</td> 0317 * </tr> 0318 * <tr> 0319 * <td>x.0:</td> 0320 * <td>The rule is a <em>default rule</em>. If the full stop in 0321 * the middle of the rule name is replaced with the decimal point 0322 * that is used in the language or DecimalFormatSymbols, then that rule will 0323 * have precedence when formatting and parsing this rule. For example, some 0324 * languages use the comma, and can thus be written as x,0 instead. For example, 0325 * you can use "x.0: << point;x,0: << comma;" to 0326 * handle the decimal point that matches the language's natural spelling of 0327 * the punctuation of either the full stop or comma.</td> 0328 * </tr> 0329 * <tr> 0330 * <td>Inf:</td> 0331 * <td>The rule for infinity.</td> 0332 * </tr> 0333 * <tr> 0334 * <td>NaN:</td> 0335 * <td>The rule for an IEEE 754 NaN (not a number).</td> 0336 * </tr> 0337 * <tr> 0338 * <td><em>nothing</em></td> 0339 * <td>If the rule's rule descriptor is left out, the base value is one plus the 0340 * preceding rule's base value (or zero if this is the first rule in the list) in a normal 0341 * rule set. In a fraction rule set, the base value is the same as the preceding rule's 0342 * base value.</td> 0343 * </tr> 0344 * </table> 0345 * 0346 * <p>A rule set may be either a regular rule set or a <em>fraction rule set,</em> depending 0347 * on whether it is used to format a number's integral part (or the whole number) or a 0348 * number's fractional part. Using a rule set to format a rule's fractional part makes it a 0349 * fraction rule set.</p> 0350 * 0351 * <p>Which rule is used to format a number is defined according to one of the following 0352 * algorithms: If the rule set is a regular rule set, do the following: 0353 * 0354 * <ul> 0355 * <li>If the rule set includes a default rule (and the number was passed in as a <tt>double</tt>), 0356 * use the default rule. (If the number being formatted was passed in as a <tt>long</tt>, 0357 * the default rule is ignored.)</li> 0358 * <li>If the number is negative, use the negative-number rule.</li> 0359 * <li>If the number has a fractional part and is greater than 1, use the improper fraction 0360 * rule.</li> 0361 * <li>If the number has a fractional part and is between 0 and 1, use the proper fraction 0362 * rule.</li> 0363 * <li>Binary-search the rule list for the rule with the highest base value less than or equal 0364 * to the number. If that rule has two substitutions, its base value is not an even multiple 0365 * of its divisor, and the number <em>is</em> an even multiple of the rule's divisor, use the 0366 * rule that precedes it in the rule list. Otherwise, use the rule itself.</li> 0367 * </ul> 0368 * 0369 * <p>If the rule set is a fraction rule set, do the following: 0370 * 0371 * <ul> 0372 * <li>Ignore negative-number and fraction rules.</li> 0373 * <li>For each rule in the list, multiply the number being formatted (which will always be 0374 * between 0 and 1) by the rule's base value. Keep track of the distance between the result 0375 * the nearest integer.</li> 0376 * <li>Use the rule that produced the result closest to zero in the above calculation. In the 0377 * event of a tie or a direct hit, use the first matching rule encountered. (The idea here is 0378 * to try each rule's base value as a possible denominator of a fraction. Whichever 0379 * denominator produces the fraction closest in value to the number being formatted wins.) If 0380 * the rule following the matching rule has the same base value, use it if the numerator of 0381 * the fraction is anything other than 1; if the numerator is 1, use the original matching 0382 * rule. (This is to allow singular and plural forms of the rule text without a lot of extra 0383 * hassle.)</li> 0384 * </ul> 0385 * 0386 * <p>A rule's body consists of a string of characters terminated by a semicolon. The rule 0387 * may include zero, one, or two <em>substitution tokens,</em> and a range of text in 0388 * brackets. The brackets denote optional text (and may also include one or both 0389 * substitutions). The exact meanings of the substitution tokens, and under what conditions 0390 * optional text is omitted, depend on the syntax of the substitution token and the context. 0391 * The rest of the text in a rule body is literal text that is output when the rule matches 0392 * the number being formatted.</p> 0393 * 0394 * <p>A substitution token begins and ends with a <em>token character.</em> The token 0395 * character and the context together specify a mathematical operation to be performed on the 0396 * number being formatted. An optional <em>substitution descriptor </em>specifies how the 0397 * value resulting from that operation is used to fill in the substitution. The position of 0398 * the substitution token in the rule body specifies the location of the resultant text in 0399 * the original rule text.</p> 0400 * 0401 * <p>The meanings of the substitution token characters are as follows:</p> 0402 * 0403 * <table border="0" width="100%"> 0404 * <tr> 0405 * <td>>></td> 0406 * <td>in normal rule</td> 0407 * <td>Divide the number by the rule's divisor and format the remainder</td> 0408 * </tr> 0409 * <tr> 0410 * <td></td> 0411 * <td>in negative-number rule</td> 0412 * <td>Find the absolute value of the number and format the result</td> 0413 * </tr> 0414 * <tr> 0415 * <td></td> 0416 * <td>in fraction or default rule</td> 0417 * <td>Isolate the number's fractional part and format it.</td> 0418 * </tr> 0419 * <tr> 0420 * <td></td> 0421 * <td>in rule in fraction rule set</td> 0422 * <td>Not allowed.</td> 0423 * </tr> 0424 * <tr> 0425 * <td>>>></td> 0426 * <td>in normal rule</td> 0427 * <td>Divide the number by the rule's divisor and format the remainder, 0428 * but bypass the normal rule-selection process and just use the 0429 * rule that precedes this one in this rule list.</td> 0430 * </tr> 0431 * <tr> 0432 * <td></td> 0433 * <td>in all other rules</td> 0434 * <td>Not allowed.</td> 0435 * </tr> 0436 * <tr> 0437 * <td><<</td> 0438 * <td>in normal rule</td> 0439 * <td>Divide the number by the rule's divisor, perform floor() on the quotient, 0440 * and format the resulting value.<br> 0441 * If there is a DecimalFormat pattern between the < characters and the 0442 * rule does NOT also contain a >> substitution, we DON'T perform 0443 * floor() on the quotient-- the quotient is passed through to the DecimalFormat 0444 * intact. That is, for the value 1,900:<br> 0445 * - "1/1000: << thousand;" will produce "one thousand"<br> 0446 * - "1/1000: <0< thousand;" will produce "2 thousand" (NOT "1 thousand")<br> 0447 * - "1/1000: <0< seconds >0> milliseconds;" will produce "1 second 900 milliseconds" 0448 * </td> 0449 * </tr> 0450 * <tr> 0451 * <td></td> 0452 * <td>in negative-number rule</td> 0453 * <td>Not allowed.</td> 0454 * </tr> 0455 * <tr> 0456 * <td></td> 0457 * <td>in fraction or default rule</td> 0458 * <td>Isolate the number's integral part and format it.</td> 0459 * </tr> 0460 * <tr> 0461 * <td></td> 0462 * <td>in rule in fraction rule set</td> 0463 * <td>Multiply the number by the rule's base value and format the result.</td> 0464 * </tr> 0465 * <tr> 0466 * <td>==</td> 0467 * <td>in all rule sets</td> 0468 * <td>Format the number unchanged</td> 0469 * </tr> 0470 * <tr> 0471 * <td>[]</td> 0472 * <td>in normal rule</td> 0473 * <td>Omit the optional text if the number is an even multiple of the rule's divisor</td> 0474 * </tr> 0475 * <tr> 0476 * <td></td> 0477 * <td>in negative-number rule</td> 0478 * <td>Not allowed.</td> 0479 * </tr> 0480 * <tr> 0481 * <td></td> 0482 * <td>in improper-fraction rule</td> 0483 * <td>Omit the optional text if the number is between 0 and 1 (same as specifying both an 0484 * x.x rule and a 0.x rule)</td> 0485 * </tr> 0486 * <tr> 0487 * <td></td> 0488 * <td>in default rule</td> 0489 * <td>Omit the optional text if the number is an integer (same as specifying both an x.x 0490 * rule and an x.0 rule)</td> 0491 * </tr> 0492 * <tr> 0493 * <td></td> 0494 * <td>in proper-fraction rule</td> 0495 * <td>Not allowed.</td> 0496 * </tr> 0497 * <tr> 0498 * <td></td> 0499 * <td>in rule in fraction rule set</td> 0500 * <td>Omit the optional text if multiplying the number by the rule's base value yields 1.</td> 0501 * </tr> 0502 * <tr> 0503 * <td width="37">$(cardinal,<i>plural syntax</i>)$</td> 0504 * <td width="23"></td> 0505 * <td width="165" valign="top">in all rule sets</td> 0506 * <td>This provides the ability to choose a word based on the number divided by the radix to the power of the 0507 * exponent of the base value for the specified locale, which is normally equivalent to the << value. 0508 * This uses the cardinal plural rules from PluralFormat. All strings used in the plural format are treated 0509 * as the same base value for parsing.</td> 0510 * </tr> 0511 * <tr> 0512 * <td width="37">$(ordinal,<i>plural syntax</i>)$</td> 0513 * <td width="23"></td> 0514 * <td width="165" valign="top">in all rule sets</td> 0515 * <td>This provides the ability to choose a word based on the number divided by the radix to the power of the 0516 * exponent of the base value for the specified locale, which is normally equivalent to the << value. 0517 * This uses the ordinal plural rules from PluralFormat. All strings used in the plural format are treated 0518 * as the same base value for parsing.</td> 0519 * </tr> 0520 * </table> 0521 * 0522 * <p>The substitution descriptor (i.e., the text between the token characters) may take one 0523 * of three forms:</p> 0524 * 0525 * <table border="0" width="100%"> 0526 * <tr> 0527 * <td>a rule set name</td> 0528 * <td>Perform the mathematical operation on the number, and format the result using the 0529 * named rule set.</td> 0530 * </tr> 0531 * <tr> 0532 * <td>a DecimalFormat pattern</td> 0533 * <td>Perform the mathematical operation on the number, and format the result using a 0534 * DecimalFormat with the specified pattern. The pattern must begin with 0 or #.</td> 0535 * </tr> 0536 * <tr> 0537 * <td>nothing</td> 0538 * <td>Perform the mathematical operation on the number, and format the result using the rule 0539 * set containing the current rule, except: 0540 * <ul> 0541 * <li>You can't have an empty substitution descriptor with a == substitution.</li> 0542 * <li>If you omit the substitution descriptor in a >> substitution in a fraction rule, 0543 * format the result one digit at a time using the rule set containing the current rule.</li> 0544 * <li>If you omit the substitution descriptor in a << substitution in a rule in a 0545 * fraction rule set, format the result using the default rule set for this formatter.</li> 0546 * </ul> 0547 * </td> 0548 * </tr> 0549 * </table> 0550 * 0551 * <p>Whitespace is ignored between a rule set name and a rule set body, between a rule 0552 * descriptor and a rule body, or between rules. If a rule body begins with an apostrophe, 0553 * the apostrophe is ignored, but all text after it becomes significant (this is how you can 0554 * have a rule's rule text begin with whitespace). There is no escape function: the semicolon 0555 * is not allowed in rule set names or in rule text, and the colon is not allowed in rule set 0556 * names. The characters beginning a substitution token are always treated as the beginning 0557 * of a substitution token.</p> 0558 * 0559 * <p>See the resource data and the demo program for annotated examples of real rule sets 0560 * using these features.</p> 0561 * 0562 * <p><em>User subclasses are not supported.</em> While clients may write 0563 * subclasses, such code will not necessarily work and will not be 0564 * guaranteed to work stably from release to release. 0565 * 0566 * <p><b>Localizations</b></p> 0567 * <p>Constructors are available that allow the specification of localizations for the 0568 * public rule sets (and also allow more control over what public rule sets are available). 0569 * Localization data is represented as a textual description. The description represents 0570 * an array of arrays of string. The first element is an array of the public rule set names, 0571 * each of these must be one of the public rule set names that appear in the rules. Only 0572 * names in this array will be treated as public rule set names by the API. Each subsequent 0573 * element is an array of localizations of these names. The first element of one of these 0574 * subarrays is the locale name, and the remaining elements are localizations of the 0575 * public rule set names, in the same order as they were listed in the first array.</p> 0576 * <p>In the syntax, angle brackets '<', '>' are used to delimit the arrays, and comma ',' is used 0577 * to separate elements of an array. Whitespace is ignored, unless quoted.</p> 0578 * <p>For example:<pre> 0579 * < < %foo, %bar, %baz >, 0580 * < en, Foo, Bar, Baz >, 0581 * < fr, 'le Foo', 'le Bar', 'le Baz' > 0582 * < zh, \\u7532, \\u4e59, \\u4e19 > > 0583 * </pre></p> 0584 * @author Richard Gillam 0585 * @see NumberFormat 0586 * @see DecimalFormat 0587 * @see PluralFormat 0588 * @see PluralRules 0589 * @stable ICU 2.0 0590 */ 0591 class U_I18N_API RuleBasedNumberFormat : public NumberFormat { 0592 public: 0593 0594 //----------------------------------------------------------------------- 0595 // constructors 0596 //----------------------------------------------------------------------- 0597 0598 /** 0599 * Creates a RuleBasedNumberFormat that behaves according to the description 0600 * passed in. The formatter uses the default locale. 0601 * @param rules A description of the formatter's desired behavior. 0602 * See the class documentation for a complete explanation of the description 0603 * syntax. 0604 * @param perror The parse error if an error was encountered. 0605 * @param status The status indicating whether the constructor succeeded. 0606 * @stable ICU 3.2 0607 */ 0608 RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status); 0609 0610 /** 0611 * Creates a RuleBasedNumberFormat that behaves according to the description 0612 * passed in. The formatter uses the default locale. 0613 * <p> 0614 * The localizations data provides information about the public 0615 * rule sets and their localized display names for different 0616 * locales. The first element in the list is an array of the names 0617 * of the public rule sets. The first element in this array is 0618 * the initial default ruleset. The remaining elements in the 0619 * list are arrays of localizations of the names of the public 0620 * rule sets. Each of these is one longer than the initial array, 0621 * with the first String being the ULocale ID, and the remaining 0622 * Strings being the localizations of the rule set names, in the 0623 * same order as the initial array. Arrays are nullptr-terminated. 0624 * @param rules A description of the formatter's desired behavior. 0625 * See the class documentation for a complete explanation of the description 0626 * syntax. 0627 * @param localizations the localization information. 0628 * names in the description. These will be copied by the constructor. 0629 * @param perror The parse error if an error was encountered. 0630 * @param status The status indicating whether the constructor succeeded. 0631 * @stable ICU 3.2 0632 */ 0633 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations, 0634 UParseError& perror, UErrorCode& status); 0635 0636 /** 0637 * Creates a RuleBasedNumberFormat that behaves according to the rules 0638 * passed in. The formatter uses the specified locale to determine the 0639 * characters to use when formatting numerals, and to define equivalences 0640 * for lenient parsing. 0641 * @param rules The formatter rules. 0642 * See the class documentation for a complete explanation of the rule 0643 * syntax. 0644 * @param locale A locale that governs which characters are used for 0645 * formatting values in numerals and which characters are equivalent in 0646 * lenient parsing. 0647 * @param perror The parse error if an error was encountered. 0648 * @param status The status indicating whether the constructor succeeded. 0649 * @stable ICU 2.0 0650 */ 0651 RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale, 0652 UParseError& perror, UErrorCode& status); 0653 0654 /** 0655 * Creates a RuleBasedNumberFormat that behaves according to the description 0656 * passed in. The formatter uses the default locale. 0657 * <p> 0658 * The localizations data provides information about the public 0659 * rule sets and their localized display names for different 0660 * locales. The first element in the list is an array of the names 0661 * of the public rule sets. The first element in this array is 0662 * the initial default ruleset. The remaining elements in the 0663 * list are arrays of localizations of the names of the public 0664 * rule sets. Each of these is one longer than the initial array, 0665 * with the first String being the ULocale ID, and the remaining 0666 * Strings being the localizations of the rule set names, in the 0667 * same order as the initial array. Arrays are nullptr-terminated. 0668 * @param rules A description of the formatter's desired behavior. 0669 * See the class documentation for a complete explanation of the description 0670 * syntax. 0671 * @param localizations a list of localizations for the rule set 0672 * names in the description. These will be copied by the constructor. 0673 * @param locale A locale that governs which characters are used for 0674 * formatting values in numerals and which characters are equivalent in 0675 * lenient parsing. 0676 * @param perror The parse error if an error was encountered. 0677 * @param status The status indicating whether the constructor succeeded. 0678 * @stable ICU 3.2 0679 */ 0680 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations, 0681 const Locale& locale, UParseError& perror, UErrorCode& status); 0682 0683 /** 0684 * Creates a RuleBasedNumberFormat from a predefined ruleset. The selector 0685 * code chose among three possible predefined formats: spellout, ordinal, 0686 * and duration. 0687 * @param tag A selector code specifying which kind of formatter to create for that 0688 * locale. There are four legal values: URBNF_SPELLOUT, which creates a formatter that 0689 * spells out a value in words in the desired language, URBNF_ORDINAL, which attaches 0690 * an ordinal suffix from the desired language to the end of a number (e.g. "123rd"), 0691 * URBNF_DURATION, which formats a duration in seconds as hours, minutes, and seconds always rounding down, 0692 * and URBNF_NUMBERING_SYSTEM, which is used to invoke rules for alternate numbering 0693 * systems such as the Hebrew numbering system, or for Roman Numerals, etc. 0694 * NOTE: If you use URBNF_NUMBERING_SYSTEM, you must also call setDefaultRuleSet() to 0695 * specify the exact numbering system you want to use. If you want the default numbering system 0696 * for the locale, call NumberFormat::createInstance() instead of creating a RuleBasedNumberFormat directly. 0697 * @param locale The locale for the formatter. 0698 * @param status The status indicating whether the constructor succeeded. 0699 * @stable ICU 2.0 0700 */ 0701 RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status); 0702 0703 //----------------------------------------------------------------------- 0704 // boilerplate 0705 //----------------------------------------------------------------------- 0706 0707 /** 0708 * Copy constructor 0709 * @param rhs the object to be copied from. 0710 * @stable ICU 2.6 0711 */ 0712 RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs); 0713 0714 /** 0715 * Assignment operator 0716 * @param rhs the object to be copied from. 0717 * @stable ICU 2.6 0718 */ 0719 RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs); 0720 0721 /** 0722 * Release memory allocated for a RuleBasedNumberFormat when you are finished with it. 0723 * @stable ICU 2.6 0724 */ 0725 virtual ~RuleBasedNumberFormat(); 0726 0727 /** 0728 * Clone this object polymorphically. The caller is responsible 0729 * for deleting the result when done. 0730 * @return A copy of the object. 0731 * @stable ICU 2.6 0732 */ 0733 virtual RuleBasedNumberFormat* clone() const override; 0734 0735 /** 0736 * Return true if the given Format objects are semantically equal. 0737 * Objects of different subclasses are considered unequal. 0738 * @param other the object to be compared with. 0739 * @return true if the given Format objects are semantically equal. 0740 * @stable ICU 2.6 0741 */ 0742 virtual bool operator==(const Format& other) const override; 0743 0744 //----------------------------------------------------------------------- 0745 // public API functions 0746 //----------------------------------------------------------------------- 0747 0748 /** 0749 * return the rules that were provided to the RuleBasedNumberFormat. 0750 * @return the result String that was passed in 0751 * @stable ICU 2.0 0752 */ 0753 virtual UnicodeString getRules() const; 0754 0755 /** 0756 * Return the number of public rule set names. 0757 * @return the number of public rule set names. 0758 * @stable ICU 2.0 0759 */ 0760 virtual int32_t getNumberOfRuleSetNames() const; 0761 0762 /** 0763 * Return the name of the index'th public ruleSet. If index is not valid, 0764 * the function returns null. 0765 * @param index the index of the ruleset 0766 * @return the name of the index'th public ruleSet. 0767 * @stable ICU 2.0 0768 */ 0769 virtual UnicodeString getRuleSetName(int32_t index) const; 0770 0771 /** 0772 * Return the number of locales for which we have localized rule set display names. 0773 * @return the number of locales for which we have localized rule set display names. 0774 * @stable ICU 3.2 0775 */ 0776 virtual int32_t getNumberOfRuleSetDisplayNameLocales() const; 0777 0778 /** 0779 * Return the index'th display name locale. 0780 * @param index the index of the locale 0781 * @param status set to a failure code when this function fails 0782 * @return the locale 0783 * @see #getNumberOfRuleSetDisplayNameLocales 0784 * @stable ICU 3.2 0785 */ 0786 virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const; 0787 0788 /** 0789 * Return the rule set display names for the provided locale. These are in the same order 0790 * as those returned by getRuleSetName. The locale is matched against the locales for 0791 * which there is display name data, using normal fallback rules. If no locale matches, 0792 * the default display names are returned. (These are the internal rule set names minus 0793 * the leading '%'.) 0794 * @param index the index of the rule set 0795 * @param locale the locale (returned by getRuleSetDisplayNameLocales) for which the localized 0796 * display name is desired 0797 * @return the display name for the given index, which might be bogus if there is an error 0798 * @see #getRuleSetName 0799 * @stable ICU 3.2 0800 */ 0801 virtual UnicodeString getRuleSetDisplayName(int32_t index, 0802 const Locale& locale = Locale::getDefault()); 0803 0804 /** 0805 * Return the rule set display name for the provided rule set and locale. 0806 * The locale is matched against the locales for which there is display name data, using 0807 * normal fallback rules. If no locale matches, the default display name is returned. 0808 * @return the display name for the rule set 0809 * @stable ICU 3.2 0810 * @see #getRuleSetDisplayName 0811 */ 0812 virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName, 0813 const Locale& locale = Locale::getDefault()); 0814 0815 0816 using NumberFormat::format; 0817 0818 /** 0819 * Formats the specified 32-bit number using the default ruleset. 0820 * @param number The number to format. 0821 * @param toAppendTo the string that will hold the (appended) result 0822 * @param pos the fieldposition 0823 * @return A textual representation of the number. 0824 * @stable ICU 2.0 0825 */ 0826 virtual UnicodeString& format(int32_t number, 0827 UnicodeString& toAppendTo, 0828 FieldPosition& pos) const override; 0829 0830 /** 0831 * Formats the specified 64-bit number using the default ruleset. 0832 * @param number The number to format. 0833 * @param toAppendTo the string that will hold the (appended) result 0834 * @param pos the fieldposition 0835 * @return A textual representation of the number. 0836 * @stable ICU 2.1 0837 */ 0838 virtual UnicodeString& format(int64_t number, 0839 UnicodeString& toAppendTo, 0840 FieldPosition& pos) const override; 0841 /** 0842 * Formats the specified number using the default ruleset. 0843 * @param number The number to format. 0844 * @param toAppendTo the string that will hold the (appended) result 0845 * @param pos the fieldposition 0846 * @return A textual representation of the number. 0847 * @stable ICU 2.0 0848 */ 0849 virtual UnicodeString& format(double number, 0850 UnicodeString& toAppendTo, 0851 FieldPosition& pos) const override; 0852 0853 /** 0854 * Formats the specified number using the named ruleset. 0855 * @param number The number to format. 0856 * @param ruleSetName The name of the rule set to format the number with. 0857 * This must be the name of a valid public rule set for this formatter. 0858 * @param toAppendTo the string that will hold the (appended) result 0859 * @param pos the fieldposition 0860 * @param status the status 0861 * @return A textual representation of the number. 0862 * @stable ICU 2.0 0863 */ 0864 virtual UnicodeString& format(int32_t number, 0865 const UnicodeString& ruleSetName, 0866 UnicodeString& toAppendTo, 0867 FieldPosition& pos, 0868 UErrorCode& status) const; 0869 /** 0870 * Formats the specified 64-bit number using the named ruleset. 0871 * @param number The number to format. 0872 * @param ruleSetName The name of the rule set to format the number with. 0873 * This must be the name of a valid public rule set for this formatter. 0874 * @param toAppendTo the string that will hold the (appended) result 0875 * @param pos the fieldposition 0876 * @param status the status 0877 * @return A textual representation of the number. 0878 * @stable ICU 2.1 0879 */ 0880 virtual UnicodeString& format(int64_t number, 0881 const UnicodeString& ruleSetName, 0882 UnicodeString& toAppendTo, 0883 FieldPosition& pos, 0884 UErrorCode& status) const; 0885 /** 0886 * Formats the specified number using the named ruleset. 0887 * @param number The number to format. 0888 * @param ruleSetName The name of the rule set to format the number with. 0889 * This must be the name of a valid public rule set for this formatter. 0890 * @param toAppendTo the string that will hold the (appended) result 0891 * @param pos the fieldposition 0892 * @param status the status 0893 * @return A textual representation of the number. 0894 * @stable ICU 2.0 0895 */ 0896 virtual UnicodeString& format(double number, 0897 const UnicodeString& ruleSetName, 0898 UnicodeString& toAppendTo, 0899 FieldPosition& pos, 0900 UErrorCode& status) const; 0901 0902 protected: 0903 /** 0904 * Format a decimal number. 0905 * The number is a DigitList wrapper onto a floating point decimal number. 0906 * The default implementation in NumberFormat converts the decimal number 0907 * to a double and formats that. Subclasses of NumberFormat that want 0908 * to specifically handle big decimal numbers must override this method. 0909 * class DecimalFormat does so. 0910 * 0911 * @param number The number, a DigitList format Decimal Floating Point. 0912 * @param appendTo Output parameter to receive result. 0913 * Result is appended to existing contents. 0914 * @param pos On input: an alignment field, if desired. 0915 * On output: the offsets of the alignment field. 0916 * @param status Output param filled with success/failure status. 0917 * @return Reference to 'appendTo' parameter. 0918 * @internal 0919 */ 0920 virtual UnicodeString& format(const number::impl::DecimalQuantity &number, 0921 UnicodeString& appendTo, 0922 FieldPosition& pos, 0923 UErrorCode& status) const override; 0924 public: 0925 0926 using NumberFormat::parse; 0927 0928 /** 0929 * Parses the specified string, beginning at the specified position, according 0930 * to this formatter's rules. This will match the string against all of the 0931 * formatter's public rule sets and return the value corresponding to the longest 0932 * parseable substring. This function's behavior is affected by the lenient 0933 * parse mode. 0934 * @param text The string to parse 0935 * @param result the result of the parse, either a double or a long. 0936 * @param parsePosition On entry, contains the position of the first character 0937 * in "text" to examine. On exit, has been updated to contain the position 0938 * of the first character in "text" that wasn't consumed by the parse. 0939 * @see #setLenient 0940 * @stable ICU 2.0 0941 */ 0942 virtual void parse(const UnicodeString& text, 0943 Formattable& result, 0944 ParsePosition& parsePosition) const override; 0945 0946 #if !UCONFIG_NO_COLLATION 0947 0948 /** 0949 * Turns lenient parse mode on and off. 0950 * 0951 * When in lenient parse mode, the formatter uses a Collator for parsing the text. 0952 * Only primary differences are treated as significant. This means that case 0953 * differences, accent differences, alternate spellings of the same letter 0954 * (e.g., ae and a-umlaut in German), ignorable characters, etc. are ignored in 0955 * matching the text. In many cases, numerals will be accepted in place of words 0956 * or phrases as well. 0957 * 0958 * For example, all of the following will correctly parse as 255 in English in 0959 * lenient-parse mode: 0960 * <br>"two hundred fifty-five" 0961 * <br>"two hundred fifty five" 0962 * <br>"TWO HUNDRED FIFTY-FIVE" 0963 * <br>"twohundredfiftyfive" 0964 * <br>"2 hundred fifty-5" 0965 * 0966 * The Collator used is determined by the locale that was 0967 * passed to this object on construction. The description passed to this object 0968 * on construction may supply additional collation rules that are appended to the 0969 * end of the default collator for the locale, enabling additional equivalences 0970 * (such as adding more ignorable characters or permitting spelled-out version of 0971 * symbols; see the demo program for examples). 0972 * 0973 * It's important to emphasize that even strict parsing is relatively lenient: it 0974 * will accept some text that it won't produce as output. In English, for example, 0975 * it will correctly parse "two hundred zero" and "fifteen hundred". 0976 * 0977 * @param enabled If true, turns lenient-parse mode on; if false, turns it off. 0978 * @see RuleBasedCollator 0979 * @stable ICU 2.0 0980 */ 0981 virtual void setLenient(UBool enabled) override; 0982 0983 /** 0984 * Returns true if lenient-parse mode is turned on. Lenient parsing is off 0985 * by default. 0986 * @return true if lenient-parse mode is turned on. 0987 * @see #setLenient 0988 * @stable ICU 2.0 0989 */ 0990 virtual inline UBool isLenient() const override; 0991 0992 #endif 0993 0994 /** 0995 * Override the default rule set to use. If ruleSetName is null, reset 0996 * to the initial default rule set. If the rule set is not a public rule set name, 0997 * U_ILLEGAL_ARGUMENT_ERROR is returned in status. 0998 * @param ruleSetName the name of the rule set, or null to reset the initial default. 0999 * @param status set to failure code when a problem occurs. 1000 * @stable ICU 2.6 1001 */ 1002 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status); 1003 1004 /** 1005 * Return the name of the current default rule set. If the current rule set is 1006 * not public, returns a bogus (and empty) UnicodeString. 1007 * @return the name of the current default rule set 1008 * @stable ICU 3.0 1009 */ 1010 virtual UnicodeString getDefaultRuleSetName() const; 1011 1012 /** 1013 * Set a particular UDisplayContext value in the formatter, such as 1014 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see 1015 * NumberFormat. 1016 * @param value The UDisplayContext value to set. 1017 * @param status Input/output status. If at entry this indicates a failure 1018 * status, the function will do nothing; otherwise this will be 1019 * updated with any new status from the function. 1020 * @stable ICU 53 1021 */ 1022 virtual void setContext(UDisplayContext value, UErrorCode& status) override; 1023 1024 /** 1025 * Get the rounding mode. 1026 * @return A rounding mode 1027 * @stable ICU 60 1028 */ 1029 virtual ERoundingMode getRoundingMode() const override; 1030 1031 /** 1032 * Set the rounding mode. 1033 * @param roundingMode A rounding mode 1034 * @stable ICU 60 1035 */ 1036 virtual void setRoundingMode(ERoundingMode roundingMode) override; 1037 1038 public: 1039 /** 1040 * ICU "poor man's RTTI", returns a UClassID for this class. 1041 * 1042 * @stable ICU 2.8 1043 */ 1044 static UClassID U_EXPORT2 getStaticClassID(); 1045 1046 /** 1047 * ICU "poor man's RTTI", returns a UClassID for the actual class. 1048 * 1049 * @stable ICU 2.8 1050 */ 1051 virtual UClassID getDynamicClassID() const override; 1052 1053 /** 1054 * Sets the decimal format symbols, which is generally not changed 1055 * by the programmer or user. The formatter takes ownership of 1056 * symbolsToAdopt; the client must not delete it. 1057 * 1058 * @param symbolsToAdopt DecimalFormatSymbols to be adopted. 1059 * @stable ICU 49 1060 */ 1061 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt); 1062 1063 /** 1064 * Sets the decimal format symbols, which is generally not changed 1065 * by the programmer or user. A clone of the symbols is created and 1066 * the symbols is _not_ adopted; the client is still responsible for 1067 * deleting it. 1068 * 1069 * @param symbols DecimalFormatSymbols. 1070 * @stable ICU 49 1071 */ 1072 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols); 1073 1074 private: 1075 RuleBasedNumberFormat() = delete; // default constructor not implemented 1076 1077 // this will ref the localizations if they are not nullptr 1078 // caller must deref to get adoption 1079 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations, 1080 const Locale& locale, UParseError& perror, UErrorCode& status); 1081 1082 void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status); 1083 void initCapitalizationContextInfo(const Locale& thelocale); 1084 void dispose(); 1085 void stripWhitespace(UnicodeString& src); 1086 void initDefaultRuleSet(); 1087 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const; 1088 1089 /* friend access */ 1090 friend class NFSubstitution; 1091 friend class NFRule; 1092 friend class NFRuleSet; 1093 friend class FractionalPartSubstitution; 1094 1095 inline NFRuleSet * getDefaultRuleSet() const; 1096 const RuleBasedCollator * getCollator() const; 1097 DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status); 1098 const DecimalFormatSymbols * getDecimalFormatSymbols() const; 1099 NFRule * initializeDefaultInfinityRule(UErrorCode &status); 1100 const NFRule * getDefaultInfinityRule() const; 1101 NFRule * initializeDefaultNaNRule(UErrorCode &status); 1102 const NFRule * getDefaultNaNRule() const; 1103 PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const; 1104 UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult, UErrorCode& status) const; 1105 UnicodeString& format(int64_t number, NFRuleSet *ruleSet, UnicodeString& toAppendTo, UErrorCode& status) const; 1106 void format(double number, NFRuleSet& rs, UnicodeString& toAppendTo, UErrorCode& status) const; 1107 1108 private: 1109 NFRuleSet **fRuleSets; 1110 UnicodeString* ruleSetDescriptions; 1111 int32_t numRuleSets; 1112 NFRuleSet *defaultRuleSet; 1113 Locale locale; 1114 RuleBasedCollator* collator; 1115 DecimalFormatSymbols* decimalFormatSymbols; 1116 NFRule *defaultInfinityRule; 1117 NFRule *defaultNaNRule; 1118 ERoundingMode fRoundingMode; 1119 UBool lenient; 1120 UnicodeString* lenientParseRules; 1121 LocalizationInfo* localizations; 1122 UnicodeString originalDescription; 1123 UBool capitalizationInfoSet; 1124 UBool capitalizationForUIListMenu; 1125 UBool capitalizationForStandAlone; 1126 BreakIterator* capitalizationBrkIter; 1127 }; 1128 1129 // --------------- 1130 1131 #if !UCONFIG_NO_COLLATION 1132 1133 inline UBool 1134 RuleBasedNumberFormat::isLenient() const { 1135 return lenient; 1136 } 1137 1138 #endif 1139 1140 inline NFRuleSet* 1141 RuleBasedNumberFormat::getDefaultRuleSet() const { 1142 return defaultRuleSet; 1143 } 1144 1145 U_NAMESPACE_END 1146 1147 /* U_HAVE_RBNF */ 1148 #endif 1149 1150 #endif /* U_SHOW_CPLUSPLUS_API */ 1151 1152 /* RBNF_H */ 1153 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|