2001-10-10 21:43:11 +00:00
|
|
|
/*
|
2001-10-11 16:56:24 +00:00
|
|
|
******************************************************************************
|
2006-03-22 07:57:49 +00:00
|
|
|
* Copyright (C) 1997-2006, International Business Machines
|
2001-10-11 16:56:24 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
******************************************************************************
|
|
|
|
* file name: nfsubs.h
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* Modification history
|
|
|
|
* Date Name Comments
|
|
|
|
* 10/11/2001 Doug Ported from ICU4J
|
2001-10-10 21:43:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NFSUBS_H
|
|
|
|
#define NFSUBS_H
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uobject.h"
|
2002-03-14 00:28:22 +00:00
|
|
|
#include "nfrule.h"
|
2002-06-27 01:19:20 +00:00
|
|
|
|
2002-03-14 00:28:22 +00:00
|
|
|
#if U_HAVE_RBNF
|
|
|
|
|
2001-10-10 21:43:11 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/decimfmt.h"
|
|
|
|
#include "nfrs.h"
|
2001-10-12 17:47:17 +00:00
|
|
|
#include <float.h>
|
2001-10-10 21:43:11 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
class NFSubstitution : public UObject {
|
2001-10-11 16:56:24 +00:00
|
|
|
int32_t pos;
|
|
|
|
const NFRuleSet* ruleSet;
|
|
|
|
const DecimalFormat* numberFormat;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
NFSubstitution(int32_t pos,
|
|
|
|
const NFRuleSet* ruleSet,
|
|
|
|
const RuleBasedNumberFormat* rbnf,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
2002-07-01 11:04:45 +00:00
|
|
|
/**
|
|
|
|
* Get the Ruleset of the object.
|
|
|
|
* @return the Ruleset of the object.
|
|
|
|
*/
|
2001-10-11 16:56:24 +00:00
|
|
|
const NFRuleSet* getRuleSet() const { return ruleSet; }
|
2002-07-01 11:04:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get the NumberFormat of this object.
|
|
|
|
* @return the numberformat of this object.
|
|
|
|
*/
|
2001-10-11 16:56:24 +00:00
|
|
|
const DecimalFormat* getNumberFormat() const { return numberFormat; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
static NFSubstitution* makeSubstitution(int32_t pos,
|
|
|
|
const NFRule* rule,
|
|
|
|
const NFRule* predecessor,
|
|
|
|
const NFRuleSet* ruleSet,
|
|
|
|
const RuleBasedNumberFormat* rbnf,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
2002-07-01 11:04:45 +00:00
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2001-10-11 16:56:24 +00:00
|
|
|
virtual ~NFSubstitution();
|
|
|
|
|
2002-07-01 11:04:45 +00:00
|
|
|
/**
|
|
|
|
* Return true if the given Format objects are semantically equal.
|
|
|
|
* Objects of different subclasses are considered unequal.
|
|
|
|
* @param rhs the object to be compared with.
|
|
|
|
* @return true if the given Format objects are semantically equal.
|
|
|
|
*/
|
2001-10-11 16:56:24 +00:00
|
|
|
virtual UBool operator==(const NFSubstitution& rhs) const;
|
2002-07-01 11:04:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the given Format objects are semantically unequal.
|
|
|
|
* Objects of different subclasses are considered unequal.
|
|
|
|
* @param rhs the object to be compared with.
|
|
|
|
* @return true if the given Format objects are semantically unequal.
|
|
|
|
*/
|
2001-10-11 16:56:24 +00:00
|
|
|
UBool operator!=(const NFSubstitution& rhs) const { return !operator==(rhs); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the substitution's divisor. Used by NFRule.setBaseValue().
|
|
|
|
* A no-op for all substitutions except multiplier and modulus
|
|
|
|
* substitutions.
|
|
|
|
* @param radix The radix of the divisor
|
|
|
|
* @param exponent The exponent of the divisor
|
|
|
|
*/
|
2004-04-09 19:58:58 +00:00
|
|
|
virtual void setDivisor(int32_t radix, int32_t exponent, UErrorCode& status);
|
2001-10-11 16:56:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces result with the string describing the substitution.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param result Output param which will receive the string.
|
2001-10-11 16:56:24 +00:00
|
|
|
*/
|
|
|
|
virtual void toString(UnicodeString& result) const;
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
// formatting
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs a mathematical operation on the number, formats it using
|
|
|
|
* either ruleSet or decimalFormat, and inserts the result into
|
|
|
|
* toInsertInto.
|
|
|
|
* @param number The number being formatted.
|
|
|
|
* @param toInsertInto The string we insert the result into
|
|
|
|
* @param pos The position in toInsertInto where the owning rule's
|
|
|
|
* rule text begins (this value is added to this substitution's
|
|
|
|
* position to determine exactly where to insert the new text)
|
|
|
|
*/
|
2002-03-14 00:28:22 +00:00
|
|
|
virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t pos) const;
|
2002-07-01 11:04:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs a mathematical operation on the number, formats it using
|
|
|
|
* either ruleSet or decimalFormat, and inserts the result into
|
|
|
|
* toInsertInto.
|
|
|
|
* @param number The number being formatted.
|
|
|
|
* @param toInsertInto The string we insert the result into
|
|
|
|
* @param pos The position in toInsertInto where the owning rule's
|
|
|
|
* rule text begins (this value is added to this substitution's
|
|
|
|
* position to determine exactly where to insert the new text)
|
|
|
|
*/
|
2001-10-11 16:56:24 +00:00
|
|
|
virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Subclasses override this function to perform some kind of
|
|
|
|
* mathematical operation on the number. The result of this operation
|
|
|
|
* is formatted using the rule set or DecimalFormat that this
|
|
|
|
* substitution refers to, and the result is inserted into the result
|
|
|
|
* string.
|
|
|
|
* @param The number being formatted
|
|
|
|
* @return The result of performing the opreration on the number
|
|
|
|
*/
|
2002-03-14 00:28:22 +00:00
|
|
|
virtual int64_t transformNumber(int64_t number) const = 0;
|
2002-07-01 11:04:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subclasses override this function to perform some kind of
|
|
|
|
* mathematical operation on the number. The result of this operation
|
|
|
|
* is formatted using the rule set or DecimalFormat that this
|
|
|
|
* substitution refers to, and the result is inserted into the result
|
|
|
|
* string.
|
|
|
|
* @param The number being formatted
|
|
|
|
* @return The result of performing the opreration on the number
|
|
|
|
*/
|
2001-10-11 16:56:24 +00:00
|
|
|
virtual double transformNumber(double number) const = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
// parsing
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses a string using the rule set or DecimalFormat belonging
|
|
|
|
* to this substitution. If there's a match, a mathematical
|
|
|
|
* operation (the inverse of the one used in formatting) is
|
|
|
|
* performed on the result of the parse and the value passed in
|
|
|
|
* and returned as the result. The parse position is updated to
|
|
|
|
* point to the first unmatched character in the string.
|
|
|
|
* @param text The string to parse
|
|
|
|
* @param parsePosition On entry, ignored, but assumed to be 0.
|
|
|
|
* On exit, this is updated to point to the first unmatched
|
|
|
|
* character (or 0 if the substitution didn't match)
|
|
|
|
* @param baseValue A partial parse result that should be
|
|
|
|
* combined with the result of this parse
|
|
|
|
* @param upperBound When searching the rule set for a rule
|
|
|
|
* matching the string passed in, only rules with base values
|
|
|
|
* lower than this are considered
|
|
|
|
* @param lenientParse If true and matching against rules fails,
|
|
|
|
* the substitution will also try matching the text against
|
|
|
|
* numerals using a default-costructed NumberFormat. If false,
|
|
|
|
* no extra work is done. (This value is false whenever the
|
|
|
|
* formatter isn't in lenient-parse mode, but is also false
|
|
|
|
* under some conditions even when the formatter _is_ in
|
|
|
|
* lenient-parse mode.)
|
|
|
|
* @return If there's a match, this is the result of composing
|
|
|
|
* baseValue with whatever was returned from matching the
|
|
|
|
* characters. This will be either a Long or a Double. If there's
|
|
|
|
* no match this is new Long(0) (not null), and parsePosition
|
|
|
|
* is left unchanged.
|
|
|
|
*/
|
|
|
|
virtual UBool doParse(const UnicodeString& text,
|
|
|
|
ParsePosition& parsePosition,
|
|
|
|
double baseValue,
|
2001-10-10 21:43:11 +00:00
|
|
|
double upperBound,
|
2001-10-11 16:56:24 +00:00
|
|
|
UBool lenientParse,
|
|
|
|
Formattable& result) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Derives a new value from the two values passed in. The two values
|
|
|
|
* are typically either the base values of two rules (the one containing
|
|
|
|
* the substitution and the one matching the substitution) or partial
|
|
|
|
* parse results derived in some other way. The operation is generally
|
|
|
|
* the inverse of the operation performed by transformNumber().
|
|
|
|
* @param newRuleValue The value produced by matching this substitution
|
|
|
|
* @param oldRuleValue The value that was passed to the substitution
|
|
|
|
* by the rule that owns it
|
|
|
|
* @return A third value derived from the other two, representing a
|
|
|
|
* partial parse result
|
|
|
|
*/
|
|
|
|
virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates an upper bound when searching for a rule that matches
|
|
|
|
* this substitution. Rules with base values greater than or equal
|
|
|
|
* to upperBound are not considered.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param oldUpperBound The current upper-bound setting. The new
|
|
|
|
* upper bound can't be any higher.
|
|
|
|
* @return the upper bound when searching for a rule that matches
|
|
|
|
* this substitution.
|
2001-10-11 16:56:24 +00:00
|
|
|
*/
|
|
|
|
virtual double calcUpperBound(double oldUpperBound) const = 0;
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
// simple accessors
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the substitution's position in the rule that owns it.
|
|
|
|
* @return The substitution's position in the rule that owns it.
|
|
|
|
*/
|
|
|
|
int32_t getPos() const { return pos; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the character used in the textual representation of
|
|
|
|
* substitutions of this type. Used by toString().
|
|
|
|
* @return This substitution's token character.
|
|
|
|
*/
|
|
|
|
virtual UChar tokenChar() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this is a null substitution. (We didn't do this
|
|
|
|
* with instanceof partially because it causes source files to
|
|
|
|
* proliferate and partially because we have to port this to C++.)
|
|
|
|
* @return true if this object is an instance of NullSubstitution
|
|
|
|
*/
|
|
|
|
virtual UBool isNullSubstitution() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this is a modulus substitution. (We didn't do this
|
|
|
|
* with instanceof partially because it causes source files to
|
|
|
|
* proliferate and partially because we have to port this to C++.)
|
|
|
|
* @return true if this object is an instance of ModulusSubstitution
|
|
|
|
*/
|
|
|
|
virtual UBool isModulusSubstitution() const;
|
|
|
|
|
|
|
|
private:
|
2002-10-04 17:47:59 +00:00
|
|
|
NFSubstitution(const NFSubstitution &other); // forbid copying of this class
|
|
|
|
NFSubstitution &operator=(const NFSubstitution &other); // forbid copying of this class
|
|
|
|
|
2001-10-11 16:56:24 +00:00
|
|
|
static const char fgClassID;
|
2002-10-04 17:47:59 +00:00
|
|
|
|
2001-10-11 16:56:24 +00:00
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SameValueSubstitution : public NFSubstitution {
|
2001-10-11 16:56:24 +00:00
|
|
|
public:
|
|
|
|
SameValueSubstitution(int32_t pos,
|
|
|
|
const NFRuleSet* ruleset,
|
|
|
|
const RuleBasedNumberFormat* formatter,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual int64_t transformNumber(int64_t number) const { return number; }
|
|
|
|
virtual double transformNumber(double number) const { return number; }
|
|
|
|
virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const { return newRuleValue; }
|
|
|
|
virtual double calcUpperBound(double oldUpperBound) const { return oldUpperBound; }
|
|
|
|
virtual UChar tokenChar() const { return (UChar)0x003d; } // '='
|
2001-10-11 16:56:24 +00:00
|
|
|
private:
|
2001-10-11 21:41:11 +00:00
|
|
|
static const char fgClassID;
|
2001-10-11 16:56:24 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MultiplierSubstitution : public NFSubstitution {
|
2001-10-11 16:56:24 +00:00
|
|
|
double divisor;
|
2002-03-14 00:28:22 +00:00
|
|
|
int64_t ldivisor;
|
2001-10-11 16:56:24 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
MultiplierSubstitution(int32_t _pos,
|
|
|
|
double _divisor,
|
|
|
|
const NFRuleSet* _ruleSet,
|
|
|
|
const RuleBasedNumberFormat* formatter,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status)
|
|
|
|
: NFSubstitution(_pos, _ruleSet, formatter, description, status), divisor(_divisor)
|
|
|
|
{
|
2002-03-14 00:28:22 +00:00
|
|
|
ldivisor = util64_fromDouble(divisor);
|
2004-04-14 18:55:19 +00:00
|
|
|
if (divisor == 0) {
|
2004-04-09 19:58:58 +00:00
|
|
|
status = U_PARSE_ERROR;
|
|
|
|
}
|
2001-10-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual void setDivisor(int32_t radix, int32_t exponent, UErrorCode& status) {
|
2001-10-11 21:41:11 +00:00
|
|
|
divisor = uprv_pow(radix, exponent);
|
2002-03-14 00:28:22 +00:00
|
|
|
ldivisor = util64_fromDouble(divisor);
|
2004-04-09 19:58:58 +00:00
|
|
|
|
2004-04-14 18:55:19 +00:00
|
|
|
if(divisor == 0) {
|
2004-04-09 19:58:58 +00:00
|
|
|
status = U_PARSE_ERROR;
|
|
|
|
}
|
2001-10-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UBool operator==(const NFSubstitution& rhs) const;
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual int64_t transformNumber(int64_t number) const {
|
2001-10-11 16:56:24 +00:00
|
|
|
return number / ldivisor;
|
|
|
|
}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual double transformNumber(double number) const {
|
2001-10-11 21:41:11 +00:00
|
|
|
return uprv_floor(number / divisor);
|
2001-10-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const {
|
2001-10-11 16:56:24 +00:00
|
|
|
return newRuleValue * divisor;
|
|
|
|
}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual double calcUpperBound(double /*oldUpperBound*/) const { return divisor; }
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UChar tokenChar() const { return (UChar)0x003c; } // '<'
|
2001-10-11 16:56:24 +00:00
|
|
|
private:
|
|
|
|
static const char fgClassID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ModulusSubstitution : public NFSubstitution {
|
2001-10-11 16:56:24 +00:00
|
|
|
double divisor;
|
2002-03-14 00:28:22 +00:00
|
|
|
int64_t ldivisor;
|
2001-10-11 16:56:24 +00:00
|
|
|
const NFRule* ruleToUse;
|
|
|
|
public:
|
|
|
|
ModulusSubstitution(int32_t pos,
|
|
|
|
double _divisor,
|
|
|
|
const NFRule* rulePredecessor,
|
|
|
|
const NFRuleSet* ruleSet,
|
|
|
|
const RuleBasedNumberFormat* formatter,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual void setDivisor(int32_t radix, int32_t exponent, UErrorCode& status) {
|
2001-10-11 21:41:11 +00:00
|
|
|
divisor = uprv_pow(radix, exponent);
|
2002-03-14 00:28:22 +00:00
|
|
|
ldivisor = util64_fromDouble(divisor);
|
2004-04-09 19:58:58 +00:00
|
|
|
|
2004-04-14 18:55:19 +00:00
|
|
|
if (divisor == 0) {
|
2004-04-09 19:58:58 +00:00
|
|
|
status = U_PARSE_ERROR;
|
|
|
|
}
|
2001-10-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UBool operator==(const NFSubstitution& rhs) const;
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t pos) const;
|
|
|
|
virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos) const;
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual int64_t transformNumber(int64_t number) const { return number % ldivisor; }
|
|
|
|
virtual double transformNumber(double number) const { return uprv_fmod(number, divisor); }
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UBool doParse(const UnicodeString& text,
|
2001-10-11 16:56:24 +00:00
|
|
|
ParsePosition& parsePosition,
|
|
|
|
double baseValue,
|
|
|
|
double upperBound,
|
|
|
|
UBool lenientParse,
|
|
|
|
Formattable& result) const;
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const {
|
2001-10-11 21:41:11 +00:00
|
|
|
return oldRuleValue - uprv_fmod(oldRuleValue, divisor) + newRuleValue;
|
2001-10-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual double calcUpperBound(double /*oldUpperBound*/) const { return divisor; }
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UBool isModulusSubstitution() const { return TRUE; }
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UChar tokenChar() const { return (UChar)0x003e; } // '>'
|
2001-10-11 16:56:24 +00:00
|
|
|
private:
|
|
|
|
static const char fgClassID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IntegralPartSubstitution : public NFSubstitution {
|
2001-10-11 16:56:24 +00:00
|
|
|
public:
|
|
|
|
IntegralPartSubstitution(int32_t _pos,
|
|
|
|
const NFRuleSet* _ruleSet,
|
|
|
|
const RuleBasedNumberFormat* formatter,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status)
|
|
|
|
: NFSubstitution(_pos, _ruleSet, formatter, description, status) {}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual int64_t transformNumber(int64_t number) const { return number; }
|
|
|
|
virtual double transformNumber(double number) const { return uprv_floor(number); }
|
|
|
|
virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue + oldRuleValue; }
|
|
|
|
virtual double calcUpperBound(double /*oldUpperBound*/) const { return DBL_MAX; }
|
|
|
|
virtual UChar tokenChar() const { return (UChar)0x003c; } // '<'
|
2001-10-11 16:56:24 +00:00
|
|
|
private:
|
|
|
|
static const char fgClassID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FractionalPartSubstitution : public NFSubstitution {
|
2001-10-11 16:56:24 +00:00
|
|
|
UBool byDigits;
|
|
|
|
UBool useSpaces;
|
|
|
|
enum { kMaxDecimalDigits = 8 };
|
|
|
|
public:
|
|
|
|
FractionalPartSubstitution(int32_t pos,
|
|
|
|
const NFRuleSet* ruleSet,
|
|
|
|
const RuleBasedNumberFormat* formatter,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UBool operator==(const NFSubstitution& rhs) const;
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos) const;
|
|
|
|
virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/) const {}
|
|
|
|
virtual int64_t transformNumber(int64_t /*number*/) const { return 0; }
|
|
|
|
virtual double transformNumber(double number) const { return number - uprv_floor(number); }
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UBool doParse(const UnicodeString& text,
|
2001-10-11 16:56:24 +00:00
|
|
|
ParsePosition& parsePosition,
|
|
|
|
double baseValue,
|
|
|
|
double upperBound,
|
|
|
|
UBool lenientParse,
|
|
|
|
Formattable& result) const;
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue + oldRuleValue; }
|
|
|
|
virtual double calcUpperBound(double /*oldUpperBound*/) const { return 0.0; }
|
|
|
|
virtual UChar tokenChar() const { return (UChar)0x003e; } // '>'
|
2001-10-11 16:56:24 +00:00
|
|
|
private:
|
|
|
|
static const char fgClassID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AbsoluteValueSubstitution : public NFSubstitution {
|
2001-10-11 16:56:24 +00:00
|
|
|
public:
|
|
|
|
AbsoluteValueSubstitution(int32_t _pos,
|
|
|
|
const NFRuleSet* _ruleSet,
|
|
|
|
const RuleBasedNumberFormat* formatter,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status)
|
|
|
|
: NFSubstitution(_pos, _ruleSet, formatter, description, status) {}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual int64_t transformNumber(int64_t number) const { return number >= 0 ? number : -number; }
|
|
|
|
virtual double transformNumber(double number) const { return uprv_fabs(number); }
|
|
|
|
virtual double composeRuleValue(double newRuleValue, double /*oldRuleValue*/) const { return -newRuleValue; }
|
|
|
|
virtual double calcUpperBound(double /*oldUpperBound*/) const { return DBL_MAX; }
|
|
|
|
virtual UChar tokenChar() const { return (UChar)0x003e; } // '>'
|
2001-10-11 16:56:24 +00:00
|
|
|
private:
|
|
|
|
static const char fgClassID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class NumeratorSubstitution : public NFSubstitution {
|
2001-10-11 16:56:24 +00:00
|
|
|
double denominator;
|
2002-03-14 00:28:22 +00:00
|
|
|
int64_t ldenominator;
|
2005-07-08 00:16:47 +00:00
|
|
|
UBool withZeros;
|
2001-10-11 16:56:24 +00:00
|
|
|
public:
|
2006-03-22 07:57:49 +00:00
|
|
|
static inline UnicodeString fixdesc(const UnicodeString& desc) {
|
|
|
|
if (desc.endsWith(LTLT, 2)) {
|
|
|
|
UnicodeString result(desc, 0, desc.length()-1);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return desc;
|
|
|
|
}
|
2001-10-11 16:56:24 +00:00
|
|
|
NumeratorSubstitution(int32_t _pos,
|
|
|
|
double _denominator,
|
|
|
|
const NFRuleSet* _ruleSet,
|
|
|
|
const RuleBasedNumberFormat* formatter,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status)
|
2005-07-08 00:16:47 +00:00
|
|
|
: NFSubstitution(_pos, _ruleSet, formatter, fixdesc(description), status), denominator(_denominator)
|
2001-10-10 21:43:11 +00:00
|
|
|
{
|
2002-03-14 00:28:22 +00:00
|
|
|
ldenominator = util64_fromDouble(denominator);
|
2005-07-09 02:13:00 +00:00
|
|
|
withZeros = description.endsWith(LTLT, 2);
|
2001-10-10 21:43:11 +00:00
|
|
|
}
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UBool operator==(const NFSubstitution& rhs) const;
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual int64_t transformNumber(int64_t number) const { return number * ldenominator; }
|
|
|
|
virtual double transformNumber(double number) const { return uprv_round(number * denominator); }
|
2001-10-11 16:56:24 +00:00
|
|
|
|
2005-07-11 20:36:49 +00:00
|
|
|
virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/) const {}
|
2005-07-08 00:16:47 +00:00
|
|
|
virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos) const;
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual UBool doParse(const UnicodeString& text,
|
2001-10-11 16:56:24 +00:00
|
|
|
ParsePosition& parsePosition,
|
|
|
|
double baseValue,
|
|
|
|
double upperBound,
|
2001-11-20 18:44:51 +00:00
|
|
|
UBool /*lenientParse*/,
|
2005-07-08 00:16:47 +00:00
|
|
|
Formattable& result) const;
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue / oldRuleValue; }
|
|
|
|
virtual double calcUpperBound(double /*oldUpperBound*/) const { return denominator; }
|
|
|
|
virtual UChar tokenChar() const { return (UChar)0x003c; } // '<'
|
2001-10-11 16:56:24 +00:00
|
|
|
private:
|
|
|
|
static const char fgClassID;
|
2005-07-09 02:13:00 +00:00
|
|
|
static const UChar LTLT[2];
|
2005-07-08 00:16:47 +00:00
|
|
|
|
2001-10-11 16:56:24 +00:00
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class NullSubstitution : public NFSubstitution {
|
2001-10-11 16:56:24 +00:00
|
|
|
public:
|
|
|
|
NullSubstitution(int32_t _pos,
|
|
|
|
const NFRuleSet* _ruleSet,
|
|
|
|
const RuleBasedNumberFormat* formatter,
|
|
|
|
const UnicodeString& description,
|
|
|
|
UErrorCode& status)
|
|
|
|
: NFSubstitution(_pos, _ruleSet, formatter, description, status) {}
|
|
|
|
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual void toString(UnicodeString& /*result*/) const {}
|
|
|
|
virtual void doSubstitution(double /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/) const {}
|
|
|
|
virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInto*/, int32_t /*_pos*/) const {}
|
|
|
|
virtual int64_t transformNumber(int64_t /*number*/) const { return 0; }
|
|
|
|
virtual double transformNumber(double /*number*/) const { return 0; }
|
|
|
|
virtual UBool doParse(const UnicodeString& /*text*/,
|
2001-10-12 17:47:17 +00:00
|
|
|
ParsePosition& /*parsePosition*/,
|
2001-10-11 21:41:11 +00:00
|
|
|
double baseValue,
|
2001-10-12 17:47:17 +00:00
|
|
|
double /*upperBound*/,
|
2001-11-20 18:44:51 +00:00
|
|
|
UBool /*lenientParse*/,
|
2001-10-11 21:41:11 +00:00
|
|
|
Formattable& result) const
|
|
|
|
{ result.setDouble(baseValue); return TRUE; }
|
2004-08-27 16:45:16 +00:00
|
|
|
virtual double composeRuleValue(double /*newRuleValue*/, double /*oldRuleValue*/) const { return 0.0; } // never called
|
|
|
|
virtual double calcUpperBound(double /*oldUpperBound*/) const { return 0; } // never called
|
|
|
|
virtual UBool isNullSubstitution() const { return TRUE; }
|
|
|
|
virtual UChar tokenChar() const { return (UChar)0x0020; } // ' ' never called
|
2001-10-11 16:56:24 +00:00
|
|
|
private:
|
|
|
|
static const char fgClassID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-03-14 00:28:22 +00:00
|
|
|
/* U_HAVE_RBNF */
|
|
|
|
#endif
|
|
|
|
|
2001-10-10 21:43:11 +00:00
|
|
|
// NFSUBS_H
|
|
|
|
#endif
|