~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/i18n/nfrule.h

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/unistr.h"
16
 
 
17
 
U_NAMESPACE_BEGIN
18
 
 
19
 
class FieldPosition;
20
 
class Formattable;
21
 
class NFRuleList;
22
 
class NFRuleSet;
23
 
class NFSubstitution;
24
 
class ParsePosition;
25
 
class RuleBasedNumberFormat;
26
 
class UnicodeString;
27
 
 
28
 
class NFRule {
29
 
public:
30
 
 
31
 
    enum ERuleType {
32
 
        kNoBase = 0,
33
 
        kNegativeNumberRule = -1,
34
 
        kImproperFractionRule = -2,
35
 
        kProperFractionRule = -3,
36
 
        kMasterRule = -4,
37
 
        kOtherRule = -5
38
 
    };
39
 
 
40
 
    static void makeRules(UnicodeString& definition,
41
 
                          const NFRuleSet* ruleSet, 
42
 
                          const NFRule* predecessor, 
43
 
                          const RuleBasedNumberFormat* rbnf, 
44
 
                          NFRuleList& ruleList,
45
 
                          UErrorCode& status);
46
 
 
47
 
    NFRule(const RuleBasedNumberFormat* rbnf);
48
 
    ~NFRule();
49
 
 
50
 
    UBool operator==(const NFRule& rhs) const;
51
 
    UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); }
52
 
 
53
 
    ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERuleType)baseValue : kOtherRule); }
54
 
    void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; }
55
 
 
56
 
    int64_t getBaseValue() const { return baseValue; }
57
 
    void setBaseValue(int64_t value);
58
 
 
59
 
    double getDivisor() const { return uprv_pow(radix, exponent); }
60
 
 
61
 
    void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos) const;
62
 
    void doFormat(double  number, UnicodeString& toAppendTo, int32_t pos) const;
63
 
 
64
 
    UBool doParse(const UnicodeString& text, 
65
 
                  ParsePosition& pos, 
66
 
                  UBool isFractional, 
67
 
                  double upperBound,
68
 
                  Formattable& result) const;
69
 
 
70
 
    UBool shouldRollBack(double number) const;
71
 
 
72
 
    void appendRuleText(UnicodeString& result) const;
73
 
 
74
 
private:
75
 
    void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status);
76
 
    void extractSubstitutions(const NFRuleSet* ruleSet, const NFRule* predecessor, const RuleBasedNumberFormat* rbnf, UErrorCode& status);
77
 
    NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule* predecessor, const RuleBasedNumberFormat* rbnf, UErrorCode& status);
78
 
    
79
 
    int16_t expectedExponent() const;
80
 
    int32_t indexOfAny(const UChar* const strings[]) const;
81
 
    double matchToDelimiter(const UnicodeString& text, int32_t startPos, double baseValue,
82
 
                            const UnicodeString& delimiter, ParsePosition& pp, const NFSubstitution* sub, 
83
 
                            double upperBound) const;
84
 
    void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const;
85
 
 
86
 
    int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix) const;
87
 
    UBool allIgnorable(const UnicodeString& str) const;
88
 
    int32_t findText(const UnicodeString& str, const UnicodeString& key, 
89
 
                     int32_t startingAt, int32_t* resultCount) const;
90
 
 
91
 
private:
92
 
    int64_t baseValue;
93
 
    int16_t radix;
94
 
    int16_t exponent;
95
 
    UnicodeString ruleText;
96
 
    NFSubstitution* sub1;
97
 
    NFSubstitution* sub2;
98
 
    const RuleBasedNumberFormat* formatter;
99
 
};
100
 
 
101
 
U_NAMESPACE_END
102
 
 
103
 
/* U_HAVE_RBNF */
104
 
#endif
105
 
 
106
 
// NFRULE_H
107
 
#endif
108