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