michael@0: /* michael@0: ****************************************************************************** michael@0: * Copyright (C) 1997-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ****************************************************************************** michael@0: * file name: nfrs.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * Modification history michael@0: * Date Name Comments michael@0: * 10/11/2001 Doug Ported from ICU4J michael@0: */ michael@0: michael@0: #ifndef NFRS_H michael@0: #define NFRS_H michael@0: michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/rbnf.h" michael@0: michael@0: #if U_HAVE_RBNF michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/umisc.h" michael@0: michael@0: #include "nfrlist.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class NFRuleSet : public UMemory { michael@0: public: michael@0: NFRuleSet(UnicodeString* descriptions, int32_t index, UErrorCode& status); michael@0: void parseRules(UnicodeString& rules, const RuleBasedNumberFormat* owner, UErrorCode& status); michael@0: void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; } michael@0: michael@0: ~NFRuleSet(); michael@0: michael@0: UBool operator==(const NFRuleSet& rhs) const; michael@0: UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); } michael@0: michael@0: UBool isPublic() const { return fIsPublic; } michael@0: michael@0: UBool isParseable() const { return fIsParseable; } michael@0: michael@0: UBool isFractionRuleSet() const { return fIsFractionRuleSet; } michael@0: michael@0: void getName(UnicodeString& result) const { result.setTo(name); } michael@0: UBool isNamed(const UnicodeString& _name) const { return this->name == _name; } michael@0: michael@0: void format(int64_t number, UnicodeString& toAppendTo, int32_t pos) const; michael@0: void format(double number, UnicodeString& toAppendTo, int32_t pos) const; michael@0: michael@0: UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, Formattable& result) const; michael@0: michael@0: void appendRules(UnicodeString& result) const; // toString michael@0: michael@0: private: michael@0: NFRule * findNormalRule(int64_t number) const; michael@0: NFRule * findDoubleRule(double number) const; michael@0: NFRule * findFractionRuleSetRule(double number) const; michael@0: michael@0: private: michael@0: UnicodeString name; michael@0: NFRuleList rules; michael@0: NFRule *negativeNumberRule; michael@0: NFRule *fractionRules[3]; michael@0: UBool fIsFractionRuleSet; michael@0: UBool fIsPublic; michael@0: UBool fIsParseable; michael@0: int32_t fRecursionCount; michael@0: michael@0: NFRuleSet(const NFRuleSet &other); // forbid copying of this class michael@0: NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class michael@0: }; michael@0: michael@0: // utilities from old llong.h michael@0: // convert mantissa portion of double to int64 michael@0: int64_t util64_fromDouble(double d); michael@0: michael@0: // raise radix to the power exponent, only non-negative exponents michael@0: int64_t util64_pow(int32_t radix, uint32_t exponent); michael@0: michael@0: // convert n to digit string in buffer, return length of string michael@0: uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE); michael@0: michael@0: #ifdef RBNF_DEBUG michael@0: int64_t util64_utoi(const UChar* str, uint32_t radix = 10); michael@0: uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE); michael@0: int64_t util64_atoi(const char* str, uint32_t radix); michael@0: #endif michael@0: michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: /* U_HAVE_RBNF */ michael@0: #endif michael@0: michael@0: // NFRS_H michael@0: #endif michael@0: