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