]>
Commit | Line | Data |
---|---|---|
374ca955 A |
1 | // *************************************************************************** |
2 | // * | |
3 | // * Copyright (C) 2004, International Business Machines | |
4 | // * Corporation and others. All Rights Reserved. | |
5 | // * | |
6 | // *************************************************************************** | |
7 | // | |
8 | ||
9 | en { | |
10 | ||
11 | ||
12 | //------------------------------------------------------------ | |
13 | // Rule Based Number Format Support | |
14 | //------------------------------------------------------------ | |
15 | ||
16 | // * Spellout rules for U.S. English. This rule set has two variants: | |
17 | // * %simplified is a set of rules showing the simple method of spelling | |
18 | // * out numbers in English: 289 is formatted as "two hundred eighty-nine". | |
19 | // * %default uses a more complicated algorithm to format | |
20 | // * numbers in a more natural way: 289 is formatted as "two hundred AND | |
21 | // * eighty-nine" and commas are inserted between the thousands groups for | |
22 | // * values above 100,000. | |
23 | ||
24 | SpelloutRules { | |
25 | // This rule set shows the normal simple formatting rules for English | |
26 | "%simplified:\n" | |
27 | // negative number rule. This rule is used to format negative | |
28 | // numbers. The result of formatting the number's absolute | |
29 | // value is placed where the >> is. | |
30 | "-x: minus >>;\n" | |
31 | // faction rule. This rule is used for formatting numbers | |
32 | // with fractional parts. The result of formatting the | |
33 | // number's integral part is substituted for the <<, and | |
34 | // the result of formatting the number's fractional part | |
35 | // (one digit at a time, e.g., 0.123 is "zero point one two | |
36 | // three") replaces the >>. | |
37 | "x.x: << point >>;\n" | |
38 | // the rules for the values from 0 to 19 are simply the | |
39 | // words for those numbers | |
40 | "zero; one; two; three; four; five; six; seven; eight; nine;\n" | |
41 | "ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n" | |
42 | "seventeen; eighteen; nineteen;\n" | |
43 | // beginning at 20, we use the >> to mark the position where | |
44 | // the result of formatting the number's ones digit. Thus, | |
45 | // we only need a new rule at every multiple of 10. Text in | |
46 | // backets is omitted if the value being formatted is an | |
47 | // even multiple of 10. | |
48 | "20: twenty[->>];\n" | |
49 | "30: thirty[->>];\n" | |
50 | "40: forty[->>];\n" | |
51 | "50: fifty[->>];\n" | |
52 | "60: sixty[->>];\n" | |
53 | "70: seventy[->>];\n" | |
54 | "80: eighty[->>];\n" | |
55 | "90: ninety[->>];\n" | |
56 | // beginning at 100, we can use << to mark the position where | |
57 | // the result of formatting the multiple of 100 is to be | |
58 | // inserted. Notice also that the meaning of >> has shifted: | |
59 | // here, it refers to both the ones place and the tens place. | |
60 | // The meanings of the << and >> tokens depend on the base value | |
61 | // of the rule. A rule's divisor is (usually) the highest | |
62 | // power of 10 that is less than or equal to the rule's base | |
63 | // value. The value being formatted is divided by the rule's | |
64 | // divisor, and the integral quotient is used to get the text | |
65 | // for <<, while the remainder is used to produce the text | |
66 | // for >>. Again, text in brackets is omitted if the value | |
67 | // being formatted is an even multiple of the rule's divisor | |
68 | // (in this case, an even multiple of 100) | |
69 | "100: << hundred[ >>];\n" | |
70 | // The rules for the higher numbers work the same way as the | |
71 | // rule for 100: Again, the << and >> tokens depend on the | |
72 | // rule's divisor, which for all these rules is also the rule's | |
73 | // base value. To group by thousand, we simply don't have any | |
74 | // rules between 1,000 and 1,000,000. | |
75 | "1000: << thousand[ >>];\n" | |
76 | "1,000,000: << million[ >>];\n" | |
77 | "1,000,000,000: << billion[ >>];\n" | |
78 | "1,000,000,000,000: << trillion[ >>];\n" | |
79 | // overflow rule. This rule specifies that values of a | |
80 | // quadrillion or more are shown in numerals rather than words. | |
81 | // The == token means to format (with new rules) the value | |
82 | // being formatted by this rule and place the result where | |
83 | // the == is. The #,##0 inside the == signs is a | |
84 | // DecimalFormat pattern. It specifies that the value should | |
85 | // be formatted with a DecimalFormat object, and that it | |
86 | // should be formatted with no decimal places, at least one | |
87 | // digit, and a thousands separator. | |
88 | "1,000,000,000,000,000: =#,##0=;\n" | |
89 | ||
90 | // %default is a more elaborate form of %simplified; It is basically | |
91 | // the same, except that it introduces "and" before the ones digit | |
92 | // when appropriate (basically, between the tens and ones digits) and | |
93 | // separates the thousands groups with commas in values over 100,000. | |
94 | "%default:\n" | |
95 | // negative-number and fraction rules. These are the same | |
96 | // as those for %simplified, but have to be stated here too | |
97 | // because this is an entry point | |
98 | "-x: minus >>;\n" | |
99 | "x.x: << point >>;\n" | |
100 | // just use %simplified for values below 100 | |
101 | "=%simplified=;\n" | |
102 | // for values from 100 to 9,999 use %%and to decide whether or | |
103 | // not to interpose the "and" | |
104 | "100: << hundred[ >%%and>];\n" | |
105 | "1000: << thousand[ >%%and>];\n" | |
106 | // for values of 100,000 and up, use %%commas to interpose the | |
107 | // commas in the right places (and also to interpose the "and") | |
108 | "100,000>>: << thousand[>%%commas>];\n" | |
109 | "1,000,000: << million[>%%commas>];\n" | |
110 | "1,000,000,000: << billion[>%%commas>];\n" | |
111 | "1,000,000,000,000: << trillion[>%%commas>];\n" | |
112 | "1,000,000,000,000,000: =#,##0=;\n" | |
113 | // if the value passed to this rule set is greater than 100, don't | |
114 | // add the "and"; if it's less than 100, add "and" before the last | |
115 | // digits | |
116 | "%%and:\n" | |
117 | "and =%default=;\n" | |
118 | "100: =%default=;\n" | |
119 | // this rule set is used to place the commas | |
120 | "%%commas:\n" | |
121 | // for values below 100, add "and" (the apostrophe at the | |
122 | // beginning is ignored, but causes the space that follows it | |
123 | // to be significant: this is necessary because the rules | |
124 | // calling %%commas don't put a space before it) | |
125 | "' and =%default=;\n" | |
126 | // put a comma after the thousands (or whatever preceded the | |
127 | // hundreds) | |
128 | "100: , =%default=;\n" | |
129 | // put a comma after the millions (or whatever precedes the | |
130 | // thousands) | |
131 | "1000: , <%default< thousand, >%default>;\n" | |
132 | // and so on... | |
133 | "1,000,000: , =%default=;" | |
134 | // %%lenient-parse isn't really a set of number formatting rules; | |
135 | // it's a set of collation rules. Lenient-parse mode uses a Collator | |
136 | // object to compare fragments of the text being parsed to the text | |
137 | // in the rules, allowing more leeway in the matching text. This set | |
138 | // of rules tells the formatter to ignore commas when parsing (it | |
139 | // already ignores spaces, which is why we refer to the space; it also | |
140 | // ignores hyphens, making "twenty one" and "twenty-one" parse | |
141 | // identically) | |
142 | "%%lenient-parse:\n" | |
143 | // "& ' ' , ',' ;\n" | |
144 | " &\u0000 << ' ' << ',' << '-'; \n" | |
145 | } | |
146 | ||
147 | ||
148 | // * This rule set adds an English ordinal abbreviation to the end of a | |
149 | // * number. For example, 2 is formatted as "2nd". Parsing doesn't work with | |
150 | // * this rule set. To parse, use DecimalFormat on the numeral. | |
151 | OrdinalRules { | |
152 | // this rule set formats the numeral and calls %%abbrev to | |
153 | // supply the abbreviation | |
154 | "%main:\n" | |
155 | "=#,##0==%%abbrev=;\n" | |
156 | // this rule set supplies the abbreviation | |
157 | "%%abbrev:\n" | |
158 | // the abbreviations. Everything from 4 to 19 ends in "th" | |
159 | "th; st; nd; rd; th;\n" | |
160 | // at 20, we begin repeating the cycle every 10 (13 is "13th", | |
161 | // but 23 and 33 are "23rd" and "33rd") We do this by | |
162 | // ignoring all bug the ones digit in selecting the abbreviation | |
163 | "20: >>;\n" | |
164 | // at 100, we repeat the whole cycle by considering only the | |
165 | // tens and ones digits in picking an abbreviation | |
166 | "100: >>;\n" | |
167 | } | |
168 | ||
169 | // * This rule set formats a number of seconds in sexagesimal notation | |
170 | // * (i.e., hours, minutes, and seconds). %with-words formats it with | |
171 | // * words (3,740 is "1 hour, 2 minutes, 20 seconds") and %in-numerals | |
172 | // * formats it entirely in numerals (3,740 is "1:02:20"). | |
173 | DurationRules { | |
174 | // main rule set for formatting with words | |
175 | "%with-words:\n" | |
176 | // take care of singular and plural forms of "second" | |
177 | "0 seconds; 1 second; =0= seconds;\n" | |
178 | // use %%min to format values greater than 60 seconds | |
179 | "60/60: <%%min<[, >>];\n" | |
180 | // use %%hr to format values greater than 3,600 seconds | |
181 | // (the ">>>" below causes us to see the number of minutes | |
182 | // when when there are zero minutes) | |
183 | "3600/60: <%%hr<[, >>>];\n" | |
184 | // this rule set takes care of the singular and plural forms | |
185 | // of "minute" | |
186 | "%%min:\n" | |
187 | "0 minutes; 1 minute; =0= minutes;\n" | |
188 | // this rule set takes care of the singular and plural forms | |
189 | // of "hour" | |
190 | "%%hr:\n" | |
191 | "0 hours; 1 hour; =0= hours;\n" | |
192 | ||
193 | // main rule set for formatting in numerals | |
194 | "%in-numerals:\n" | |
195 | // values below 60 seconds are shown with "sec." | |
196 | "=0= sec.;\n" | |
197 | // higher values are shown with colons: %%min-sec is used for | |
198 | // values below 3,600 seconds... | |
199 | "60: =%%min-sec=;\n" | |
200 | // ...and %%hr-min-sec is used for values of 3,600 seconds | |
201 | // and above | |
202 | "3600: =%%hr-min-sec=;\n" | |
203 | // this rule causes values of less than 10 minutes to show without | |
204 | // a leading zero | |
205 | "%%min-sec:\n" | |
206 | "0: :=00=;\n" | |
207 | "60/60: <0<>>;\n" | |
208 | // this rule set is used for values of 3,600 or more. Minutes are always | |
209 | // shown, and always shown with two digits | |
210 | "%%hr-min-sec:\n" | |
211 | "0: :=00=;\n" | |
212 | "60/60: <00<>>;\n" | |
213 | "3600/60: <#,##0<:>>>;\n" | |
214 | // the lenient-parse rules allow several different characters to be used | |
215 | // as delimiters between hours, minutes, and seconds | |
216 | "%%lenient-parse:\n" | |
217 | "& ':' = '.' = ' ' = '-';\n" | |
218 | } | |
219 | } |