intl/icu/source/i18n/nfrule.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /*
     2 *******************************************************************************
     3 * Copyright (C) 1997-2008, International Business Machines
     4 * Corporation and others. All Rights Reserved.
     5 *******************************************************************************
     6 */
     8 #ifndef NFRULE_H
     9 #define NFRULE_H
    11 #include "unicode/rbnf.h"
    13 #if U_HAVE_RBNF
    15 #include "unicode/utypes.h"
    16 #include "unicode/uobject.h"
    17 #include "unicode/unistr.h"
    18 #include "putilimp.h"
    20 U_NAMESPACE_BEGIN
    22 class FieldPosition;
    23 class Formattable;
    24 class NFRuleList;
    25 class NFRuleSet;
    26 class NFSubstitution;
    27 class ParsePosition;
    28 class RuleBasedNumberFormat;
    29 class UnicodeString;
    31 class NFRule : public UMemory {
    32 public:
    34     enum ERuleType {
    35         kNoBase = 0,
    36         kNegativeNumberRule = -1,
    37         kImproperFractionRule = -2,
    38         kProperFractionRule = -3,
    39         kMasterRule = -4,
    40         kOtherRule = -5
    41     };
    43     static void makeRules(UnicodeString& definition,
    44                           const NFRuleSet* ruleSet, 
    45                           const NFRule* predecessor, 
    46                           const RuleBasedNumberFormat* rbnf, 
    47                           NFRuleList& ruleList,
    48                           UErrorCode& status);
    50     NFRule(const RuleBasedNumberFormat* rbnf);
    51     ~NFRule();
    53     UBool operator==(const NFRule& rhs) const;
    54     UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); }
    56     ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERuleType)baseValue : kOtherRule); }
    57     void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; }
    59     int64_t getBaseValue() const { return baseValue; }
    60     void setBaseValue(int64_t value, UErrorCode& status);
    62     double getDivisor() const { return uprv_pow(radix, exponent); }
    64     void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos) const;
    65     void doFormat(double  number, UnicodeString& toAppendTo, int32_t pos) const;
    67     UBool doParse(const UnicodeString& text, 
    68                   ParsePosition& pos, 
    69                   UBool isFractional, 
    70                   double upperBound,
    71                   Formattable& result) const;
    73     UBool shouldRollBack(double number) const;
    75     void _appendRuleText(UnicodeString& result) const;
    77 private:
    78     void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status);
    79     void extractSubstitutions(const NFRuleSet* ruleSet, const NFRule* predecessor, const RuleBasedNumberFormat* rbnf, UErrorCode& status);
    80     NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule* predecessor, const RuleBasedNumberFormat* rbnf, UErrorCode& status);
    82     int16_t expectedExponent() const;
    83     int32_t indexOfAny(const UChar* const strings[]) const;
    84     double matchToDelimiter(const UnicodeString& text, int32_t startPos, double baseValue,
    85                             const UnicodeString& delimiter, ParsePosition& pp, const NFSubstitution* sub, 
    86                             double upperBound) const;
    87     void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const;
    89     int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErrorCode& status) const;
    90     UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const;
    91     int32_t findText(const UnicodeString& str, const UnicodeString& key, 
    92                      int32_t startingAt, int32_t* resultCount) const;
    94 private:
    95     int64_t baseValue;
    96     int32_t radix;
    97     int16_t exponent;
    98     UnicodeString ruleText;
    99     NFSubstitution* sub1;
   100     NFSubstitution* sub2;
   101     const RuleBasedNumberFormat* formatter;
   103     NFRule(const NFRule &other); // forbid copying of this class
   104     NFRule &operator=(const NFRule &other); // forbid copying of this class
   105 };
   107 U_NAMESPACE_END
   109 /* U_HAVE_RBNF */
   110 #endif
   112 // NFRULE_H
   113 #endif

mercurial