]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/nfsubs.h
2 ******************************************************************************
3 * Copyright (C) 1997-2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************
8 * tab size: 8 (not used)
11 * Modification history
13 * 10/11/2001 Doug Ported from ICU4J
19 #include "unicode/utypes.h"
20 #include "unicode/uobject.h"
25 #include "unicode/utypes.h"
26 #include "unicode/decimfmt.h"
32 class NFSubstitution
: public UObject
{
34 const NFRuleSet
* ruleSet
;
35 DecimalFormat
* numberFormat
;
38 NFSubstitution(int32_t pos
,
39 const NFRuleSet
* ruleSet
,
40 const UnicodeString
& description
,
44 * Get the Ruleset of the object.
45 * @return the Ruleset of the object.
47 const NFRuleSet
* getRuleSet() const { return ruleSet
; }
50 * get the NumberFormat of this object.
51 * @return the numberformat of this object.
53 const DecimalFormat
* getNumberFormat() const { return numberFormat
; }
56 static NFSubstitution
* makeSubstitution(int32_t pos
,
58 const NFRule
* predecessor
,
59 const NFRuleSet
* ruleSet
,
60 const RuleBasedNumberFormat
* rbnf
,
61 const UnicodeString
& description
,
67 virtual ~NFSubstitution();
70 * Return true if the given Format objects are semantically equal.
71 * Objects of different subclasses are considered unequal.
72 * @param rhs the object to be compared with.
73 * @return true if the given Format objects are semantically equal.
75 virtual UBool
operator==(const NFSubstitution
& rhs
) const;
78 * Return true if the given Format objects are semantically unequal.
79 * Objects of different subclasses are considered unequal.
80 * @param rhs the object to be compared with.
81 * @return true if the given Format objects are semantically unequal.
83 UBool
operator!=(const NFSubstitution
& rhs
) const { return !operator==(rhs
); }
86 * Sets the substitution's divisor. Used by NFRule.setBaseValue().
87 * A no-op for all substitutions except multiplier and modulus
89 * @param radix The radix of the divisor
90 * @param exponent The exponent of the divisor
92 virtual void setDivisor(int32_t radix
, int32_t exponent
, UErrorCode
& status
);
95 * Replaces result with the string describing the substitution.
96 * @param result Output param which will receive the string.
98 virtual void toString(UnicodeString
& result
) const;
100 void setDecimalFormatSymbols(const DecimalFormatSymbols
&newSymbols
, UErrorCode
& status
);
102 //-----------------------------------------------------------------------
104 //-----------------------------------------------------------------------
107 * Performs a mathematical operation on the number, formats it using
108 * either ruleSet or decimalFormat, and inserts the result into
110 * @param number The number being formatted.
111 * @param toInsertInto The string we insert the result into
112 * @param pos The position in toInsertInto where the owning rule's
113 * rule text begins (this value is added to this substitution's
114 * position to determine exactly where to insert the new text)
116 virtual void doSubstitution(int64_t number
, UnicodeString
& toInsertInto
, int32_t pos
, int32_t recursionCount
, UErrorCode
& status
) const;
119 * Performs a mathematical operation on the number, formats it using
120 * either ruleSet or decimalFormat, and inserts the result into
122 * @param number The number being formatted.
123 * @param toInsertInto The string we insert the result into
124 * @param pos The position in toInsertInto where the owning rule's
125 * rule text begins (this value is added to this substitution's
126 * position to determine exactly where to insert the new text)
128 virtual void doSubstitution(double number
, UnicodeString
& toInsertInto
, int32_t pos
, int32_t recursionCount
, UErrorCode
& status
) const;
132 * Subclasses override this function to perform some kind of
133 * mathematical operation on the number. The result of this operation
134 * is formatted using the rule set or DecimalFormat that this
135 * substitution refers to, and the result is inserted into the result
137 * @param The number being formatted
138 * @return The result of performing the opreration on the number
140 virtual int64_t transformNumber(int64_t number
) const = 0;
143 * Subclasses override this function to perform some kind of
144 * mathematical operation on the number. The result of this operation
145 * is formatted using the rule set or DecimalFormat that this
146 * substitution refers to, and the result is inserted into the result
148 * @param The number being formatted
149 * @return The result of performing the opreration on the number
151 virtual double transformNumber(double number
) const = 0;
154 //-----------------------------------------------------------------------
156 //-----------------------------------------------------------------------
159 * Parses a string using the rule set or DecimalFormat belonging
160 * to this substitution. If there's a match, a mathematical
161 * operation (the inverse of the one used in formatting) is
162 * performed on the result of the parse and the value passed in
163 * and returned as the result. The parse position is updated to
164 * point to the first unmatched character in the string.
165 * @param text The string to parse
166 * @param parsePosition On entry, ignored, but assumed to be 0.
167 * On exit, this is updated to point to the first unmatched
168 * character (or 0 if the substitution didn't match)
169 * @param baseValue A partial parse result that should be
170 * combined with the result of this parse
171 * @param upperBound When searching the rule set for a rule
172 * matching the string passed in, only rules with base values
173 * lower than this are considered
174 * @param lenientParse If true and matching against rules fails,
175 * the substitution will also try matching the text against
176 * numerals using a default-costructed NumberFormat. If false,
177 * no extra work is done. (This value is false whenever the
178 * formatter isn't in lenient-parse mode, but is also false
179 * under some conditions even when the formatter _is_ in
180 * lenient-parse mode.)
181 * @return If there's a match, this is the result of composing
182 * baseValue with whatever was returned from matching the
183 * characters. This will be either a Long or a Double. If there's
184 * no match this is new Long(0) (not null), and parsePosition
187 virtual UBool
doParse(const UnicodeString
& text
,
188 ParsePosition
& parsePosition
,
192 Formattable
& result
) const;
195 * Derives a new value from the two values passed in. The two values
196 * are typically either the base values of two rules (the one containing
197 * the substitution and the one matching the substitution) or partial
198 * parse results derived in some other way. The operation is generally
199 * the inverse of the operation performed by transformNumber().
200 * @param newRuleValue The value produced by matching this substitution
201 * @param oldRuleValue The value that was passed to the substitution
202 * by the rule that owns it
203 * @return A third value derived from the other two, representing a
204 * partial parse result
206 virtual double composeRuleValue(double newRuleValue
, double oldRuleValue
) const = 0;
209 * Calculates an upper bound when searching for a rule that matches
210 * this substitution. Rules with base values greater than or equal
211 * to upperBound are not considered.
212 * @param oldUpperBound The current upper-bound setting. The new
213 * upper bound can't be any higher.
214 * @return the upper bound when searching for a rule that matches
217 virtual double calcUpperBound(double oldUpperBound
) const = 0;
219 //-----------------------------------------------------------------------
221 //-----------------------------------------------------------------------
224 * Returns the substitution's position in the rule that owns it.
225 * @return The substitution's position in the rule that owns it.
227 int32_t getPos() const { return pos
; }
230 * Returns the character used in the textual representation of
231 * substitutions of this type. Used by toString().
232 * @return This substitution's token character.
234 virtual UChar
tokenChar() const = 0;
237 * Returns true if this is a modulus substitution. (We didn't do this
238 * with instanceof partially because it causes source files to
239 * proliferate and partially because we have to port this to C++.)
240 * @return true if this object is an instance of ModulusSubstitution
242 virtual UBool
isModulusSubstitution() const;
246 * @return true if this is a decimal format-only substitution
248 virtual UBool
isDecimalFormatSubstitutionOnly() const;
251 * Apple addition, not currently used
252 * @return true if this substitution only points to another ruleSet (no numberFormat)
254 //virtual UBool isRuleSetSubstitutionOnly() const;
257 NFSubstitution(const NFSubstitution
&other
); // forbid copying of this class
258 NFSubstitution
&operator=(const NFSubstitution
&other
); // forbid copying of this class
261 static UClassID
getStaticClassID(void);
262 virtual UClassID
getDynamicClassID(void) const;