2017-04-19 17:00:05 +03:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-11-03 15:27:28 +03:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2013-03-02 08:58:49 +04:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2015-11-20 14:37:51 +03:00
|
|
|
* Copyright (C) 1997-2015, International Business Machines
|
2013-03-02 08:58:49 +04:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NFRULE_H
|
|
|
|
#define NFRULE_H
|
|
|
|
|
|
|
|
#include "unicode/rbnf.h"
|
|
|
|
|
|
|
|
#if U_HAVE_RBNF
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uobject.h"
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class FieldPosition;
|
|
|
|
class Formattable;
|
|
|
|
class NFRuleList;
|
|
|
|
class NFRuleSet;
|
|
|
|
class NFSubstitution;
|
|
|
|
class ParsePosition;
|
2015-06-13 00:25:17 +03:00
|
|
|
class PluralFormat;
|
2013-03-02 08:58:49 +04:00
|
|
|
class RuleBasedNumberFormat;
|
|
|
|
class UnicodeString;
|
|
|
|
|
|
|
|
class NFRule : public UMemory {
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum ERuleType {
|
|
|
|
kNoBase = 0,
|
|
|
|
kNegativeNumberRule = -1,
|
|
|
|
kImproperFractionRule = -2,
|
|
|
|
kProperFractionRule = -3,
|
|
|
|
kMasterRule = -4,
|
2015-11-20 14:37:51 +03:00
|
|
|
kInfinityRule = -5,
|
|
|
|
kNaNRule = -6,
|
|
|
|
kOtherRule = -7
|
2013-03-02 08:58:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void makeRules(UnicodeString& definition,
|
2015-11-20 14:37:51 +03:00
|
|
|
NFRuleSet* ruleSet,
|
2013-03-02 08:58:49 +04:00
|
|
|
const NFRule* predecessor,
|
|
|
|
const RuleBasedNumberFormat* rbnf,
|
|
|
|
NFRuleList& ruleList,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
2015-11-20 14:37:51 +03:00
|
|
|
NFRule(const RuleBasedNumberFormat* rbnf, const UnicodeString &ruleText, UErrorCode &status);
|
2013-03-02 08:58:49 +04:00
|
|
|
~NFRule();
|
|
|
|
|
|
|
|
UBool operator==(const NFRule& rhs) const;
|
|
|
|
UBool operator!=(const NFRule& rhs) const { return !operator==(rhs); }
|
|
|
|
|
|
|
|
ERuleType getType() const { return (ERuleType)(baseValue <= kNoBase ? (ERuleType)baseValue : kOtherRule); }
|
|
|
|
void setType(ERuleType ruleType) { baseValue = (int32_t)ruleType; }
|
|
|
|
|
|
|
|
int64_t getBaseValue() const { return baseValue; }
|
|
|
|
void setBaseValue(int64_t value, UErrorCode& status);
|
|
|
|
|
2015-11-20 14:37:51 +03:00
|
|
|
UChar getDecimalPoint() const { return decimalPoint; }
|
|
|
|
|
2017-04-19 17:00:05 +03:00
|
|
|
int64_t getDivisor() const;
|
2013-03-02 08:58:49 +04:00
|
|
|
|
2015-11-20 14:37:51 +03:00
|
|
|
void doFormat(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
|
|
|
|
void doFormat(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const;
|
2013-03-02 08:58:49 +04:00
|
|
|
|
|
|
|
UBool doParse(const UnicodeString& text,
|
|
|
|
ParsePosition& pos,
|
|
|
|
UBool isFractional,
|
|
|
|
double upperBound,
|
|
|
|
Formattable& result) const;
|
|
|
|
|
2017-04-19 17:00:05 +03:00
|
|
|
UBool shouldRollBack(int64_t number) const;
|
2013-03-02 08:58:49 +04:00
|
|
|
|
|
|
|
void _appendRuleText(UnicodeString& result) const;
|
|
|
|
|
2015-06-13 00:25:17 +03:00
|
|
|
int32_t findTextLenient(const UnicodeString& str, const UnicodeString& key,
|
|
|
|
int32_t startingAt, int32_t* resultCount) const;
|
|
|
|
|
2015-11-20 14:37:51 +03:00
|
|
|
void setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status);
|
|
|
|
|
2013-03-02 08:58:49 +04:00
|
|
|
private:
|
|
|
|
void parseRuleDescriptor(UnicodeString& descriptor, UErrorCode& status);
|
2015-06-13 00:25:17 +03:00
|
|
|
void extractSubstitutions(const NFRuleSet* ruleSet, const UnicodeString &ruleText, const NFRule* predecessor, UErrorCode& status);
|
|
|
|
NFSubstitution* extractSubstitution(const NFRuleSet* ruleSet, const NFRule* predecessor, UErrorCode& status);
|
2013-03-02 08:58:49 +04:00
|
|
|
|
|
|
|
int16_t expectedExponent() const;
|
2015-11-20 14:37:51 +03:00
|
|
|
int32_t indexOfAnyRulePrefix() const;
|
2013-03-02 08:58:49 +04:00
|
|
|
double matchToDelimiter(const UnicodeString& text, int32_t startPos, double baseValue,
|
|
|
|
const UnicodeString& delimiter, ParsePosition& pp, const NFSubstitution* sub,
|
|
|
|
double upperBound) const;
|
|
|
|
void stripPrefix(UnicodeString& text, const UnicodeString& prefix, ParsePosition& pp) const;
|
|
|
|
|
|
|
|
int32_t prefixLength(const UnicodeString& str, const UnicodeString& prefix, UErrorCode& status) const;
|
|
|
|
UBool allIgnorable(const UnicodeString& str, UErrorCode& status) const;
|
|
|
|
int32_t findText(const UnicodeString& str, const UnicodeString& key,
|
|
|
|
int32_t startingAt, int32_t* resultCount) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int64_t baseValue;
|
|
|
|
int32_t radix;
|
|
|
|
int16_t exponent;
|
2015-11-20 14:37:51 +03:00
|
|
|
UChar decimalPoint;
|
2013-03-02 08:58:49 +04:00
|
|
|
UnicodeString ruleText;
|
|
|
|
NFSubstitution* sub1;
|
|
|
|
NFSubstitution* sub2;
|
|
|
|
const RuleBasedNumberFormat* formatter;
|
2015-06-13 00:25:17 +03:00
|
|
|
const PluralFormat* rulePatternFormat;
|
2013-03-02 08:58:49 +04:00
|
|
|
|
|
|
|
NFRule(const NFRule &other); // forbid copying of this class
|
|
|
|
NFRule &operator=(const NFRule &other); // forbid copying of this class
|
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
/* U_HAVE_RBNF */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// NFRULE_H
|
|
|
|
#endif
|
|
|
|
|