]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/nfrs.h
ICU-511.35.tar.gz
[apple/icu.git] / icuSources / i18n / nfrs.h
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
4388f060 3* Copyright (C) 1997-2012, International Business Machines
b75a7d8f
A
4* Corporation and others. All Rights Reserved.
5******************************************************************************
6* file name: nfrs.h
7* encoding: US-ASCII
8* tab size: 8 (not used)
9* indentation:4
10*
11* Modification history
12* Date Name Comments
13* 10/11/2001 Doug Ported from ICU4J
14*/
15
16#ifndef NFRS_H
17#define NFRS_H
18
19#include "unicode/uobject.h"
20#include "unicode/rbnf.h"
21
22#if U_HAVE_RBNF
23
24#include "unicode/utypes.h"
25#include "unicode/umisc.h"
26
27#include "nfrlist.h"
28
29U_NAMESPACE_BEGIN
30
31class NFRuleSet : public UMemory {
32 public:
33 NFRuleSet(UnicodeString* descriptions, int32_t index, UErrorCode& status);
34 void parseRules(UnicodeString& rules, const RuleBasedNumberFormat* owner, UErrorCode& status);
35 void makeIntoFractionRuleSet() { fIsFractionRuleSet = TRUE; }
36
37 ~NFRuleSet();
38
39 UBool operator==(const NFRuleSet& rhs) const;
40 UBool operator!=(const NFRuleSet& rhs) const { return !operator==(rhs); }
41
42 UBool isPublic() const { return fIsPublic; }
729e4ab9 43
4388f060 44 UBool isParseable() const { return fIsParseable; }
729e4ab9
A
45
46 UBool isDecimalFormatRuleParseable() const {
47 UnicodeString numberingYear = UNICODE_STRING_SIMPLE("spellout-numbering-year");
48 UnicodeString ordinal = UNICODE_STRING_SIMPLE("spellout-ordinal");
49
50 return ( name.indexOf(numberingYear) == -1 && name.indexOf(ordinal) == -1 );
51 }
52
b75a7d8f
A
53 UBool isFractionRuleSet() const { return fIsFractionRuleSet; }
54
55 void getName(UnicodeString& result) const { result.setTo(name); }
56 UBool isNamed(const UnicodeString& _name) const { return this->name == _name; }
57
58 void format(int64_t number, UnicodeString& toAppendTo, int32_t pos) const;
59 void format(double number, UnicodeString& toAppendTo, int32_t pos) const;
60
729e4ab9 61 UBool parse(const UnicodeString& text, ParsePosition& pos, double upperBound, Formattable& result, UBool lenient=FALSE) const;
b75a7d8f
A
62
63 void appendRules(UnicodeString& result) const; // toString
64
65 private:
66 NFRule * findNormalRule(int64_t number) const;
67 NFRule * findDoubleRule(double number) const;
68 NFRule * findFractionRuleSetRule(double number) const;
69
70 private:
71 UnicodeString name;
72 NFRuleList rules;
73 NFRule *negativeNumberRule;
74 NFRule *fractionRules[3];
75 UBool fIsFractionRuleSet;
76 UBool fIsPublic;
4388f060 77 UBool fIsParseable;
374ca955 78 int32_t fRecursionCount;
b75a7d8f
A
79
80 NFRuleSet(const NFRuleSet &other); // forbid copying of this class
81 NFRuleSet &operator=(const NFRuleSet &other); // forbid copying of this class
82};
83
84// utilities from old llong.h
85// convert mantissa portion of double to int64
86int64_t util64_fromDouble(double d);
87
88// raise radix to the power exponent, only non-negative exponents
89int64_t util64_pow(int32_t radix, uint32_t exponent);
90
91// convert n to digit string in buffer, return length of string
92uint32_t util64_tou(int64_t n, UChar* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
b75a7d8f
A
93
94#ifdef RBNF_DEBUG
73c04bcf 95int64_t util64_utoi(const UChar* str, uint32_t radix = 10);
b75a7d8f
A
96uint32_t util64_toa(int64_t n, char* buffer, uint32_t buflen, uint32_t radix = 10, UBool raw = FALSE);
97int64_t util64_atoi(const char* str, uint32_t radix);
98#endif
99
100
101U_NAMESPACE_END
102
103/* U_HAVE_RBNF */
104#endif
105
106// NFRS_H
107#endif
108