nfrs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. * Copyright (C) 1997-2015, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. ******************************************************************************
  8. * file name: nfrs.h
  9. * encoding: UTF-8
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * Modification history
  14. * Date Name Comments
  15. * 10/11/2001 Doug Ported from ICU4J
  16. */
  17. #ifndef NFRS_H
  18. #define NFRS_H
  19. #include "unicode/uobject.h"
  20. #include "unicode/rbnf.h"
  21. #if U_HAVE_RBNF
  22. #include "unicode/utypes.h"
  23. #include "unicode/umisc.h"
  24. #include "nfrlist.h"
  25. U_NAMESPACE_BEGIN
  26. class NFRuleSet : public UMemory {
  27. public:
  28. NFRuleSet(RuleBasedNumberFormat *owner, UnicodeString* descriptions, int32_t index, UErrorCode& status);
  29. void parseRules(UnicodeString& rules, UErrorCode& status);
  30. void setNonNumericalRule(NFRule *rule);
  31. void setBestFractionRule(int32_t originalIndex, NFRule *newRule, UBool rememberRule);
  32. void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; }
  33. ~NFRuleSet();
  34. UBool operator==(const NFRuleSet& rhs) const;
  35. UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); }
  36. UBool isPublic() const { return fIsPublic; }
  37. UBool isParseable() const { return fIsParseable; }
  38. UBool isFractionRuleSet() const { return fIsFractionRuleSet; }
  39. void getName(UnicodeString& result) const { result.setTo(name); }
  40. UBool isNamed(const UnicodeString& _name) const { return this->name == _name; }
  41. void format(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
  42. void format(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
  43. UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, Formattable& result) const;
  44. void appendRules(UnicodeString& result) const; // toString
  45. void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status);
  46. const RuleBasedNumberFormat *getOwner() const { return owner; }
  47. private:
  48. const NFRule * findNormalRule(int64_t number) const;
  49. const NFRule * findDoubleRule(double number) const;
  50. const NFRule * findFractionRuleSetRule(double number) const;
  51. friend class NFSubstitution;
  52. private:
  53. UnicodeString name;
  54. NFRuleList rules;
  55. NFRule *nonNumericalRules[6];
  56. RuleBasedNumberFormat *owner;
  57. NFRuleList fractionRules;
  58. UBool fIsFractionRuleSet;
  59. UBool fIsPublic;
  60. UBool fIsParseable;
  61. NFRuleSet(const NFRuleSet &other); // forbid copying of this class
  62. NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class
  63. };
  64. // utilities from old llong.h
  65. // convert mantissa portion of double to int64
  66. int64_t util64_fromDouble(double d);
  67. // raise radix to the power exponent, only non-negative exponents
  68. // Arithmetic is performed in unsigned space since overflow in
  69. // signed space is undefined behavior.
  70. uint64_t util64_pow(uint32_t radix, uint16_t exponent);
  71. // convert n to digit string in buffer, return length of string
  72. uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
  73. #ifdef RBNF_DEBUG
  74. int64_t util64_utoi(const UChar* str, uint32_t radix = 10);
  75. uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
  76. int64_t util64_atoi(const char* str, uint32_t radix);
  77. #endif
  78. U_NAMESPACE_END
  79. /* U_HAVE_RBNF */
  80. #endif
  81. // NFRS_H
  82. #endif