]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
3 | /* |
4 | ****************************************************************************** | |
2ca993e8 | 5 | * Copyright (C) 1997-2015, International Business Machines |
b75a7d8f A |
6 | * Corporation and others. All Rights Reserved. |
7 | ****************************************************************************** | |
8 | * file name: nfrs.h | |
f3c0d7a5 | 9 | * encoding: UTF-8 |
b75a7d8f A |
10 | * tab size: 8 (not used) |
11 | * indentation:4 | |
12 | * | |
13 | * Modification history | |
14 | * Date Name Comments | |
15 | * 10/11/2001 Doug Ported from ICU4J | |
16 | */ | |
17 | ||
18 | #ifndef NFRS_H | |
19 | #define NFRS_H | |
20 | ||
21 | #include "unicode/uobject.h" | |
22 | #include "unicode/rbnf.h" | |
23 | ||
24 | #if U_HAVE_RBNF | |
25 | ||
26 | #include "unicode/utypes.h" | |
27 | #include "unicode/umisc.h" | |
28 | ||
29 | #include "nfrlist.h" | |
30 | ||
31 | U_NAMESPACE_BEGIN | |
32 | ||
33 | class NFRuleSet : public UMemory { | |
b331163b | 34 | public: |
2ca993e8 A |
35 | NFRuleSet(RuleBasedNumberFormat *owner, UnicodeString* descriptions, int32_t index, UErrorCode& status); |
36 | void parseRules(UnicodeString& rules, UErrorCode& status); | |
37 | void setNonNumericalRule(NFRule *rule); | |
38 | void setBestFractionRule(int32_t originalIndex, NFRule *newRule, UBool rememberRule); | |
b331163b | 39 | void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; } |
b75a7d8f | 40 | |
b331163b | 41 | ~NFRuleSet(); |
b75a7d8f | 42 | |
b331163b A |
43 | UBool operator==(const NFRuleSet& rhs) const; |
44 | UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); } | |
b75a7d8f | 45 | |
b331163b | 46 | UBool isPublic() const { return fIsPublic; } |
729e4ab9 | 47 | |
b331163b | 48 | UBool isParseable() const { return fIsParseable; } |
729e4ab9 | 49 | |
b331163b A |
50 | UBool isDecimalFormatRuleParseable() const { |
51 | UnicodeString numberingYear = UNICODE_STRING_SIMPLE("spellout-numbering-year"); | |
52 | UnicodeString ordinal = UNICODE_STRING_SIMPLE("spellout-ordinal"); | |
729e4ab9 | 53 | |
b331163b A |
54 | return ( name.indexOf(numberingYear) == -1 && name.indexOf(ordinal) == -1 ); |
55 | } | |
729e4ab9 | 56 | |
b331163b | 57 | UBool isFractionRuleSet() const { return fIsFractionRuleSet; } |
b75a7d8f | 58 | |
b331163b A |
59 | void getName(UnicodeString& result) const { result.setTo(name); } |
60 | UBool isNamed(const UnicodeString& _name) const { return this->name == _name; } | |
b75a7d8f | 61 | |
2ca993e8 A |
62 | void format(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const; |
63 | void format(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const; | |
b75a7d8f | 64 | |
0f5d89e8 | 65 | UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, Formattable& result, UBool lenient=FALSE) const; |
b75a7d8f | 66 | |
b331163b | 67 | void appendRules(UnicodeString& result) const; // toString |
b75a7d8f | 68 | |
2ca993e8 A |
69 | void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status); |
70 | ||
71 | const RuleBasedNumberFormat *getOwner() const { return owner; } | |
b331163b | 72 | private: |
2ca993e8 A |
73 | const NFRule * findNormalRule(int64_t number) const; |
74 | const NFRule * findDoubleRule(double number) const; | |
75 | const NFRule * findFractionRuleSetRule(double number) const; | |
76 | ||
77 | friend class NFSubstitution; | |
b75a7d8f | 78 | |
b331163b A |
79 | private: |
80 | UnicodeString name; | |
81 | NFRuleList rules; | |
2ca993e8 A |
82 | NFRule *nonNumericalRules[6]; |
83 | RuleBasedNumberFormat *owner; | |
84 | NFRuleList fractionRules; | |
b331163b A |
85 | UBool fIsFractionRuleSet; |
86 | UBool fIsPublic; | |
87 | UBool fIsParseable; | |
b75a7d8f | 88 | |
b331163b A |
89 | NFRuleSet(const NFRuleSet &other); // forbid copying of this class |
90 | NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class | |
b75a7d8f A |
91 | }; |
92 | ||
93 | // utilities from old llong.h | |
94 | // convert mantissa portion of double to int64 | |
95 | int64_t util64_fromDouble(double d); | |
96 | ||
97 | // raise radix to the power exponent, only non-negative exponents | |
0f5d89e8 A |
98 | // Arithmetic is performed in unsigned space since overflow in |
99 | // signed space is undefined behavior. | |
100 | uint64_t util64_pow(uint32_t radix, uint16_t exponent); | |
b75a7d8f A |
101 | |
102 | // convert n to digit string in buffer, return length of string | |
103 | uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE); | |
b75a7d8f A |
104 | |
105 | #ifdef RBNF_DEBUG | |
73c04bcf | 106 | int64_t util64_utoi(const UChar* str, uint32_t radix = 10); |
b75a7d8f A |
107 | uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE); |
108 | int64_t util64_atoi(const char* str, uint32_t radix); | |
109 | #endif | |
110 | ||
111 | ||
112 | U_NAMESPACE_END | |
113 | ||
114 | /* U_HAVE_RBNF */ | |
115 | #endif | |
116 | ||
117 | // NFRS_H | |
118 | #endif |