rbnf.h 47 KB

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