+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
-* Copyright (C) 1997-2001, International Business Machines
+* Copyright (C) 1997-2015, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* file name: nfrs.h
-* encoding: US-ASCII
+* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
U_NAMESPACE_BEGIN
class NFRuleSet : public UMemory {
- public:
- NFRuleSet(UnicodeString* descriptions, int32_t index, UErrorCode& status);
- void parseRules(UnicodeString& rules, const RuleBasedNumberFormat* owner, UErrorCode& status);
- void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; }
+public:
+ NFRuleSet(RuleBasedNumberFormat *owner, UnicodeString* descriptions, int32_t index, UErrorCode& status);
+ void parseRules(UnicodeString& rules, UErrorCode& status);
+ void setNonNumericalRule(NFRule *rule);
+ void setBestFractionRule(int32_t originalIndex, NFRule *newRule, UBool rememberRule);
+ void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; }
- ~NFRuleSet();
+ ~NFRuleSet();
- UBool operator==(const NFRuleSet& rhs) const;
- UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); }
+ UBool operator==(const NFRuleSet& rhs) const;
+ UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); }
- UBool isPublic() const { return fIsPublic; }
- UBool isFractionRuleSet() const { return fIsFractionRuleSet; }
+ UBool isPublic() const { return fIsPublic; }
- void getName(UnicodeString& result) const { result.setTo(name); }
- UBool isNamed(const UnicodeString& _name) const { return this->name == _name; }
+ UBool isParseable() const { return fIsParseable; }
- void format(int64_t number, UnicodeString& toAppendTo, int32_t pos) const;
- void format(double number, UnicodeString& toAppendTo, int32_t pos) const;
+ UBool isDecimalFormatRuleParseable() const {
+ UnicodeString numberingYear = UNICODE_STRING_SIMPLE("spellout-numbering-year");
+ UnicodeString ordinal = UNICODE_STRING_SIMPLE("spellout-ordinal");
- UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, Formattable& result) const;
+ return ( name.indexOf(numberingYear) == -1 && name.indexOf(ordinal) == -1 );
+ }
- void appendRules(UnicodeString& result) const; // toString
+ UBool isFractionRuleSet() const { return fIsFractionRuleSet; }
- private:
- NFRule * findNormalRule(int64_t number) const;
- NFRule * findDoubleRule(double number) const;
- NFRule * findFractionRuleSetRule(double number) const;
+ void getName(UnicodeString& result) const { result.setTo(name); }
+ UBool isNamed(const UnicodeString& _name) const { return this->name == _name; }
- private:
- UnicodeString name;
- NFRuleList rules;
- NFRule *negativeNumberRule;
- NFRule *fractionRules[3];
- UBool fIsFractionRuleSet;
- UBool fIsPublic;
+ void format(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
+ void format(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
- NFRuleSet(const NFRuleSet &other); // forbid copying of this class
- NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class
+ UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, Formattable& result, UBool lenient=FALSE) const;
+
+ void appendRules(UnicodeString& result) const; // toString
+
+ void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status);
+
+ const RuleBasedNumberFormat *getOwner() const { return owner; }
+private:
+ const NFRule * findNormalRule(int64_t number) const;
+ const NFRule * findDoubleRule(double number) const;
+ const NFRule * findFractionRuleSetRule(double number) const;
+
+ friend class NFSubstitution;
+
+private:
+ UnicodeString name;
+ NFRuleList rules;
+ NFRule *nonNumericalRules[6];
+ RuleBasedNumberFormat *owner;
+ NFRuleList fractionRules;
+ UBool fIsFractionRuleSet;
+ UBool fIsPublic;
+ UBool fIsParseable;
+
+ NFRuleSet(const NFRuleSet &other); // forbid copying of this class
+ NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class
};
// utilities from old llong.h
int64_t util64_fromDouble(double d);
// raise radix to the power exponent, only non-negative exponents
-int64_t util64_pow(int32_t radix, uint32_t exponent);
+// Arithmetic is performed in unsigned space since overflow in
+// signed space is undefined behavior.
+uint64_t util64_pow(uint32_t radix, uint16_t exponent);
// convert n to digit string in buffer, return length of string
uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
-int64_t util64_utoi(const UChar* str, uint32_t radix = 10);
#ifdef RBNF_DEBUG
+int64_t util64_utoi(const UChar* str, uint32_t radix = 10);
uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
int64_t util64_atoi(const char* str, uint32_t radix);
#endif
// NFRS_H
#endif
-