ICU 63.1 63.1

rbnf.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 1997-2015, International Business Machines Corporation and others.
6 * All Rights Reserved.
7 *******************************************************************************
8 */
9
10 #ifndef RBNF_H
11 #define RBNF_H
12
13 #include "unicode/utypes.h"
14
27 #if UCONFIG_NO_FORMATTING
28 #define U_HAVE_RBNF 0
29 #else
30 #define U_HAVE_RBNF 1
31
32 #include "unicode/dcfmtsym.h"
33 #include "unicode/fmtable.h"
34 #include "unicode/locid.h"
35 #include "unicode/numfmt.h"
36 #include "unicode/unistr.h"
37 #include "unicode/strenum.h"
38 #include "unicode/brkiter.h"
39 #include "unicode/upluralrules.h"
40
41 U_NAMESPACE_BEGIN
42
43 class NFRule;
44 class NFRuleSet;
45 class LocalizationInfo;
46 class PluralFormat;
47 class RuleBasedCollator;
48
54 enum URBNFRuleSetTag {
55 URBNF_SPELLOUT,
56 URBNF_ORDINAL,
57 URBNF_DURATION,
58 URBNF_NUMBERING_SYSTEM,
59 #ifndef U_HIDE_DEPRECATED_API
60
64 URBNF_COUNT
65 #endif // U_HIDE_DEPRECATED_API
66 };
67
560 class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
561 public:
562
563 //-----------------------------------------------------------------------
564 // constructors
565 //-----------------------------------------------------------------------
566
577 RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
578
602 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
603 UParseError& perror, UErrorCode& status);
604
620 RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
621 UParseError& perror, UErrorCode& status);
622
649 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
650 const Locale& locale, UParseError& perror, UErrorCode& status);
651
667 RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
668
669 //-----------------------------------------------------------------------
670 // boilerplate
671 //-----------------------------------------------------------------------
672
678 RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
679
685 RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
686
691 virtual ~RuleBasedNumberFormat();
692
699 virtual Format* clone(void) const;
700
708 virtual UBool operator==(const Format& other) const;
709
710 //-----------------------------------------------------------------------
711 // public API functions
712 //-----------------------------------------------------------------------
713
719 virtual UnicodeString getRules() const;
720
726 virtual int32_t getNumberOfRuleSetNames() const;
727
735 virtual UnicodeString getRuleSetName(int32_t index) const;
736
742 virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
743
752 virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
753
767 virtual UnicodeString getRuleSetDisplayName(int32_t index,
768 const Locale& locale = Locale::getDefault());
769
778 virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
779 const Locale& locale = Locale::getDefault());
780
781
782 using NumberFormat::format;
783
792 virtual UnicodeString& format(int32_t number,
793 UnicodeString& toAppendTo,
794 FieldPosition& pos) const;
795
804 virtual UnicodeString& format(int64_t number,
805 UnicodeString& toAppendTo,
806 FieldPosition& pos) const;
815 virtual UnicodeString& format(double number,
816 UnicodeString& toAppendTo,
817 FieldPosition& pos) const;
818
830 virtual UnicodeString& format(int32_t number,
831 const UnicodeString& ruleSetName,
832 UnicodeString& toAppendTo,
833 FieldPosition& pos,
834 UErrorCode& status) const;
846 virtual UnicodeString& format(int64_t number,
847 const UnicodeString& ruleSetName,
848 UnicodeString& toAppendTo,
849 FieldPosition& pos,
850 UErrorCode& status) const;
862 virtual UnicodeString& format(double number,
863 const UnicodeString& ruleSetName,
864 UnicodeString& toAppendTo,
865 FieldPosition& pos,
866 UErrorCode& status) const;
867
868 protected:
886 virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
887 UnicodeString& appendTo,
888 FieldPositionIterator* posIter,
889 UErrorCode& status) const;
890
908 virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
909 UnicodeString& appendTo,
910 FieldPosition& pos,
911 UErrorCode& status) const;
912 public:
913
914 using NumberFormat::parse;
915
930 virtual void parse(const UnicodeString& text,
931 Formattable& result,
932 ParsePosition& parsePosition) const;
933
934 #if !UCONFIG_NO_COLLATION
935
969 virtual void setLenient(UBool enabled);
970
978 virtual inline UBool isLenient(void) const;
979
980 #endif
981
990 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
991
998 virtual UnicodeString getDefaultRuleSetName() const;
999
1010 virtual void setContext(UDisplayContext value, UErrorCode& status);
1011
1017 virtual ERoundingMode getRoundingMode(void) const;
1018
1024 virtual void setRoundingMode(ERoundingMode roundingMode);
1025
1026 public:
1032 static UClassID U_EXPORT2 getStaticClassID(void);
1033
1039 virtual UClassID getDynamicClassID(void) const;
1040
1049 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
1050
1060 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1061
1062 private:
1063 RuleBasedNumberFormat(); // default constructor not implemented
1064
1065 // this will ref the localizations if they are not NULL
1066 // caller must deref to get adoption
1067 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
1068 const Locale& locale, UParseError& perror, UErrorCode& status);
1069
1070 void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
1071 void initCapitalizationContextInfo(const Locale& thelocale);
1072 void dispose();
1073 void stripWhitespace(UnicodeString& src);
1074 void initDefaultRuleSet();
1075 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
1076
1077 /* friend access */
1078 friend class NFSubstitution;
1079 friend class NFRule;
1080 friend class NFRuleSet;
1081 friend class FractionalPartSubstitution;
1082
1083 inline NFRuleSet * getDefaultRuleSet() const;
1084 const RuleBasedCollator * getCollator() const;
1085 DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status);
1086 const DecimalFormatSymbols * getDecimalFormatSymbols() const;
1087 NFRule * initializeDefaultInfinityRule(UErrorCode &status);
1088 const NFRule * getDefaultInfinityRule() const;
1089 NFRule * initializeDefaultNaNRule(UErrorCode &status);
1090 const NFRule * getDefaultNaNRule() const;
1091 PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
1092 UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult, UErrorCode& status) const;
1093 UnicodeString& format(int64_t number, NFRuleSet *ruleSet, UnicodeString& toAppendTo, UErrorCode& status) const;
1094 void format(double number, NFRuleSet& rs, UnicodeString& toAppendTo, UErrorCode& status) const;
1095
1096 private:
1097 NFRuleSet **fRuleSets;
1098 UnicodeString* ruleSetDescriptions;
1099 int32_t numRuleSets;
1100 NFRuleSet *defaultRuleSet;
1101 Locale locale;
1102 RuleBasedCollator* collator;
1103 DecimalFormatSymbols* decimalFormatSymbols;
1104 NFRule *defaultInfinityRule;
1105 NFRule *defaultNaNRule;
1106 ERoundingMode fRoundingMode;
1107 UBool lenient;
1108 UnicodeString* lenientParseRules;
1109 LocalizationInfo* localizations;
1110 UnicodeString originalDescription;
1111 UBool capitalizationInfoSet;
1112 UBool capitalizationForUIListMenu;
1113 UBool capitalizationForStandAlone;
1114 BreakIterator* capitalizationBrkIter;
1115 };
1116
1117 // ---------------
1118
1119 #if !UCONFIG_NO_COLLATION
1120
1121 inline UBool
1122 RuleBasedNumberFormat::isLenient(void) const {
1123 return lenient;
1124 }
1125
1126 #endif
1127
1128 inline NFRuleSet*
1129 RuleBasedNumberFormat::getDefaultRuleSet() const {
1130 return defaultRuleSet;
1131 }
1132
1133 U_NAMESPACE_END
1134
1135 /* U_HAVE_RBNF */
1136 #endif
1137
1138 /* RBNF_H */
1139 #endif
brkiter.h
C++ API: Break Iterator.
icu::Format
Base class for all formats.
Definition: format.h:96
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:84
icu::NumberFormat::format
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
icu::NumberFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
icu::NumberFormat
Definition: numfmt.h:173
icu::NumberFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:64
unistr.h
C++ API: Unicode String.
icu::NumberFormat::setRoundingMode
virtual void setRoundingMode(ERoundingMode roundingMode)
Set the rounding mode.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:90
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
icu::NumberFormat::setLenient
virtual void setLenient(UBool enable)
Sets whether lenient parsing should be enabled (it is off by default).
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
icu::URBNFRuleSetTag
URBNFRuleSetTag
Tags for the predefined rulesets.
Definition: rbnf.h:54
icu::URBNF_COUNT
One more than the highest normal URBNFRuleSetTag value.
Definition: rbnf.h:64
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:113
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:55
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text...
Definition: brkiter.h:102
upluralrules.h
C API: Plural rules, select plural keywords for numeric values.
icu::PluralFormat
Definition: plurfmt.h:146
icu::RuleBasedNumberFormat
The RuleBasedNumberFormat class formats numbers according to a set of rules.
Definition: rbnf.h:560
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
icu::NumberFormat::getRoundingMode
virtual ERoundingMode getRoundingMode(void) const
Get the rounding mode.
icu::NumberFormat::setContext
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
icu::NumberFormat::getStaticClassID
static UClassID getStaticClassID(void)
Return the class ID for this class.
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:50
dcfmtsym.h
C++ API: Symbols for formatting numbers.
strenum.h
C++ API: String Enumeration.
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
locid.h
C++ API: Locale ID object.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::NumberFormat::operator==
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
numfmt.h
C++ API: Compatibility APIs for number formatting.
icu::NumberFormat::operator=
NumberFormat & operator=(const NumberFormat &)
Assignment operator.
icu::NumberFormat::isLenient
virtual UBool isLenient(void) const
Returns whether lenient parsing is enabled (it is off by default).
Definition: numfmt.h:1243
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
fmtable.h
C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing...
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192