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