/src/icu/icu4c/source/i18n/nfrs.h
Line | Count | Source |
1 | | // © 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 |
6 | | * Corporation and others. All Rights Reserved. |
7 | | ****************************************************************************** |
8 | | * file name: nfrs.h |
9 | | * encoding: UTF-8 |
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 { |
34 | | public: |
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); |
39 | 1.36k | void makeIntoFractionRuleSet() { fIsFractionRuleSet = true; } |
40 | | |
41 | | ~NFRuleSet(); |
42 | | |
43 | | bool operator==(const NFRuleSet& rhs) const; |
44 | 0 | bool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); } |
45 | | |
46 | 29.4k | UBool isPublic() const { return fIsPublic; } |
47 | | |
48 | 11.7k | UBool isParseable() const { return fIsParseable; } |
49 | | |
50 | 1.31M | UBool isFractionRuleSet() const { return fIsFractionRuleSet; } |
51 | | |
52 | 1.84k | void getName(UnicodeString& result) const { result.setTo(name); } |
53 | 3.01M | UBool isNamed(const UnicodeString& _name) const { return this->name == _name; } |
54 | | |
55 | | void format(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const; |
56 | | void format(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const; |
57 | | |
58 | | UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, int32_t recursionCount, Formattable& result) const; |
59 | | |
60 | | void appendRules(UnicodeString& result) const; // toString |
61 | | |
62 | | void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status); |
63 | | |
64 | 396k | const RuleBasedNumberFormat *getOwner() const { return owner; } |
65 | | private: |
66 | | const NFRule * findNormalRule(int64_t number) const; |
67 | | const NFRule * findDoubleRule(double number) const; |
68 | | const NFRule * findFractionRuleSetRule(double number) const; |
69 | | |
70 | | friend class NFSubstitution; |
71 | | friend class NFRule; |
72 | | |
73 | | private: |
74 | | UnicodeString name; |
75 | | NFRuleList rules; |
76 | | NFRule *nonNumericalRules[6] { }; |
77 | | RuleBasedNumberFormat *owner { }; |
78 | | NFRuleList fractionRules; |
79 | | UBool fIsFractionRuleSet { }; |
80 | | UBool fIsPublic { }; |
81 | | UBool fIsParseable { true }; |
82 | | |
83 | | NFRuleSet(const NFRuleSet &other); // forbid copying of this class |
84 | | NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class |
85 | | }; |
86 | | |
87 | | // utilities from old llong.h |
88 | | // convert mantissa portion of double to int64 |
89 | | int64_t util64_fromDouble(double d); |
90 | | |
91 | | // raise radix to the power exponent, only non-negative exponents |
92 | | // Arithmetic is performed in unsigned space since overflow in |
93 | | // signed space is undefined behavior. |
94 | | uint64_t util64_pow(uint32_t radix, uint16_t exponent); |
95 | | |
96 | | // convert n to digit string in buffer, return length of string |
97 | | uint32_t util64_tou(int64_t n, char16_t* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = false); |
98 | | |
99 | | #ifdef RBNF_DEBUG |
100 | | int64_t util64_utoi(const char16_t* str, uint32_t radix = 10); |
101 | | uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = false); |
102 | | int64_t util64_atoi(const char* str, uint32_t radix); |
103 | | #endif |
104 | | |
105 | | |
106 | | U_NAMESPACE_END |
107 | | |
108 | | /* U_HAVE_RBNF */ |
109 | | #endif |
110 | | |
111 | | // NFRS_H |
112 | | #endif |