OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ****************************************************************************** |
| 3 * Copyright (C) 1997-2009, 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(UnicodeString* descriptions, int32_t index, UErrorCode& status); |
| 34 void parseRules(UnicodeString& rules, const RuleBasedNumberFormat* owner, UErr
orCode& status); |
| 35 void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; } |
| 36 |
| 37 ~NFRuleSet(); |
| 38 |
| 39 UBool operator==(const NFRuleSet& rhs) const; |
| 40 UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); } |
| 41 |
| 42 UBool isPublic() const { return fIsPublic; } |
| 43 |
| 44 UBool isParseable() const { |
| 45 UnicodeString prefixpart = UNICODE_STRING_SIMPLE("-prefixpart"); |
| 46 UnicodeString postfix = UNICODE_STRING_SIMPLE("-postfix"); |
| 47 UnicodeString postfx = UNICODE_STRING_SIMPLE("-postfx"); |
| 48 |
| 49 return ( name.indexOf(prefixpart) == -1 && name.indexOf(postfix) == -1 &&
name.indexOf(postfx) == -1 ); |
| 50 } |
| 51 |
| 52 UBool isFractionRuleSet() const { return fIsFractionRuleSet; } |
| 53 |
| 54 void getName(UnicodeString& result) const { result.setTo(name); } |
| 55 UBool isNamed(const UnicodeString& _name) const { return this->name == _name;
} |
| 56 |
| 57 void format(int64_t number, UnicodeString& toAppendTo, int32_t pos) const; |
| 58 void format(double number, UnicodeString& toAppendTo, int32_t pos) const; |
| 59 |
| 60 UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound,
Formattable& result) const; |
| 61 |
| 62 void appendRules(UnicodeString& result) const; // toString |
| 63 |
| 64 private: |
| 65 NFRule * findNormalRule(int64_t number) const; |
| 66 NFRule * findDoubleRule(double number) const; |
| 67 NFRule * findFractionRuleSetRule(double number) const; |
| 68 |
| 69 private: |
| 70 UnicodeString name; |
| 71 NFRuleList rules; |
| 72 NFRule *negativeNumberRule; |
| 73 NFRule *fractionRules[3]; |
| 74 UBool fIsFractionRuleSet; |
| 75 UBool fIsPublic; |
| 76 int32_t fRecursionCount; |
| 77 |
| 78 NFRuleSet(const NFRuleSet &other); // forbid copying of this class |
| 79 NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class |
| 80 }; |
| 81 |
| 82 // utilities from old llong.h |
| 83 // convert mantissa portion of double to int64 |
| 84 int64_t util64_fromDouble(double d); |
| 85 |
| 86 // raise radix to the power exponent, only non-negative exponents |
| 87 int64_t util64_pow(int32_t radix, uint32_t exponent); |
| 88 |
| 89 // convert n to digit string in buffer, return length of string |
| 90 uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix =
10, UBool raw = FALSE); |
| 91 |
| 92 #ifdef RBNF_DEBUG |
| 93 int64_t util64_utoi(const UChar* str, uint32_t radix = 10); |
| 94 uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 1
0, UBool raw = FALSE); |
| 95 int64_t util64_atoi(const char* str, uint32_t radix); |
| 96 #endif |
| 97 |
| 98 |
| 99 U_NAMESPACE_END |
| 100 |
| 101 /* U_HAVE_RBNF */ |
| 102 #endif |
| 103 |
| 104 // NFRS_H |
| 105 #endif |
| 106 |
OLD | NEW |