OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 1997-2013, International Business Machines Corporation and other
s. | 3 * Copyright (C) 1997-2014, International Business Machines Corporation and other
s. |
4 * All Rights Reserved. | 4 * All Rights Reserved. |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 */ | 6 */ |
7 | 7 |
8 #ifndef RBNF_H | 8 #ifndef RBNF_H |
9 #define RBNF_H | 9 #define RBNF_H |
10 | 10 |
11 #include "unicode/utypes.h" | 11 #include "unicode/utypes.h" |
12 | 12 |
13 /** | 13 /** |
14 * \file | 14 * \file |
15 * \brief C++ API: Rule Based Number Format | 15 * \brief C++ API: Rule Based Number Format |
16 */ | 16 */ |
17 | 17 |
18 /** | 18 /** |
19 * \def U_HAVE_RBNF | 19 * \def U_HAVE_RBNF |
20 * This will be 0 if RBNF support is not included in ICU | 20 * This will be 0 if RBNF support is not included in ICU |
21 * and 1 if it is. | 21 * and 1 if it is. |
22 * | 22 * |
23 * @stable ICU 2.4 | 23 * @stable ICU 2.4 |
24 */ | 24 */ |
25 #if UCONFIG_NO_FORMATTING | 25 #if UCONFIG_NO_FORMATTING |
26 #define U_HAVE_RBNF 0 | 26 #define U_HAVE_RBNF 0 |
27 #else | 27 #else |
28 #define U_HAVE_RBNF 1 | 28 #define U_HAVE_RBNF 1 |
29 | 29 |
30 #include "unicode/coll.h" | |
31 #include "unicode/dcfmtsym.h" | 30 #include "unicode/dcfmtsym.h" |
32 #include "unicode/fmtable.h" | 31 #include "unicode/fmtable.h" |
33 #include "unicode/locid.h" | 32 #include "unicode/locid.h" |
34 #include "unicode/numfmt.h" | 33 #include "unicode/numfmt.h" |
35 #include "unicode/unistr.h" | 34 #include "unicode/unistr.h" |
36 #include "unicode/strenum.h" | 35 #include "unicode/strenum.h" |
| 36 #include "unicode/brkiter.h" |
| 37 #include "unicode/upluralrules.h" |
37 | 38 |
38 U_NAMESPACE_BEGIN | 39 U_NAMESPACE_BEGIN |
39 | 40 |
40 class NFRuleSet; | 41 class NFRuleSet; |
41 class LocalizationInfo; | 42 class LocalizationInfo; |
| 43 class PluralFormat; |
| 44 class RuleBasedCollator; |
42 | 45 |
43 /** | 46 /** |
44 * Tags for the predefined rulesets. | 47 * Tags for the predefined rulesets. |
45 * | 48 * |
46 * @stable ICU 2.2 | 49 * @stable ICU 2.2 |
47 */ | 50 */ |
48 enum URBNFRuleSetTag { | 51 enum URBNFRuleSetTag { |
49 URBNF_SPELLOUT, | 52 URBNF_SPELLOUT, |
50 URBNF_ORDINAL, | 53 URBNF_ORDINAL, |
51 URBNF_DURATION, | 54 URBNF_DURATION, |
52 URBNF_NUMBERING_SYSTEM, | 55 URBNF_NUMBERING_SYSTEM, |
53 URBNF_COUNT | 56 URBNF_COUNT |
54 }; | 57 }; |
55 | 58 |
56 #if UCONFIG_NO_COLLATION | |
57 class Collator; | |
58 #endif | |
59 | |
60 /** | 59 /** |
61 * The RuleBasedNumberFormat class formats numbers according to a set of rules.
This number formatter is | 60 * The RuleBasedNumberFormat class formats numbers according to a set of rules.
This number formatter is |
62 * typically used for spelling out numeric values in words (e.g., 25,3476 as | 61 * typically used for spelling out numeric values in words (e.g., 25,3476 as |
63 * "twenty-five thousand three hundred seventy-six" or "vingt-cin
q mille trois | 62 * "twenty-five thousand three hundred seventy-six" or "vingt-cin
q mille trois |
64 * cents soixante-seize" or | 63 * cents soixante-seize" or |
65 * "fünfundzwanzigtausenddreihundertsechsundsiebzig"), but can al
so be used for | 64 * "fünfundzwanzigtausenddreihundertsechsundsiebzig"), but can al
so be used for |
66 * other complicated formatting tasks, such as formatting a number of seconds as
hours, | 65 * other complicated formatting tasks, such as formatting a number of seconds as
hours, |
67 * minutes and seconds (e.g., 3,730 as "1:02:10"). | 66 * minutes and seconds (e.g., 3,730 as "1:02:10"). |
68 * | 67 * |
69 * <p>The resources contain three predefined formatters for each locale: spellou
t, which | 68 * <p>The resources contain three predefined formatters for each locale: spellou
t, which |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 * <tr> | 423 * <tr> |
425 * <td></td> | 424 * <td></td> |
426 * <td>in proper-fraction rule</td> | 425 * <td>in proper-fraction rule</td> |
427 * <td>Not allowed.</td> | 426 * <td>Not allowed.</td> |
428 * </tr> | 427 * </tr> |
429 * <tr> | 428 * <tr> |
430 * <td></td> | 429 * <td></td> |
431 * <td>in rule in fraction rule set</td> | 430 * <td>in rule in fraction rule set</td> |
432 * <td>Omit the optional text if multiplying the number by the rule's base v
alue yields 1.</td> | 431 * <td>Omit the optional text if multiplying the number by the rule's base v
alue yields 1.</td> |
433 * </tr> | 432 * </tr> |
| 433 * <tr> |
| 434 * <td width="37">$(cardinal,<i>plural syntax</i>)$</td> |
| 435 * <td width="23"></td> |
| 436 * <td width="165" valign="top">in all rule sets</td> |
| 437 * <td>This provides the ability to choose a word based on the number divide
d by the radix to the power of the |
| 438 * exponent of the base value for the specified locale, which is normally eq
uivalent to the << value. |
| 439 * This uses the cardinal plural rules from PluralFormat. All strings used i
n the plural format are treated |
| 440 * as the same base value for parsing.</td> |
| 441 * </tr> |
| 442 * <tr> |
| 443 * <td width="37">$(ordinal,<i>plural syntax</i>)$</td> |
| 444 * <td width="23"></td> |
| 445 * <td width="165" valign="top">in all rule sets</td> |
| 446 * <td>This provides the ability to choose a word based on the number divide
d by the radix to the power of the |
| 447 * exponent of the base value for the specified locale, which is normally eq
uivalent to the << value. |
| 448 * This uses the ordinal plural rules from PluralFormat. All strings used in
the plural format are treated |
| 449 * as the same base value for parsing.</td> |
| 450 * </tr> |
434 * </table> | 451 * </table> |
435 * | 452 * |
436 * <p>The substitution descriptor (i.e., the text between the token characters)
may take one | 453 * <p>The substitution descriptor (i.e., the text between the token characters)
may take one |
437 * of three forms:</p> | 454 * of three forms:</p> |
438 * | 455 * |
439 * <table border="0" width="100%"> | 456 * <table border="0" width="100%"> |
440 * <tr> | 457 * <tr> |
441 * <td>a rule set name</td> | 458 * <td>a rule set name</td> |
442 * <td>Perform the mathematical operation on the number, and format the resu
lt using the | 459 * <td>Perform the mathematical operation on the number, and format the resu
lt using the |
443 * named rule set.</td> | 460 * named rule set.</td> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 * to separate elements of an array. Whitespace is ignored, unless quoted.</p> | 508 * to separate elements of an array. Whitespace is ignored, unless quoted.</p> |
492 * <p>For example:<pre> | 509 * <p>For example:<pre> |
493 * < < %foo, %bar, %baz >, | 510 * < < %foo, %bar, %baz >, |
494 * < en, Foo, Bar, Baz >, | 511 * < en, Foo, Bar, Baz >, |
495 * < fr, 'le Foo', 'le Bar', 'le Baz' > | 512 * < fr, 'le Foo', 'le Bar', 'le Baz' > |
496 * < zh, \\u7532, \\u4e59, \\u4e19 > > | 513 * < zh, \\u7532, \\u4e59, \\u4e19 > > |
497 * </pre></p> | 514 * </pre></p> |
498 * @author Richard Gillam | 515 * @author Richard Gillam |
499 * @see NumberFormat | 516 * @see NumberFormat |
500 * @see DecimalFormat | 517 * @see DecimalFormat |
| 518 * @see PluralFormat |
| 519 * @see PluralRules |
501 * @stable ICU 2.0 | 520 * @stable ICU 2.0 |
502 */ | 521 */ |
503 class U_I18N_API RuleBasedNumberFormat : public NumberFormat { | 522 class U_I18N_API RuleBasedNumberFormat : public NumberFormat { |
504 public: | 523 public: |
505 | 524 |
506 //----------------------------------------------------------------------- | 525 //----------------------------------------------------------------------- |
507 // constructors | 526 // constructors |
508 //----------------------------------------------------------------------- | 527 //----------------------------------------------------------------------- |
509 | 528 |
510 /** | 529 /** |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& s
tatus); | 906 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& s
tatus); |
888 | 907 |
889 /** | 908 /** |
890 * Return the name of the current default rule set. If the current rule set i
s | 909 * Return the name of the current default rule set. If the current rule set i
s |
891 * not public, returns a bogus (and empty) UnicodeString. | 910 * not public, returns a bogus (and empty) UnicodeString. |
892 * @return the name of the current default rule set | 911 * @return the name of the current default rule set |
893 * @stable ICU 3.0 | 912 * @stable ICU 3.0 |
894 */ | 913 */ |
895 virtual UnicodeString getDefaultRuleSetName() const; | 914 virtual UnicodeString getDefaultRuleSetName() const; |
896 | 915 |
| 916 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it
is virtual */ |
| 917 /** |
| 918 * Set a particular UDisplayContext value in the formatter, such as |
| 919 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see |
| 920 * NumberFormat. |
| 921 * @param value The UDisplayContext value to set. |
| 922 * @param status Input/output status. If at entry this indicates a failure |
| 923 * status, the function will do nothing; otherwise this will be |
| 924 * updated with any new status from the function. |
| 925 * @draft ICU 53 |
| 926 */ |
| 927 virtual void setContext(UDisplayContext value, UErrorCode& status); |
| 928 |
897 public: | 929 public: |
898 /** | 930 /** |
899 * ICU "poor man's RTTI", returns a UClassID for this class. | 931 * ICU "poor man's RTTI", returns a UClassID for this class. |
900 * | 932 * |
901 * @stable ICU 2.8 | 933 * @stable ICU 2.8 |
902 */ | 934 */ |
903 static UClassID U_EXPORT2 getStaticClassID(void); | 935 static UClassID U_EXPORT2 getStaticClassID(void); |
904 | 936 |
905 /** | 937 /** |
906 * ICU "poor man's RTTI", returns a UClassID for the actual class. | 938 * ICU "poor man's RTTI", returns a UClassID for the actual class. |
(...skipping 25 matching lines...) Expand all Loading... |
932 | 964 |
933 private: | 965 private: |
934 RuleBasedNumberFormat(); // default constructor not implemented | 966 RuleBasedNumberFormat(); // default constructor not implemented |
935 | 967 |
936 // this will ref the localizations if they are not NULL | 968 // this will ref the localizations if they are not NULL |
937 // caller must deref to get adoption | 969 // caller must deref to get adoption |
938 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* lo
calizations, | 970 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* lo
calizations, |
939 const Locale& locale, UParseError& perror, UErrorCode& status); | 971 const Locale& locale, UParseError& perror, UErrorCode& status); |
940 | 972 |
941 void init(const UnicodeString& rules, LocalizationInfo* localizations, UPars
eError& perror, UErrorCode& status); | 973 void init(const UnicodeString& rules, LocalizationInfo* localizations, UPars
eError& perror, UErrorCode& status); |
| 974 void initCapitalizationContextInfo(const Locale& thelocale); |
942 void dispose(); | 975 void dispose(); |
943 void stripWhitespace(UnicodeString& src); | 976 void stripWhitespace(UnicodeString& src); |
944 void initDefaultRuleSet(); | 977 void initDefaultRuleSet(); |
945 void format(double number, NFRuleSet& ruleSet); | 978 void format(double number, NFRuleSet& ruleSet); |
946 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const; | 979 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const; |
947 | 980 |
948 /* friend access */ | 981 /* friend access */ |
949 friend class NFSubstitution; | 982 friend class NFSubstitution; |
950 friend class NFRule; | 983 friend class NFRule; |
951 friend class FractionalPartSubstitution; | 984 friend class FractionalPartSubstitution; |
952 | 985 |
953 inline NFRuleSet * getDefaultRuleSet() const; | 986 inline NFRuleSet * getDefaultRuleSet() const; |
954 Collator * getCollator() const; | 987 const RuleBasedCollator * getCollator() const; |
955 DecimalFormatSymbols * getDecimalFormatSymbols() const; | 988 DecimalFormatSymbols * getDecimalFormatSymbols() const; |
| 989 PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString
&pattern, UErrorCode& status) const; |
| 990 UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeStrin
g& currentResult) const; |
956 | 991 |
957 private: | 992 private: |
958 NFRuleSet **ruleSets; | 993 NFRuleSet **ruleSets; |
959 UnicodeString* ruleSetDescriptions; | 994 UnicodeString* ruleSetDescriptions; |
960 int32_t numRuleSets; | 995 int32_t numRuleSets; |
961 NFRuleSet *defaultRuleSet; | 996 NFRuleSet *defaultRuleSet; |
962 Locale locale; | 997 Locale locale; |
963 Collator* collator; | 998 RuleBasedCollator* collator; |
964 DecimalFormatSymbols* decimalFormatSymbols; | 999 DecimalFormatSymbols* decimalFormatSymbols; |
965 UBool lenient; | 1000 UBool lenient; |
966 UnicodeString* lenientParseRules; | 1001 UnicodeString* lenientParseRules; |
967 LocalizationInfo* localizations; | 1002 LocalizationInfo* localizations; |
| 1003 UnicodeString originalDescription; |
| 1004 UBool capitalizationInfoSet; |
| 1005 UBool capitalizationForUIListMenu; |
| 1006 UBool capitalizationForStandAlone; |
| 1007 BreakIterator* capitalizationBrkIter; |
968 }; | 1008 }; |
969 | 1009 |
970 // --------------- | 1010 // --------------- |
971 | 1011 |
972 #if !UCONFIG_NO_COLLATION | 1012 #if !UCONFIG_NO_COLLATION |
973 | 1013 |
974 inline UBool | 1014 inline UBool |
975 RuleBasedNumberFormat::isLenient(void) const { | 1015 RuleBasedNumberFormat::isLenient(void) const { |
976 return lenient; | 1016 return lenient; |
977 } | 1017 } |
978 | 1018 |
979 #endif | 1019 #endif |
980 | 1020 |
981 inline NFRuleSet* | 1021 inline NFRuleSet* |
982 RuleBasedNumberFormat::getDefaultRuleSet() const { | 1022 RuleBasedNumberFormat::getDefaultRuleSet() const { |
983 return defaultRuleSet; | 1023 return defaultRuleSet; |
984 } | 1024 } |
985 | 1025 |
986 U_NAMESPACE_END | 1026 U_NAMESPACE_END |
987 | 1027 |
988 /* U_HAVE_RBNF */ | 1028 /* U_HAVE_RBNF */ |
989 #endif | 1029 #endif |
990 | 1030 |
991 /* RBNF_H */ | 1031 /* RBNF_H */ |
992 #endif | 1032 #endif |
OLD | NEW |