• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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);
makeIntoFractionRuleSet()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 
isPublic()44     UBool isPublic() const { return fIsPublic; }
45 
isParseable()46     UBool isParseable() const { return fIsParseable; }
47 
isFractionRuleSet()48     UBool isFractionRuleSet() const { return fIsFractionRuleSet; }
49 
getName(UnicodeString & result)50     void  getName(UnicodeString& result) const { result.setTo(name); }
isNamed(const UnicodeString & _name)51     UBool isNamed(const UnicodeString& _name) const { return this->name == _name; }
52 
53     void  format(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
54     void  format(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
55 
56     UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, Formattable& result) const;
57 
58     void appendRules(UnicodeString& result) const; // toString
59 
60     void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status);
61 
getOwner()62     const RuleBasedNumberFormat *getOwner() const { return owner; }
63 private:
64     const NFRule * findNormalRule(int64_t number) const;
65     const NFRule * findDoubleRule(double number) const;
66     const NFRule * findFractionRuleSetRule(double number) const;
67 
68     friend class NFSubstitution;
69 
70 private:
71     UnicodeString name;
72     NFRuleList rules;
73     NFRule *nonNumericalRules[6];
74     RuleBasedNumberFormat *owner;
75     NFRuleList fractionRules;
76     UBool fIsFractionRuleSet;
77     UBool fIsPublic;
78     UBool fIsParseable;
79 
80     NFRuleSet(const NFRuleSet &other); // forbid copying of this class
81     NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class
82 };
83 
84 // utilities from old llong.h
85 // convert mantissa portion of double to int64
86 int64_t util64_fromDouble(double d);
87 
88 // raise radix to the power exponent, only non-negative exponents
89 int64_t util64_pow(int32_t radix, uint32_t exponent);
90 
91 // convert n to digit string in buffer, return length of string
92 uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
93 
94 #ifdef RBNF_DEBUG
95 int64_t util64_utoi(const UChar* str, uint32_t radix = 10);
96 uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
97 int64_t util64_atoi(const char* str, uint32_t radix);
98 #endif
99 
100 
101 U_NAMESPACE_END
102 
103 /* U_HAVE_RBNF */
104 #endif
105 
106 // NFRS_H
107 #endif
108 
109