2001-10-10 21:43:11 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2014-08-18 20:47:36 +00:00
|
|
|
* Copyright (C) 1997-2014, International Business Machines
|
2005-06-14 17:14:30 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
2001-10-10 21:43:11 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NFRULE_H
|
|
|
|
#define NFRULE_H
|
|
|
|
|
2002-03-14 00:28:22 +00:00
|
|
|
#include "unicode/rbnf.h"
|
|
|
|
|
|
|
|
#if U_HAVE_RBNF
|
|
|
|
|
2001-10-10 21:43:11 +00:00
|
|
|
#include "unicode/utypes.h"
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/uobject.h"
|
2001-10-10 21:43:11 +00:00
|
|
|
#include "unicode/unistr.h"
|
2004-10-18 02:43:33 +00:00
|
|
|
#include "putilimp.h"
|
2001-10-10 21:43:11 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class FieldPosition;
|
|
|
|
class Formattable;
|
|
|
|
class NFRuleList;
|
|
|
|
class NFRuleSet;
|
|
|
|
class NFSubstitution;
|
|
|
|
class ParsePosition;
|
2014-08-18 20:47:36 +00:00
|
|
|
class PluralFormat;
|
2001-10-10 21:43:11 +00:00
|
|
|
class RuleBasedNumberFormat;
|
|
|
|
class UnicodeString;
|
|
|
|
|
2002-10-04 17:46:52 +00:00
|
|
|
class NFRule : public UMemory {
|
2001-10-11 21:41:11 +00:00
|
|
|
public:
|
2001-10-10 21:43:11 +00:00
|
|
|
|
|
|
|
enum ERuleType {
|
|
|
|
kNoBase = 0,
|
|
|
|
kNegativeNumberRule = -1,
|
|
|
|
kImproperFractionRule = -2,
|
|
|
|
kProperFractionRule = -3,
|
|
|
|
kMasterRule = -4,
|
|
|
|
kOtherRule = -5
|
|
|
|
};
|
|
|
|
|
|
|
|
static void makeRules(UnicodeString& definition,
|
|
|
|
const NFRuleSet* ruleSet,
|
|
|
|
const NFRule* predecessor,
|
|
|
|
const RuleBasedNumberFormat* rbnf,
|
|
|
|
NFRuleList& ruleList,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
|
|
|
NFRule(const RuleBasedNumberFormat* rbnf);
|
|
|
|
~NFRule();
|
|
|
|
|
|
|
|
UBool operator==(const NFRule& rhs) const;
|
|
|
|
UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); }
|
|
|
|
|
2002-04-02 03:25:05 +00:00
|
|
|
ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERuleType)baseValue : kOtherRule); }
|
2001-10-10 21:43:11 +00:00
|
|
|
void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; }
|
|
|
|
|
2002-03-14 00:28:22 +00:00
|
|
|
int64_t getBaseValue() const { return baseValue; }
|
2004-04-09 19:58:58 +00:00
|
|
|
void setBaseValue(int64_t value, UErrorCode& status);
|
2001-10-10 21:43:11 +00:00
|
|
|
|
2001-10-11 21:41:11 +00:00
|
|
|
double getDivisor() const { return uprv_pow(radix, exponent); }
|
2001-10-10 21:43:11 +00:00
|
|
|
|
2014-08-18 20:47:36 +00:00
|
|
|
void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos, UErrorCode& status) const;
|
|
|
|
void doFormat(double number, UnicodeString& toAppendTo, int32_t pos, UErrorCode& status) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
|
|
|
|
UBool doParse(const UnicodeString& text,
|
|
|
|
ParsePosition& pos,
|
|
|
|
UBool isFractional,
|
|
|
|
double upperBound,
|
|
|
|
Formattable& result) const;
|
|
|
|
|
|
|
|
UBool shouldRollBack(double number) const;
|
|
|
|
|
2005-06-14 17:14:30 +00:00
|
|
|
void _appendRuleText(UnicodeString& result) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
|
2014-08-18 20:47:36 +00:00
|
|
|
int32_t findTextLenient(const UnicodeString& str, const UnicodeString& key,
|
|
|
|
int32_t startingAt, int32_t* resultCount) const;
|
|
|
|
|
2001-10-11 21:41:11 +00:00
|
|
|
private:
|
2001-10-10 21:43:11 +00:00
|
|
|
void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status);
|
2014-08-18 20:47:36 +00:00
|
|
|
void extractSubstitutions(const NFRuleSet* ruleSet, const UnicodeString &ruleText, const NFRule* predecessor, UErrorCode& status);
|
|
|
|
NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule* predecessor, UErrorCode& status);
|
2001-10-10 21:43:11 +00:00
|
|
|
|
|
|
|
int16_t expectedExponent() const;
|
2001-10-11 16:56:24 +00:00
|
|
|
int32_t indexOfAny(const UChar* const strings[]) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
double matchToDelimiter(const UnicodeString& text, int32_t startPos, double baseValue,
|
|
|
|
const UnicodeString& delimiter, ParsePosition& pp, const NFSubstitution* sub,
|
2001-10-11 21:41:11 +00:00
|
|
|
double upperBound) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const;
|
|
|
|
|
2008-01-20 01:39:16 +00:00
|
|
|
int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErrorCode& status) const;
|
|
|
|
UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const;
|
2001-10-11 21:41:11 +00:00
|
|
|
int32_t findText(const UnicodeString& str, const UnicodeString& key,
|
|
|
|
int32_t startingAt, int32_t* resultCount) const;
|
2001-10-10 21:43:11 +00:00
|
|
|
|
|
|
|
private:
|
2002-03-14 00:28:22 +00:00
|
|
|
int64_t baseValue;
|
2004-03-24 00:40:49 +00:00
|
|
|
int32_t radix;
|
2001-10-10 21:43:11 +00:00
|
|
|
int16_t exponent;
|
|
|
|
UnicodeString ruleText;
|
|
|
|
NFSubstitution* sub1;
|
|
|
|
NFSubstitution* sub2;
|
|
|
|
const RuleBasedNumberFormat* formatter;
|
2014-08-18 20:47:36 +00:00
|
|
|
const PluralFormat* rulePatternFormat;
|
2002-06-29 00:04:16 +00:00
|
|
|
|
2002-10-04 17:46:52 +00:00
|
|
|
NFRule(const NFRule &other); // forbid copying of this class
|
|
|
|
NFRule &operator=(const NFRule &other); // forbid copying of this class
|
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
|
|
|
// NFRULE_H
|
|
|
|
#endif
|
2002-03-14 00:28:22 +00:00
|
|
|
|