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