1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
5 * Copyright (C) 1997-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
10 * tab size: 8 (not used)
13 * Modification history
15 * 10/11/2001 Doug Ported from ICU4J
21 #include "unicode/uobject.h"
22 #include "unicode/rbnf.h"
26 #include "unicode/utypes.h"
27 #include "unicode/umisc.h"
33 class NFRuleSet : public UMemory {
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 void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; }
43 UBool operator==(const NFRuleSet& rhs) const;
44 UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); }
46 UBool isPublic() const { return fIsPublic; }
48 UBool isParseable() const { return fIsParseable; }
50 UBool isFractionRuleSet() const { return fIsFractionRuleSet; }
52 void getName(UnicodeString& result) const { result.setTo(name); }
53 UBool isNamed(const UnicodeString& _name) const { return this->name == _name; }
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;
58 UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, Formattable& result) const;
60 void appendRules(UnicodeString& result) const; // toString
62 void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status);
64 const RuleBasedNumberFormat *getOwner() const { return owner; }
66 const NFRule * findNormalRule(int64_t number) const;
67 const NFRule * findDoubleRule(double number) const;
68 const NFRule * findFractionRuleSetRule(double number) const;
70 friend class NFSubstitution;
75 NFRule *nonNumericalRules[6];
76 RuleBasedNumberFormat *owner;
77 NFRuleList fractionRules;
78 UBool fIsFractionRuleSet;
82 NFRuleSet(const NFRuleSet &other); // forbid copying of this class
83 NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class
86 // utilities from old llong.h
87 // convert mantissa portion of double to int64
88 int64_t util64_fromDouble(double d);
90 // raise radix to the power exponent, only non-negative exponents
91 int64_t util64_pow(int32_t radix, uint32_t exponent);
93 // convert n to digit string in buffer, return length of string
94 uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
97 int64_t util64_utoi(const UChar* str, uint32_t radix = 10);
98 uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
99 int64_t util64_atoi(const char* str, uint32_t radix);