X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b331163bffd790ced0e88b73f44f86d49ccc48a5..38fbf2fd31f5cd99b500914d6037b1d06b608645:/icuSources/i18n/unicode/rbnf.h diff --git a/icuSources/i18n/unicode/rbnf.h b/icuSources/i18n/unicode/rbnf.h index 7058c967..5f9510f3 100644 --- a/icuSources/i18n/unicode/rbnf.h +++ b/icuSources/i18n/unicode/rbnf.h @@ -1,3 +1,5 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * Copyright (C) 1997-2015, International Business Machines Corporation and others. @@ -36,8 +38,10 @@ #include "unicode/brkiter.h" #include "unicode/upluralrules.h" +#if U_SHOW_CPLUSPLUS_API U_NAMESPACE_BEGIN +class NFRule; class NFRuleSet; class LocalizationInfo; class PluralFormat; @@ -53,7 +57,13 @@ enum URBNFRuleSetTag { URBNF_ORDINAL, URBNF_DURATION, URBNF_NUMBERING_SYSTEM, +#ifndef U_HIDE_DEPRECATED_API + /** + * One more than the highest normal URBNFRuleSetTag value. + * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. + */ URBNF_COUNT +#endif // U_HIDE_DEPRECATED_API }; /** @@ -264,17 +274,47 @@ enum URBNFRuleSetTag { * * * x.x: - * The rule is an improper fraction rule. + * The rule is an improper fraction rule. If the full stop in + * the middle of the rule name is replaced with the decimal point + * that is used in the language or DecimalFormatSymbols, then that rule will + * have precedence when formatting and parsing this rule. For example, some + * languages use the comma, and can thus be written as x,x instead. For example, + * you can use "x.x: << point >>;x,x: << comma >>;" to + * handle the decimal point that matches the language's natural spelling of + * the punctuation of either the full stop or comma. * * * 0.x: - * The rule is a proper fraction rule. + * The rule is a proper fraction rule. If the full stop in + * the middle of the rule name is replaced with the decimal point + * that is used in the language or DecimalFormatSymbols, then that rule will + * have precedence when formatting and parsing this rule. For example, some + * languages use the comma, and can thus be written as 0,x instead. For example, + * you can use "0.x: point >>;0,x: comma >>;" to + * handle the decimal point that matches the language's natural spelling of + * the punctuation of either the full stop or comma. * * * x.0: - * The rule is a master rule. + * The rule is a master rule. If the full stop in + * the middle of the rule name is replaced with the decimal point + * that is used in the language or DecimalFormatSymbols, then that rule will + * have precedence when formatting and parsing this rule. For example, some + * languages use the comma, and can thus be written as x,0 instead. For example, + * you can use "x.0: << point;x,0: << comma;" to + * handle the decimal point that matches the language's natural spelling of + * the punctuation of either the full stop or comma. + * + * + * Inf: + * The rule for infinity. * * + * NaN: + * The rule for an IEEE 754 NaN (not a number). + * + * + * * nothing * If the rule's rule descriptor is left out, the base value is one plus the * preceding rule's base value (or zero if this is the first rule in the list) in a normal @@ -827,6 +867,52 @@ public: FieldPosition& pos, UErrorCode& status) const; +protected: + /** + * Format a decimal number. + * The number is a DigitList wrapper onto a floating point decimal number. + * The default implementation in NumberFormat converts the decimal number + * to a double and formats that. Subclasses of NumberFormat that want + * to specifically handle big decimal numbers must override this method. + * class DecimalFormat does so. + * + * @param number The number, a DigitList format Decimal Floating Point. + * @param appendTo Output parameter to receive result. + * Result is appended to existing contents. + * @param posIter On return, can be used to iterate over positions + * of fields generated by this format call. + * @param status Output param filled with success/failure status. + * @return Reference to 'appendTo' parameter. + * @internal + */ + virtual UnicodeString& format(const DigitList &number, + UnicodeString& appendTo, + FieldPositionIterator* posIter, + UErrorCode& status) const; + + /** + * Format a decimal number. + * The number is a DigitList wrapper onto a floating point decimal number. + * The default implementation in NumberFormat converts the decimal number + * to a double and formats that. Subclasses of NumberFormat that want + * to specifically handle big decimal numbers must override this method. + * class DecimalFormat does so. + * + * @param number The number, a DigitList format Decimal Floating Point. + * @param appendTo Output parameter to receive result. + * Result is appended to existing contents. + * @param pos On input: an alignment field, if desired. + * On output: the offsets of the alignment field. + * @param status Output param filled with success/failure status. + * @return Reference to 'appendTo' parameter. + * @internal + */ + virtual UnicodeString& format(const DigitList &number, + UnicodeString& appendTo, + FieldPosition& pos, + UErrorCode& status) const; +public: + using NumberFormat::parse; /** @@ -980,13 +1066,20 @@ private: /* friend access */ friend class NFSubstitution; friend class NFRule; + friend class NFRuleSet; friend class FractionalPartSubstitution; inline NFRuleSet * getDefaultRuleSet() const; const RuleBasedCollator * getCollator() const; - DecimalFormatSymbols * getDecimalFormatSymbols() const; + DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status); + const DecimalFormatSymbols * getDecimalFormatSymbols() const; + NFRule * initializeDefaultInfinityRule(UErrorCode &status); + const NFRule * getDefaultInfinityRule() const; + NFRule * initializeDefaultNaNRule(UErrorCode &status); + const NFRule * getDefaultNaNRule() const; PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const; - UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult) const; + UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult, UErrorCode& status) const; + UnicodeString& format(int64_t number, NFRuleSet *ruleSet, UnicodeString& toAppendTo, UErrorCode& status) const; private: NFRuleSet **ruleSets; @@ -996,6 +1089,8 @@ private: Locale locale; RuleBasedCollator* collator; DecimalFormatSymbols* decimalFormatSymbols; + NFRule *defaultInfinityRule; + NFRule *defaultNaNRule; UBool lenient; UnicodeString* lenientParseRules; LocalizationInfo* localizations; @@ -1023,6 +1118,7 @@ RuleBasedNumberFormat::getDefaultRuleSet() const { } U_NAMESPACE_END +#endif // U_SHOW_CPLUSPLUS_API /* U_HAVE_RBNF */ #endif