]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/unicode/rbnf.h
ICU-59180.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / rbnf.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4*******************************************************************************
b331163b 5* Copyright (C) 1997-2015, International Business Machines Corporation and others.
b75a7d8f
A
6* All Rights Reserved.
7*******************************************************************************
8*/
9
10#ifndef RBNF_H
11#define RBNF_H
12
13#include "unicode/utypes.h"
14
73c04bcf 15/**
729e4ab9 16 * \file
73c04bcf
A
17 * \brief C++ API: Rule Based Number Format
18 */
19
374ca955
A
20/**
21 * \def U_HAVE_RBNF
22 * This will be 0 if RBNF support is not included in ICU
23 * and 1 if it is.
24 *
25 * @stable ICU 2.4
26 */
73c04bcf 27#if UCONFIG_NO_FORMATTING
b75a7d8f
A
28#define U_HAVE_RBNF 0
29#else
30#define U_HAVE_RBNF 1
31
b75a7d8f
A
32#include "unicode/dcfmtsym.h"
33#include "unicode/fmtable.h"
34#include "unicode/locid.h"
35#include "unicode/numfmt.h"
36#include "unicode/unistr.h"
374ca955 37#include "unicode/strenum.h"
57a6839d 38#include "unicode/brkiter.h"
b331163b 39#include "unicode/upluralrules.h"
b75a7d8f 40
f3c0d7a5 41#if U_SHOW_CPLUSPLUS_API
b75a7d8f
A
42U_NAMESPACE_BEGIN
43
2ca993e8 44class NFRule;
b75a7d8f 45class NFRuleSet;
374ca955 46class LocalizationInfo;
b331163b 47class PluralFormat;
57a6839d 48class RuleBasedCollator;
b75a7d8f 49
374ca955
A
50/**
51 * Tags for the predefined rulesets.
52 *
53 * @stable ICU 2.2
54 */
b75a7d8f
A
55enum URBNFRuleSetTag {
56 URBNF_SPELLOUT,
57 URBNF_ORDINAL,
58 URBNF_DURATION,
729e4ab9 59 URBNF_NUMBERING_SYSTEM,
f3c0d7a5
A
60#ifndef U_HIDE_DEPRECATED_API
61 /**
62 * One more than the highest normal URBNFRuleSetTag value.
63 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
64 */
b75a7d8f 65 URBNF_COUNT
f3c0d7a5 66#endif // U_HIDE_DEPRECATED_API
b75a7d8f
A
67};
68
b75a7d8f 69/**
73c04bcf 70 * The RuleBasedNumberFormat class formats numbers according to a set of rules. This number formatter is
b75a7d8f
A
71 * typically used for spelling out numeric values in words (e.g., 25,3476 as
72 * "twenty-five thousand three hundred seventy-six" or "vingt-cinq mille trois
73 * cents soixante-seize" or
74 * "fünfundzwanzigtausenddreihundertsechsundsiebzig"), but can also be used for
75 * other complicated formatting tasks, such as formatting a number of seconds as hours,
73c04bcf 76 * minutes and seconds (e.g., 3,730 as "1:02:10").
b75a7d8f
A
77 *
78 * <p>The resources contain three predefined formatters for each locale: spellout, which
79 * spells out a value in words (123 is &quot;one hundred twenty-three&quot;); ordinal, which
80 * appends an ordinal suffix to the end of a numeral (123 is &quot;123rd&quot;); and
81 * duration, which shows a duration in seconds as hours, minutes, and seconds (123 is
82 * &quot;2:03&quot;).&nbsp; The client can also define more specialized <tt>RuleBasedNumberFormat</tt>s
83 * by supplying programmer-defined rule sets.</p>
84 *
85 * <p>The behavior of a <tt>RuleBasedNumberFormat</tt> is specified by a textual description
86 * that is either passed to the constructor as a <tt>String</tt> or loaded from a resource
87 * bundle. In its simplest form, the description consists of a semicolon-delimited list of <em>rules.</em>
88 * Each rule has a string of output text and a value or range of values it is applicable to.
89 * In a typical spellout rule set, the first twenty rules are the words for the numbers from
90 * 0 to 19:</p>
91 *
92 * <pre>zero; one; two; three; four; five; six; seven; eight; nine;
93 * ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen; seventeen; eighteen; nineteen;</pre>
94 *
95 * <p>For larger numbers, we can use the preceding set of rules to format the ones place, and
96 * we only have to supply the words for the multiples of 10:</p>
97 *
98 * <pre> 20: twenty[-&gt;&gt;];
99 * 30: thirty[-&gt;&gt;];
100 * 40: forty[-&gt;&gt;];
101 * 50: fifty[-&gt;&gt;];
102 * 60: sixty[-&gt;&gt;];
103 * 70: seventy[-&gt;&gt;];
104 * 80: eighty[-&gt;&gt;];
105 * 90: ninety[-&gt;&gt;];</pre>
106 *
107 * <p>In these rules, the <em>base value</em> is spelled out explicitly and set off from the
108 * rule's output text with a colon. The rules are in a sorted list, and a rule is applicable
109 * to all numbers from its own base value to one less than the next rule's base value. The
110 * &quot;&gt;&gt;&quot; token is called a <em>substitution</em> and tells the fomatter to
111 * isolate the number's ones digit, format it using this same set of rules, and place the
112 * result at the position of the &quot;&gt;&gt;&quot; token. Text in brackets is omitted if
113 * the number being formatted is an even multiple of 10 (the hyphen is a literal hyphen; 24
114 * is &quot;twenty-four,&quot; not &quot;twenty four&quot;).</p>
115 *
116 * <p>For even larger numbers, we can actually look up several parts of the number in the
117 * list:</p>
118 *
119 * <pre>100: &lt;&lt; hundred[ &gt;&gt;];</pre>
120 *
121 * <p>The &quot;&lt;&lt;&quot; represents a new kind of substitution. The &lt;&lt; isolates
122 * the hundreds digit (and any digits to its left), formats it using this same rule set, and
123 * places the result where the &quot;&lt;&lt;&quot; was. Notice also that the meaning of
124 * &gt;&gt; has changed: it now refers to both the tens and the ones digits. The meaning of
125 * both substitutions depends on the rule's base value. The base value determines the rule's <em>divisor,</em>
126 * which is the highest power of 10 that is less than or equal to the base value (the user
127 * can change this). To fill in the substitutions, the formatter divides the number being
128 * formatted by the divisor. The integral quotient is used to fill in the &lt;&lt;
129 * substitution, and the remainder is used to fill in the &gt;&gt; substitution. The meaning
130 * of the brackets changes similarly: text in brackets is omitted if the value being
131 * formatted is an even multiple of the rule's divisor. The rules are applied recursively, so
132 * if a substitution is filled in with text that includes another substitution, that
133 * substitution is also filled in.</p>
134 *
135 * <p>This rule covers values up to 999, at which point we add another rule:</p>
136 *
137 * <pre>1000: &lt;&lt; thousand[ &gt;&gt;];</pre>
138 *
139 * <p>Again, the meanings of the brackets and substitution tokens shift because the rule's
140 * base value is a higher power of 10, changing the rule's divisor. This rule can actually be
141 * used all the way up to 999,999. This allows us to finish out the rules as follows:</p>
142 *
143 * <pre> 1,000,000: &lt;&lt; million[ &gt;&gt;];
144 * 1,000,000,000: &lt;&lt; billion[ &gt;&gt;];
145 * 1,000,000,000,000: &lt;&lt; trillion[ &gt;&gt;];
146 * 1,000,000,000,000,000: OUT OF RANGE!;</pre>
147 *
148 * <p>Commas, periods, and spaces can be used in the base values to improve legibility and
149 * are ignored by the rule parser. The last rule in the list is customarily treated as an
150 * &quot;overflow rule,&quot; applying to everything from its base value on up, and often (as
151 * in this example) being used to print out an error message or default representation.
152 * Notice also that the size of the major groupings in large numbers is controlled by the
153 * spacing of the rules: because in English we group numbers by thousand, the higher rules
154 * are separated from each other by a factor of 1,000.</p>
155 *
156 * <p>To see how these rules actually work in practice, consider the following example:
157 * Formatting 25,430 with this rule set would work like this:</p>
158 *
159 * <table border="0" width="100%">
160 * <tr>
374ca955 161 * <td><strong>&lt;&lt; thousand &gt;&gt;</strong></td>
b75a7d8f
A
162 * <td>[the rule whose base value is 1,000 is applicable to 25,340]</td>
163 * </tr>
164 * <tr>
165 * <td><strong>twenty-&gt;&gt;</strong> thousand &gt;&gt;</td>
166 * <td>[25,340 over 1,000 is 25. The rule for 20 applies.]</td>
167 * </tr>
168 * <tr>
169 * <td>twenty-<strong>five</strong> thousand &gt;&gt;</td>
170 * <td>[25 mod 10 is 5. The rule for 5 is &quot;five.&quot;</td>
171 * </tr>
172 * <tr>
173 * <td>twenty-five thousand <strong>&lt;&lt; hundred &gt;&gt;</strong></td>
174 * <td>[25,340 mod 1,000 is 340. The rule for 100 applies.]</td>
175 * </tr>
176 * <tr>
177 * <td>twenty-five thousand <strong>three</strong> hundred &gt;&gt;</td>
178 * <td>[340 over 100 is 3. The rule for 3 is &quot;three.&quot;]</td>
179 * </tr>
180 * <tr>
181 * <td>twenty-five thousand three hundred <strong>forty</strong></td>
182 * <td>[340 mod 100 is 40. The rule for 40 applies. Since 40 divides
183 * evenly by 10, the hyphen and substitution in the brackets are omitted.]</td>
184 * </tr>
185 * </table>
186 *
187 * <p>The above syntax suffices only to format positive integers. To format negative numbers,
188 * we add a special rule:</p>
189 *
190 * <pre>-x: minus &gt;&gt;;</pre>
191 *
192 * <p>This is called a <em>negative-number rule,</em> and is identified by &quot;-x&quot;
193 * where the base value would be. This rule is used to format all negative numbers. the
194 * &gt;&gt; token here means &quot;find the number's absolute value, format it with these
195 * rules, and put the result here.&quot;</p>
196 *
197 * <p>We also add a special rule called a <em>fraction rule </em>for numbers with fractional
198 * parts:</p>
199 *
200 * <pre>x.x: &lt;&lt; point &gt;&gt;;</pre>
201 *
202 * <p>This rule is used for all positive non-integers (negative non-integers pass through the
203 * negative-number rule first and then through this rule). Here, the &lt;&lt; token refers to
204 * the number's integral part, and the &gt;&gt; to the number's fractional part. The
205 * fractional part is formatted as a series of single-digit numbers (e.g., 123.456 would be
206 * formatted as &quot;one hundred twenty-three point four five six&quot;).</p>
207 *
208 * <p>To see how this rule syntax is applied to various languages, examine the resource data.</p>
209 *
210 * <p>There is actually much more flexibility built into the rule language than the
211 * description above shows. A formatter may own multiple rule sets, which can be selected by
212 * the caller, and which can use each other to fill in their substitutions. Substitutions can
213 * also be filled in with digits, using a DecimalFormat object. There is syntax that can be
214 * used to alter a rule's divisor in various ways. And there is provision for much more
215 * flexible fraction handling. A complete description of the rule syntax follows:</p>
216 *
217 * <hr>
218 *
219 * <p>The description of a <tt>RuleBasedNumberFormat</tt>'s behavior consists of one or more <em>rule
220 * sets.</em> Each rule set consists of a name, a colon, and a list of <em>rules.</em> A rule
221 * set name must begin with a % sign. Rule sets with names that begin with a single % sign
222 * are <em>public:</em> the caller can specify that they be used to format and parse numbers.
223 * Rule sets with names that begin with %% are <em>private:</em> they exist only for the use
224 * of other rule sets. If a formatter only has one rule set, the name may be omitted.</p>
225 *
226 * <p>The user can also specify a special &quot;rule set&quot; named <tt>%%lenient-parse</tt>.
227 * The body of <tt>%%lenient-parse</tt> isn't a set of number-formatting rules, but a <tt>RuleBasedCollator</tt>
228 * description which is used to define equivalences for lenient parsing. For more information
229 * on the syntax, see <tt>RuleBasedCollator</tt>. For more information on lenient parsing,
230 * see <tt>setLenientParse()</tt>. <em>Note:</em> symbols that have syntactic meaning
231 * in collation rules, such as '&amp;', have no particular meaning when appearing outside
232 * of the <tt>lenient-parse</tt> rule set.</p>
233 *
234 * <p>The body of a rule set consists of an ordered, semicolon-delimited list of <em>rules.</em>
235 * Internally, every rule has a base value, a divisor, rule text, and zero, one, or two <em>substitutions.</em>
236 * These parameters are controlled by the description syntax, which consists of a <em>rule
237 * descriptor,</em> a colon, and a <em>rule body.</em></p>
238 *
239 * <p>A rule descriptor can take one of the following forms (text in <em>italics</em> is the
240 * name of a token):</p>
241 *
242 * <table border="0" width="100%">
243 * <tr>
244 * <td><em>bv</em>:</td>
245 * <td><em>bv</em> specifies the rule's base value. <em>bv</em> is a decimal
246 * number expressed using ASCII digits. <em>bv</em> may contain spaces, period, and commas,
247 * which are ignored. The rule's divisor is the highest power of 10 less than or equal to
248 * the base value.</td>
249 * </tr>
250 * <tr>
251 * <td><em>bv</em>/<em>rad</em>:</td>
252 * <td><em>bv</em> specifies the rule's base value. The rule's divisor is the
253 * highest power of <em>rad</em> less than or equal to the base value.</td>
254 * </tr>
255 * <tr>
256 * <td><em>bv</em>&gt;:</td>
257 * <td><em>bv</em> specifies the rule's base value. To calculate the divisor,
258 * let the radix be 10, and the exponent be the highest exponent of the radix that yields a
259 * result less than or equal to the base value. Every &gt; character after the base value
260 * decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix
261 * raised to the power of the exponent; otherwise, the divisor is 1.</td>
262 * </tr>
263 * <tr>
264 * <td><em>bv</em>/<em>rad</em>&gt;:</td>
265 * <td><em>bv</em> specifies the rule's base value. To calculate the divisor,
266 * let the radix be <em>rad</em>, and the exponent be the highest exponent of the radix that
267 * yields a result less than or equal to the base value. Every &gt; character after the radix
268 * decreases the exponent by 1. If the exponent is positive or 0, the divisor is the radix
269 * raised to the power of the exponent; otherwise, the divisor is 1.</td>
270 * </tr>
271 * <tr>
272 * <td>-x:</td>
273 * <td>The rule is a negative-number rule.</td>
274 * </tr>
275 * <tr>
276 * <td>x.x:</td>
2ca993e8
A
277 * <td>The rule is an <em>improper fraction rule</em>. If the full stop in
278 * the middle of the rule name is replaced with the decimal point
279 * that is used in the language or DecimalFormatSymbols, then that rule will
280 * have precedence when formatting and parsing this rule. For example, some
281 * languages use the comma, and can thus be written as x,x instead. For example,
282 * you can use "x.x: &lt;&lt; point &gt;&gt;;x,x: &lt;&lt; comma &gt;&gt;;" to
283 * handle the decimal point that matches the language's natural spelling of
284 * the punctuation of either the full stop or comma.</td>
b75a7d8f
A
285 * </tr>
286 * <tr>
287 * <td>0.x:</td>
2ca993e8
A
288 * <td>The rule is a <em>proper fraction rule</em>. If the full stop in
289 * the middle of the rule name is replaced with the decimal point
290 * that is used in the language or DecimalFormatSymbols, then that rule will
291 * have precedence when formatting and parsing this rule. For example, some
292 * languages use the comma, and can thus be written as 0,x instead. For example,
293 * you can use "0.x: point &gt;&gt;;0,x: comma &gt;&gt;;" to
294 * handle the decimal point that matches the language's natural spelling of
295 * the punctuation of either the full stop or comma.</td>
b75a7d8f
A
296 * </tr>
297 * <tr>
298 * <td>x.0:</td>
2ca993e8
A
299 * <td>The rule is a <em>master rule</em>. If the full stop in
300 * the middle of the rule name is replaced with the decimal point
301 * that is used in the language or DecimalFormatSymbols, then that rule will
302 * have precedence when formatting and parsing this rule. For example, some
303 * languages use the comma, and can thus be written as x,0 instead. For example,
304 * you can use "x.0: &lt;&lt; point;x,0: &lt;&lt; comma;" to
305 * handle the decimal point that matches the language's natural spelling of
306 * the punctuation of either the full stop or comma.</td>
b75a7d8f
A
307 * </tr>
308 * <tr>
2ca993e8
A
309 * <td>Inf:</td>
310 * <td>The rule for infinity.</td>
311 * </tr>
312 * <tr>
313 * <td>NaN:</td>
314 * <td>The rule for an IEEE 754 NaN (not a number).</td>
315 * </tr>
316 * <tr>
317 * <tr>
b75a7d8f
A
318 * <td><em>nothing</em></td>
319 * <td>If the rule's rule descriptor is left out, the base value is one plus the
320 * preceding rule's base value (or zero if this is the first rule in the list) in a normal
321 * rule set.&nbsp; In a fraction rule set, the base value is the same as the preceding rule's
322 * base value.</td>
323 * </tr>
324 * </table>
325 *
326 * <p>A rule set may be either a regular rule set or a <em>fraction rule set,</em> depending
327 * on whether it is used to format a number's integral part (or the whole number) or a
328 * number's fractional part. Using a rule set to format a rule's fractional part makes it a
329 * fraction rule set.</p>
330 *
331 * <p>Which rule is used to format a number is defined according to one of the following
332 * algorithms: If the rule set is a regular rule set, do the following:
333 *
334 * <ul>
335 * <li>If the rule set includes a master rule (and the number was passed in as a <tt>double</tt>),
336 * use the master rule.&nbsp; (If the number being formatted was passed in as a <tt>long</tt>,
337 * the master rule is ignored.)</li>
338 * <li>If the number is negative, use the negative-number rule.</li>
339 * <li>If the number has a fractional part and is greater than 1, use the improper fraction
340 * rule.</li>
341 * <li>If the number has a fractional part and is between 0 and 1, use the proper fraction
342 * rule.</li>
343 * <li>Binary-search the rule list for the rule with the highest base value less than or equal
344 * to the number. If that rule has two substitutions, its base value is not an even multiple
345 * of its divisor, and the number <em>is</em> an even multiple of the rule's divisor, use the
346 * rule that precedes it in the rule list. Otherwise, use the rule itself.</li>
347 * </ul>
348 *
349 * <p>If the rule set is a fraction rule set, do the following:
350 *
351 * <ul>
352 * <li>Ignore negative-number and fraction rules.</li>
353 * <li>For each rule in the list, multiply the number being formatted (which will always be
354 * between 0 and 1) by the rule's base value. Keep track of the distance between the result
355 * the nearest integer.</li>
356 * <li>Use the rule that produced the result closest to zero in the above calculation. In the
357 * event of a tie or a direct hit, use the first matching rule encountered. (The idea here is
358 * to try each rule's base value as a possible denominator of a fraction. Whichever
359 * denominator produces the fraction closest in value to the number being formatted wins.) If
360 * the rule following the matching rule has the same base value, use it if the numerator of
361 * the fraction is anything other than 1; if the numerator is 1, use the original matching
362 * rule. (This is to allow singular and plural forms of the rule text without a lot of extra
363 * hassle.)</li>
364 * </ul>
365 *
366 * <p>A rule's body consists of a string of characters terminated by a semicolon. The rule
367 * may include zero, one, or two <em>substitution tokens,</em> and a range of text in
368 * brackets. The brackets denote optional text (and may also include one or both
369 * substitutions). The exact meanings of the substitution tokens, and under what conditions
370 * optional text is omitted, depend on the syntax of the substitution token and the context.
371 * The rest of the text in a rule body is literal text that is output when the rule matches
372 * the number being formatted.</p>
373 *
374 * <p>A substitution token begins and ends with a <em>token character.</em> The token
375 * character and the context together specify a mathematical operation to be performed on the
376 * number being formatted. An optional <em>substitution descriptor </em>specifies how the
377 * value resulting from that operation is used to fill in the substitution. The position of
378 * the substitution token in the rule body specifies the location of the resultant text in
379 * the original rule text.</p>
380 *
381 * <p>The meanings of the substitution token characters are as follows:</p>
382 *
383 * <table border="0" width="100%">
384 * <tr>
385 * <td>&gt;&gt;</td>
386 * <td>in normal rule</td>
387 * <td>Divide the number by the rule's divisor and format the remainder</td>
388 * </tr>
389 * <tr>
390 * <td></td>
391 * <td>in negative-number rule</td>
392 * <td>Find the absolute value of the number and format the result</td>
393 * </tr>
394 * <tr>
395 * <td></td>
396 * <td>in fraction or master rule</td>
397 * <td>Isolate the number's fractional part and format it.</td>
398 * </tr>
399 * <tr>
400 * <td></td>
401 * <td>in rule in fraction rule set</td>
402 * <td>Not allowed.</td>
403 * </tr>
404 * <tr>
405 * <td>&gt;&gt;&gt;</td>
406 * <td>in normal rule</td>
407 * <td>Divide the number by the rule's divisor and format the remainder,
408 * but bypass the normal rule-selection process and just use the
409 * rule that precedes this one in this rule list.</td>
410 * </tr>
411 * <tr>
412 * <td></td>
413 * <td>in all other rules</td>
414 * <td>Not allowed.</td>
415 * </tr>
416 * <tr>
417 * <td>&lt;&lt;</td>
418 * <td>in normal rule</td>
419 * <td>Divide the number by the rule's divisor and format the quotient</td>
420 * </tr>
421 * <tr>
422 * <td></td>
423 * <td>in negative-number rule</td>
424 * <td>Not allowed.</td>
425 * </tr>
426 * <tr>
427 * <td></td>
428 * <td>in fraction or master rule</td>
429 * <td>Isolate the number's integral part and format it.</td>
430 * </tr>
431 * <tr>
432 * <td></td>
433 * <td>in rule in fraction rule set</td>
434 * <td>Multiply the number by the rule's base value and format the result.</td>
435 * </tr>
436 * <tr>
437 * <td>==</td>
438 * <td>in all rule sets</td>
439 * <td>Format the number unchanged</td>
440 * </tr>
441 * <tr>
442 * <td>[]</td>
443 * <td>in normal rule</td>
444 * <td>Omit the optional text if the number is an even multiple of the rule's divisor</td>
445 * </tr>
446 * <tr>
447 * <td></td>
448 * <td>in negative-number rule</td>
449 * <td>Not allowed.</td>
450 * </tr>
451 * <tr>
452 * <td></td>
453 * <td>in improper-fraction rule</td>
454 * <td>Omit the optional text if the number is between 0 and 1 (same as specifying both an
455 * x.x rule and a 0.x rule)</td>
456 * </tr>
457 * <tr>
458 * <td></td>
459 * <td>in master rule</td>
460 * <td>Omit the optional text if the number is an integer (same as specifying both an x.x
461 * rule and an x.0 rule)</td>
462 * </tr>
463 * <tr>
464 * <td></td>
465 * <td>in proper-fraction rule</td>
466 * <td>Not allowed.</td>
467 * </tr>
468 * <tr>
469 * <td></td>
470 * <td>in rule in fraction rule set</td>
471 * <td>Omit the optional text if multiplying the number by the rule's base value yields 1.</td>
472 * </tr>
b331163b
A
473 * <tr>
474 * <td width="37">$(cardinal,<i>plural syntax</i>)$</td>
475 * <td width="23"></td>
476 * <td width="165" valign="top">in all rule sets</td>
477 * <td>This provides the ability to choose a word based on the number divided by the radix to the power of the
478 * exponent of the base value for the specified locale, which is normally equivalent to the &lt;&lt; value.
479 * This uses the cardinal plural rules from PluralFormat. All strings used in the plural format are treated
480 * as the same base value for parsing.</td>
481 * </tr>
482 * <tr>
483 * <td width="37">$(ordinal,<i>plural syntax</i>)$</td>
484 * <td width="23"></td>
485 * <td width="165" valign="top">in all rule sets</td>
486 * <td>This provides the ability to choose a word based on the number divided by the radix to the power of the
487 * exponent of the base value for the specified locale, which is normally equivalent to the &lt;&lt; value.
488 * This uses the ordinal plural rules from PluralFormat. All strings used in the plural format are treated
489 * as the same base value for parsing.</td>
490 * </tr>
b75a7d8f
A
491 * </table>
492 *
493 * <p>The substitution descriptor (i.e., the text between the token characters) may take one
494 * of three forms:</p>
495 *
496 * <table border="0" width="100%">
497 * <tr>
498 * <td>a rule set name</td>
499 * <td>Perform the mathematical operation on the number, and format the result using the
500 * named rule set.</td>
501 * </tr>
502 * <tr>
503 * <td>a DecimalFormat pattern</td>
504 * <td>Perform the mathematical operation on the number, and format the result using a
505 * DecimalFormat with the specified pattern.&nbsp; The pattern must begin with 0 or #.</td>
506 * </tr>
507 * <tr>
508 * <td>nothing</td>
509 * <td>Perform the mathematical operation on the number, and format the result using the rule
374ca955
A
510 * set containing the current rule, except:
511 * <ul>
b75a7d8f
A
512 * <li>You can't have an empty substitution descriptor with a == substitution.</li>
513 * <li>If you omit the substitution descriptor in a &gt;&gt; substitution in a fraction rule,
514 * format the result one digit at a time using the rule set containing the current rule.</li>
515 * <li>If you omit the substitution descriptor in a &lt;&lt; substitution in a rule in a
516 * fraction rule set, format the result using the default rule set for this formatter.</li>
517 * </ul>
518 * </td>
519 * </tr>
520 * </table>
521 *
522 * <p>Whitespace is ignored between a rule set name and a rule set body, between a rule
523 * descriptor and a rule body, or between rules. If a rule body begins with an apostrophe,
524 * the apostrophe is ignored, but all text after it becomes significant (this is how you can
525 * have a rule's rule text begin with whitespace). There is no escape function: the semicolon
526 * is not allowed in rule set names or in rule text, and the colon is not allowed in rule set
527 * names. The characters beginning a substitution token are always treated as the beginning
528 * of a substitution token.</p>
529 *
530 * <p>See the resource data and the demo program for annotated examples of real rule sets
531 * using these features.</p>
532 *
374ca955
A
533 * <p><em>User subclasses are not supported.</em> While clients may write
534 * subclasses, such code will not necessarily work and will not be
535 * guaranteed to work stably from release to release.
536 *
537 * <p><b>Localizations</b></p>
538 * <p>Constructors are available that allow the specification of localizations for the
539 * public rule sets (and also allow more control over what public rule sets are available).
540 * Localization data is represented as a textual description. The description represents
541 * an array of arrays of string. The first element is an array of the public rule set names,
542 * each of these must be one of the public rule set names that appear in the rules. Only
543 * names in this array will be treated as public rule set names by the API. Each subsequent
544 * element is an array of localizations of these names. The first element of one of these
545 * subarrays is the locale name, and the remaining elements are localizations of the
546 * public rule set names, in the same order as they were listed in the first arrray.</p>
547 * <p>In the syntax, angle brackets '<', '>' are used to delimit the arrays, and comma ',' is used
548 * to separate elements of an array. Whitespace is ignored, unless quoted.</p>
549 * <p>For example:<pre>
729e4ab9
A
550 * < < %foo, %bar, %baz >,
551 * < en, Foo, Bar, Baz >,
552 * < fr, 'le Foo', 'le Bar', 'le Baz' >
374ca955
A
553 * < zh, \\u7532, \\u4e59, \\u4e19 > >
554 * </pre></p>
b75a7d8f
A
555 * @author Richard Gillam
556 * @see NumberFormat
557 * @see DecimalFormat
b331163b
A
558 * @see PluralFormat
559 * @see PluralRules
b75a7d8f
A
560 * @stable ICU 2.0
561 */
562class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
563public:
564
565 //-----------------------------------------------------------------------
566 // constructors
567 //-----------------------------------------------------------------------
568
374ca955
A
569 /**
570 * Creates a RuleBasedNumberFormat that behaves according to the description
571 * passed in. The formatter uses the default locale.
572 * @param rules A description of the formatter's desired behavior.
573 * See the class documentation for a complete explanation of the description
574 * syntax.
575 * @param perror The parse error if an error was encountered.
576 * @param status The status indicating whether the constructor succeeded.
73c04bcf 577 * @stable ICU 3.2
374ca955
A
578 */
579 RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
580
581 /**
582 * Creates a RuleBasedNumberFormat that behaves according to the description
729e4ab9 583 * passed in. The formatter uses the default locale.
374ca955
A
584 * <p>
585 * The localizations data provides information about the public
586 * rule sets and their localized display names for different
587 * locales. The first element in the list is an array of the names
588 * of the public rule sets. The first element in this array is
589 * the initial default ruleset. The remaining elements in the
590 * list are arrays of localizations of the names of the public
591 * rule sets. Each of these is one longer than the initial array,
592 * with the first String being the ULocale ID, and the remaining
593 * Strings being the localizations of the rule set names, in the
594 * same order as the initial array. Arrays are NULL-terminated.
595 * @param rules A description of the formatter's desired behavior.
596 * See the class documentation for a complete explanation of the description
597 * syntax.
598 * @param localizations the localization information.
599 * names in the description. These will be copied by the constructor.
600 * @param perror The parse error if an error was encountered.
601 * @param status The status indicating whether the constructor succeeded.
73c04bcf 602 * @stable ICU 3.2
374ca955
A
603 */
604 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
605 UParseError& perror, UErrorCode& status);
606
b75a7d8f
A
607 /**
608 * Creates a RuleBasedNumberFormat that behaves according to the rules
609 * passed in. The formatter uses the specified locale to determine the
610 * characters to use when formatting numerals, and to define equivalences
611 * for lenient parsing.
612 * @param rules The formatter rules.
613 * See the class documentation for a complete explanation of the rule
614 * syntax.
374ca955
A
615 * @param locale A locale that governs which characters are used for
616 * formatting values in numerals and which characters are equivalent in
b75a7d8f
A
617 * lenient parsing.
618 * @param perror The parse error if an error was encountered.
619 * @param status The status indicating whether the constructor succeeded.
620 * @stable ICU 2.0
621 */
374ca955 622 RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
b75a7d8f
A
623 UParseError& perror, UErrorCode& status);
624
374ca955
A
625 /**
626 * Creates a RuleBasedNumberFormat that behaves according to the description
729e4ab9 627 * passed in. The formatter uses the default locale.
374ca955
A
628 * <p>
629 * The localizations data provides information about the public
630 * rule sets and their localized display names for different
631 * locales. The first element in the list is an array of the names
632 * of the public rule sets. The first element in this array is
633 * the initial default ruleset. The remaining elements in the
634 * list are arrays of localizations of the names of the public
635 * rule sets. Each of these is one longer than the initial array,
636 * with the first String being the ULocale ID, and the remaining
637 * Strings being the localizations of the rule set names, in the
638 * same order as the initial array. Arrays are NULL-terminated.
639 * @param rules A description of the formatter's desired behavior.
640 * See the class documentation for a complete explanation of the description
641 * syntax.
642 * @param localizations a list of localizations for the rule set
643 * names in the description. These will be copied by the constructor.
644 * @param locale A locale that governs which characters are used for
645 * formatting values in numerals and which characters are equivalent in
646 * lenient parsing.
647 * @param perror The parse error if an error was encountered.
648 * @param status The status indicating whether the constructor succeeded.
73c04bcf 649 * @stable ICU 3.2
374ca955
A
650 */
651 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
652 const Locale& locale, UParseError& perror, UErrorCode& status);
653
b75a7d8f
A
654 /**
655 * Creates a RuleBasedNumberFormat from a predefined ruleset. The selector
656 * code choosed among three possible predefined formats: spellout, ordinal,
657 * and duration.
658 * @param tag A selector code specifying which kind of formatter to create for that
729e4ab9 659 * locale. There are four legal values: URBNF_SPELLOUT, which creates a formatter that
b75a7d8f
A
660 * spells out a value in words in the desired language, URBNF_ORDINAL, which attaches
661 * an ordinal suffix from the desired language to the end of a number (e.g. "123rd"),
b331163b 662 * URBNF_DURATION, which formats a duration in seconds as hours, minutes, and seconds always rounding down,
729e4ab9
A
663 * and URBNF_NUMBERING_SYSTEM, which is used to invoke rules for alternate numbering
664 * systems such as the Hebrew numbering system, or for Roman Numerals, etc.
b75a7d8f
A
665 * @param locale The locale for the formatter.
666 * @param status The status indicating whether the constructor succeeded.
667 * @stable ICU 2.0
668 */
669 RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
670
671 //-----------------------------------------------------------------------
672 // boilerplate
673 //-----------------------------------------------------------------------
674
675 /**
676 * Copy constructor
677 * @param rhs the object to be copied from.
678 * @stable ICU 2.6
679 */
680 RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
681
682 /**
683 * Assignment operator
684 * @param rhs the object to be copied from.
685 * @stable ICU 2.6
686 */
687 RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
688
689 /**
690 * Release memory allocated for a RuleBasedNumberFormat when you are finished with it.
691 * @stable ICU 2.6
692 */
693 virtual ~RuleBasedNumberFormat();
694
695 /**
696 * Clone this object polymorphically. The caller is responsible
697 * for deleting the result when done.
698 * @return A copy of the object.
699 * @stable ICU 2.6
700 */
701 virtual Format* clone(void) const;
702
703 /**
704 * Return true if the given Format objects are semantically equal.
705 * Objects of different subclasses are considered unequal.
706 * @param other the object to be compared with.
707 * @return true if the given Format objects are semantically equal.
708 * @stable ICU 2.6
709 */
710 virtual UBool operator==(const Format& other) const;
711
712//-----------------------------------------------------------------------
713// public API functions
714//-----------------------------------------------------------------------
715
716 /**
717 * return the rules that were provided to the RuleBasedNumberFormat.
718 * @return the result String that was passed in
719 * @stable ICU 2.0
720 */
721 virtual UnicodeString getRules() const;
722
374ca955
A
723 /**
724 * Return the number of public rule set names.
725 * @return the number of public rule set names.
726 * @stable ICU 2.0
727 */
728 virtual int32_t getNumberOfRuleSetNames() const;
729
b75a7d8f
A
730 /**
731 * Return the name of the index'th public ruleSet. If index is not valid,
732 * the function returns null.
733 * @param index the index of the ruleset
734 * @return the name of the index'th public ruleSet.
735 * @stable ICU 2.0
736 */
737 virtual UnicodeString getRuleSetName(int32_t index) const;
738
739 /**
374ca955
A
740 * Return the number of locales for which we have localized rule set display names.
741 * @return the number of locales for which we have localized rule set display names.
73c04bcf 742 * @stable ICU 3.2
b75a7d8f 743 */
374ca955
A
744 virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
745
746 /**
747 * Return the index'th display name locale.
748 * @param index the index of the locale
749 * @param status set to a failure code when this function fails
750 * @return the locale
751 * @see #getNumberOfRuleSetDisplayNameLocales
73c04bcf 752 * @stable ICU 3.2
374ca955
A
753 */
754 virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
755
756 /**
757 * Return the rule set display names for the provided locale. These are in the same order
758 * as those returned by getRuleSetName. The locale is matched against the locales for
729e4ab9 759 * which there is display name data, using normal fallback rules. If no locale matches,
374ca955
A
760 * the default display names are returned. (These are the internal rule set names minus
761 * the leading '%'.)
762 * @param index the index of the rule set
763 * @param locale the locale (returned by getRuleSetDisplayNameLocales) for which the localized
764 * display name is desired
765 * @return the display name for the given index, which might be bogus if there is an error
766 * @see #getRuleSetName
73c04bcf 767 * @stable ICU 3.2
374ca955 768 */
729e4ab9 769 virtual UnicodeString getRuleSetDisplayName(int32_t index,
374ca955
A
770 const Locale& locale = Locale::getDefault());
771
772 /**
729e4ab9 773 * Return the rule set display name for the provided rule set and locale.
374ca955
A
774 * The locale is matched against the locales for which there is display name data, using
775 * normal fallback rules. If no locale matches, the default display name is returned.
776 * @return the display name for the rule set
73c04bcf
A
777 * @stable ICU 3.2
778 * @see #getRuleSetDisplayName
374ca955 779 */
729e4ab9 780 virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
374ca955 781 const Locale& locale = Locale::getDefault());
b75a7d8f 782
729e4ab9
A
783
784 using NumberFormat::format;
785
b75a7d8f
A
786 /**
787 * Formats the specified 32-bit number using the default ruleset.
788 * @param number The number to format.
789 * @param toAppendTo the string that will hold the (appended) result
790 * @param pos the fieldposition
791 * @return A textual representation of the number.
792 * @stable ICU 2.0
793 */
794 virtual UnicodeString& format(int32_t number,
795 UnicodeString& toAppendTo,
796 FieldPosition& pos) const;
797
798 /**
799 * Formats the specified 64-bit number using the default ruleset.
800 * @param number The number to format.
801 * @param toAppendTo the string that will hold the (appended) result
802 * @param pos the fieldposition
803 * @return A textual representation of the number.
804 * @stable ICU 2.1
805 */
806 virtual UnicodeString& format(int64_t number,
807 UnicodeString& toAppendTo,
808 FieldPosition& pos) const;
809 /**
810 * Formats the specified number using the default ruleset.
811 * @param number The number to format.
812 * @param toAppendTo the string that will hold the (appended) result
813 * @param pos the fieldposition
814 * @return A textual representation of the number.
815 * @stable ICU 2.0
816 */
817 virtual UnicodeString& format(double number,
818 UnicodeString& toAppendTo,
819 FieldPosition& pos) const;
820
821 /**
822 * Formats the specified number using the named ruleset.
823 * @param number The number to format.
824 * @param ruleSetName The name of the rule set to format the number with.
825 * This must be the name of a valid public rule set for this formatter.
826 * @param toAppendTo the string that will hold the (appended) result
827 * @param pos the fieldposition
828 * @param status the status
829 * @return A textual representation of the number.
830 * @stable ICU 2.0
831 */
832 virtual UnicodeString& format(int32_t number,
833 const UnicodeString& ruleSetName,
834 UnicodeString& toAppendTo,
835 FieldPosition& pos,
836 UErrorCode& status) const;
837 /**
838 * Formats the specified 64-bit number using the named ruleset.
839 * @param number The number to format.
840 * @param ruleSetName The name of the rule set to format the number with.
841 * This must be the name of a valid public rule set for this formatter.
842 * @param toAppendTo the string that will hold the (appended) result
843 * @param pos the fieldposition
844 * @param status the status
845 * @return A textual representation of the number.
846 * @stable ICU 2.1
847 */
848 virtual UnicodeString& format(int64_t number,
849 const UnicodeString& ruleSetName,
850 UnicodeString& toAppendTo,
851 FieldPosition& pos,
852 UErrorCode& status) const;
853 /**
854 * Formats the specified number using the named ruleset.
855 * @param number The number to format.
856 * @param ruleSetName The name of the rule set to format the number with.
857 * This must be the name of a valid public rule set for this formatter.
858 * @param toAppendTo the string that will hold the (appended) result
859 * @param pos the fieldposition
860 * @param status the status
861 * @return A textual representation of the number.
862 * @stable ICU 2.0
863 */
864 virtual UnicodeString& format(double number,
865 const UnicodeString& ruleSetName,
866 UnicodeString& toAppendTo,
867 FieldPosition& pos,
868 UErrorCode& status) const;
869
f3c0d7a5
A
870protected:
871 /**
872 * Format a decimal number.
873 * The number is a DigitList wrapper onto a floating point decimal number.
874 * The default implementation in NumberFormat converts the decimal number
875 * to a double and formats that. Subclasses of NumberFormat that want
876 * to specifically handle big decimal numbers must override this method.
877 * class DecimalFormat does so.
878 *
879 * @param number The number, a DigitList format Decimal Floating Point.
880 * @param appendTo Output parameter to receive result.
881 * Result is appended to existing contents.
882 * @param posIter On return, can be used to iterate over positions
883 * of fields generated by this format call.
884 * @param status Output param filled with success/failure status.
885 * @return Reference to 'appendTo' parameter.
886 * @internal
887 */
888 virtual UnicodeString& format(const DigitList &number,
889 UnicodeString& appendTo,
890 FieldPositionIterator* posIter,
891 UErrorCode& status) const;
892
893 /**
894 * Format a decimal number.
895 * The number is a DigitList wrapper onto a floating point decimal number.
896 * The default implementation in NumberFormat converts the decimal number
897 * to a double and formats that. Subclasses of NumberFormat that want
898 * to specifically handle big decimal numbers must override this method.
899 * class DecimalFormat does so.
900 *
901 * @param number The number, a DigitList format Decimal Floating Point.
902 * @param appendTo Output parameter to receive result.
903 * Result is appended to existing contents.
904 * @param pos On input: an alignment field, if desired.
905 * On output: the offsets of the alignment field.
906 * @param status Output param filled with success/failure status.
907 * @return Reference to 'appendTo' parameter.
908 * @internal
909 */
910 virtual UnicodeString& format(const DigitList &number,
911 UnicodeString& appendTo,
912 FieldPosition& pos,
913 UErrorCode& status) const;
914public:
915
57a6839d 916 using NumberFormat::parse;
b75a7d8f
A
917
918 /**
919 * Parses the specfied string, beginning at the specified position, according
920 * to this formatter's rules. This will match the string against all of the
921 * formatter's public rule sets and return the value corresponding to the longest
922 * parseable substring. This function's behavior is affected by the lenient
923 * parse mode.
924 * @param text The string to parse
925 * @param result the result of the parse, either a double or a long.
926 * @param parsePosition On entry, contains the position of the first character
927 * in "text" to examine. On exit, has been updated to contain the position
928 * of the first character in "text" that wasn't consumed by the parse.
73c04bcf 929 * @see #setLenient
b75a7d8f
A
930 * @stable ICU 2.0
931 */
932 virtual void parse(const UnicodeString& text,
933 Formattable& result,
934 ParsePosition& parsePosition) const;
935
b75a7d8f
A
936#if !UCONFIG_NO_COLLATION
937
938 /**
939 * Turns lenient parse mode on and off.
940 *
941 * When in lenient parse mode, the formatter uses a Collator for parsing the text.
942 * Only primary differences are treated as significant. This means that case
943 * differences, accent differences, alternate spellings of the same letter
944 * (e.g., ae and a-umlaut in German), ignorable characters, etc. are ignored in
945 * matching the text. In many cases, numerals will be accepted in place of words
946 * or phrases as well.
947 *
948 * For example, all of the following will correctly parse as 255 in English in
949 * lenient-parse mode:
950 * <br>"two hundred fifty-five"
951 * <br>"two hundred fifty five"
952 * <br>"TWO HUNDRED FIFTY-FIVE"
953 * <br>"twohundredfiftyfive"
954 * <br>"2 hundred fifty-5"
955 *
956 * The Collator used is determined by the locale that was
957 * passed to this object on construction. The description passed to this object
958 * on construction may supply additional collation rules that are appended to the
959 * end of the default collator for the locale, enabling additional equivalences
960 * (such as adding more ignorable characters or permitting spelled-out version of
961 * symbols; see the demo program for examples).
962 *
963 * It's important to emphasize that even strict parsing is relatively lenient: it
964 * will accept some text that it won't produce as output. In English, for example,
965 * it will correctly parse "two hundred zero" and "fifteen hundred".
966 *
967 * @param enabled If true, turns lenient-parse mode on; if false, turns it off.
968 * @see RuleBasedCollator
969 * @stable ICU 2.0
970 */
971 virtual void setLenient(UBool enabled);
972
973 /**
974 * Returns true if lenient-parse mode is turned on. Lenient parsing is off
975 * by default.
976 * @return true if lenient-parse mode is turned on.
73c04bcf 977 * @see #setLenient
b75a7d8f
A
978 * @stable ICU 2.0
979 */
980 virtual inline UBool isLenient(void) const;
981
982#endif
983
984 /**
985 * Override the default rule set to use. If ruleSetName is null, reset
986 * to the initial default rule set. If the rule set is not a public rule set name,
987 * U_ILLEGAL_ARGUMENT_ERROR is returned in status.
988 * @param ruleSetName the name of the rule set, or null to reset the initial default.
374ca955
A
989 * @param status set to failure code when a problem occurs.
990 * @stable ICU 2.6
b75a7d8f
A
991 */
992 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
993
374ca955
A
994 /**
995 * Return the name of the current default rule set. If the current rule set is
996 * not public, returns a bogus (and empty) UnicodeString.
997 * @return the name of the current default rule set
73c04bcf 998 * @stable ICU 3.0
374ca955
A
999 */
1000 virtual UnicodeString getDefaultRuleSetName() const;
b75a7d8f 1001
57a6839d
A
1002 /**
1003 * Set a particular UDisplayContext value in the formatter, such as
1004 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see
1005 * NumberFormat.
1006 * @param value The UDisplayContext value to set.
1007 * @param status Input/output status. If at entry this indicates a failure
1008 * status, the function will do nothing; otherwise this will be
1009 * updated with any new status from the function.
b331163b 1010 * @stable ICU 53
57a6839d
A
1011 */
1012 virtual void setContext(UDisplayContext value, UErrorCode& status);
1013
374ca955
A
1014public:
1015 /**
1016 * ICU "poor man's RTTI", returns a UClassID for this class.
1017 *
1018 * @stable ICU 2.8
1019 */
1020 static UClassID U_EXPORT2 getStaticClassID(void);
b75a7d8f 1021
374ca955
A
1022 /**
1023 * ICU "poor man's RTTI", returns a UClassID for the actual class.
1024 *
1025 * @stable ICU 2.8
1026 */
1027 virtual UClassID getDynamicClassID(void) const;
b75a7d8f 1028
4388f060
A
1029 /**
1030 * Sets the decimal format symbols, which is generally not changed
1031 * by the programmer or user. The formatter takes ownership of
1032 * symbolsToAdopt; the client must not delete it.
1033 *
1034 * @param symbolsToAdopt DecimalFormatSymbols to be adopted.
51004dcb 1035 * @stable ICU 49
4388f060
A
1036 */
1037 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
1038
1039 /**
1040 * Sets the decimal format symbols, which is generally not changed
1041 * by the programmer or user. A clone of the symbols is created and
1042 * the symbols is _not_ adopted; the client is still responsible for
1043 * deleting it.
1044 *
1045 * @param symbols DecimalFormatSymbols.
51004dcb 1046 * @stable ICU 49
4388f060
A
1047 */
1048 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1049
b75a7d8f 1050private:
374ca955 1051 RuleBasedNumberFormat(); // default constructor not implemented
b75a7d8f 1052
374ca955 1053 // this will ref the localizations if they are not NULL
729e4ab9
A
1054 // caller must deref to get adoption
1055 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
374ca955
A
1056 const Locale& locale, UParseError& perror, UErrorCode& status);
1057
1058 void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
57a6839d 1059 void initCapitalizationContextInfo(const Locale& thelocale);
374ca955
A
1060 void dispose();
1061 void stripWhitespace(UnicodeString& src);
1062 void initDefaultRuleSet();
1063 void format(double number, NFRuleSet& ruleSet);
1064 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
1065
1066 /* friend access */
1067 friend class NFSubstitution;
1068 friend class NFRule;
2ca993e8 1069 friend class NFRuleSet;
374ca955
A
1070 friend class FractionalPartSubstitution;
1071
1072 inline NFRuleSet * getDefaultRuleSet() const;
57a6839d 1073 const RuleBasedCollator * getCollator() const;
2ca993e8
A
1074 DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status);
1075 const DecimalFormatSymbols * getDecimalFormatSymbols() const;
1076 NFRule * initializeDefaultInfinityRule(UErrorCode &status);
1077 const NFRule * getDefaultInfinityRule() const;
1078 NFRule * initializeDefaultNaNRule(UErrorCode &status);
1079 const NFRule * getDefaultNaNRule() const;
b331163b 1080 PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
f3c0d7a5
A
1081 UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult, UErrorCode& status) const;
1082 UnicodeString& format(int64_t number, NFRuleSet *ruleSet, UnicodeString& toAppendTo, UErrorCode& status) const;
b75a7d8f
A
1083
1084private:
1085 NFRuleSet **ruleSets;
4388f060
A
1086 UnicodeString* ruleSetDescriptions;
1087 int32_t numRuleSets;
b75a7d8f
A
1088 NFRuleSet *defaultRuleSet;
1089 Locale locale;
57a6839d 1090 RuleBasedCollator* collator;
b75a7d8f 1091 DecimalFormatSymbols* decimalFormatSymbols;
2ca993e8
A
1092 NFRule *defaultInfinityRule;
1093 NFRule *defaultNaNRule;
b75a7d8f
A
1094 UBool lenient;
1095 UnicodeString* lenientParseRules;
374ca955 1096 LocalizationInfo* localizations;
57a6839d
A
1097 UnicodeString originalDescription;
1098 UBool capitalizationInfoSet;
1099 UBool capitalizationForUIListMenu;
1100 UBool capitalizationForStandAlone;
1101 BreakIterator* capitalizationBrkIter;
b75a7d8f
A
1102};
1103
1104// ---------------
1105
b75a7d8f
A
1106#if !UCONFIG_NO_COLLATION
1107
374ca955
A
1108inline UBool
1109RuleBasedNumberFormat::isLenient(void) const {
1110 return lenient;
b75a7d8f
A
1111}
1112
1113#endif
1114
374ca955
A
1115inline NFRuleSet*
1116RuleBasedNumberFormat::getDefaultRuleSet() const {
1117 return defaultRuleSet;
b75a7d8f
A
1118}
1119
1120U_NAMESPACE_END
f3c0d7a5 1121#endif // U_SHOW_CPLUSPLUS_API
b75a7d8f
A
1122
1123/* U_HAVE_RBNF */
1124#endif
1125
1126/* RBNF_H */
1127#endif