rbnf.h 47 KB

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