ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
561 class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
562 public:
563
564 //-----------------------------------------------------------------------
565 // constructors
566 //-----------------------------------------------------------------------
567
578 RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
579
603 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
604 UParseError& perror, UErrorCode& status);
605
621 RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
622 UParseError& perror, UErrorCode& status);
623
650 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
651 const Locale& locale, UParseError& perror, UErrorCode& status);
652
668 RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
669
670 //-----------------------------------------------------------------------
671 // boilerplate
672 //-----------------------------------------------------------------------
673
679 RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
680
686 RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
687
692 virtual ~RuleBasedNumberFormat();
693
700 virtual Format* clone(void) const;
701
709 virtual UBool operator==(const Format& other) const;
710
711 //-----------------------------------------------------------------------
712 // public API functions
713 //-----------------------------------------------------------------------
714
720 virtual UnicodeString getRules() const;
721
727 virtual int32_t getNumberOfRuleSetNames() const;
728
736 virtual UnicodeString getRuleSetName(int32_t index) const;
737
743 virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
744
753 virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
754
768 virtual UnicodeString getRuleSetDisplayName(int32_t index,
769 const Locale& locale = Locale::getDefault());
770
779 virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
780 const Locale& locale = Locale::getDefault());
781
782
783 using NumberFormat::format;
784
793 virtual UnicodeString& format(int32_t number,
794 UnicodeString& toAppendTo,
795 FieldPosition& pos) const;
796
805 virtual UnicodeString& format(int64_t number,
806 UnicodeString& toAppendTo,
807 FieldPosition& pos) const;
816 virtual UnicodeString& format(double number,
817 UnicodeString& toAppendTo,
818 FieldPosition& pos) const;
819
831 virtual UnicodeString& format(int32_t number,
832 const UnicodeString& ruleSetName,
833 UnicodeString& toAppendTo,
834 FieldPosition& pos,
835 UErrorCode& status) const;
847 virtual UnicodeString& format(int64_t number,
848 const UnicodeString& ruleSetName,
849 UnicodeString& toAppendTo,
850 FieldPosition& pos,
851 UErrorCode& status) const;
863 virtual UnicodeString& format(double number,
864 const UnicodeString& ruleSetName,
865 UnicodeString& toAppendTo,
866 FieldPosition& pos,
867 UErrorCode& status) const;
868
869 protected:
887 virtual UnicodeString& format(const DigitList &number,
888 UnicodeString& appendTo,
889 FieldPositionIterator* posIter,
890 UErrorCode& status) const;
891
909 virtual UnicodeString& format(const DigitList &number,
910 UnicodeString& appendTo,
911 FieldPosition& pos,
912 UErrorCode& status) const;
913 public:
914
915 using NumberFormat::parse;
916
931 virtual void parse(const UnicodeString& text,
932 Formattable& result,
933 ParsePosition& parsePosition) const;
934
935 #if !UCONFIG_NO_COLLATION
936
970 virtual void setLenient(UBool enabled);
971
979 virtual inline UBool isLenient(void) const;
980
981 #endif
982
991 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
992
999 virtual UnicodeString getDefaultRuleSetName() const;
1000
1011 virtual void setContext(UDisplayContext value, UErrorCode& status);
1012
1018 virtual ERoundingMode getRoundingMode(void) const;
1019
1025 virtual void setRoundingMode(ERoundingMode roundingMode);
1026
1027 public:
1033 static UClassID U_EXPORT2 getStaticClassID(void);
1034
1040 virtual UClassID getDynamicClassID(void) const;
1041
1050 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
1051
1061 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1062
1063 private:
1064 RuleBasedNumberFormat(); // default constructor not implemented
1065
1066 // this will ref the localizations if they are not NULL
1067 // caller must deref to get adoption
1068 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
1069 const Locale& locale, UParseError& perror, UErrorCode& status);
1070
1071 void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
1072 void initCapitalizationContextInfo(const Locale& thelocale);
1073 void dispose();
1074 void stripWhitespace(UnicodeString& src);
1075 void initDefaultRuleSet();
1076 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
1077
1078 /* friend access */
1079 friend class NFSubstitution;
1080 friend class NFRule;
1081 friend class NFRuleSet;
1082 friend class FractionalPartSubstitution;
1083
1084 inline NFRuleSet * getDefaultRuleSet() const;
1085 const RuleBasedCollator * getCollator() const;
1086 DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status);
1087 const DecimalFormatSymbols * getDecimalFormatSymbols() const;
1088 NFRule * initializeDefaultInfinityRule(UErrorCode &status);
1089 const NFRule * getDefaultInfinityRule() const;
1090 NFRule * initializeDefaultNaNRule(UErrorCode &status);
1091 const NFRule * getDefaultNaNRule() const;
1092 PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
1093 UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult, UErrorCode& status) const;
1094 UnicodeString& format(int64_t number, NFRuleSet *ruleSet, UnicodeString& toAppendTo, UErrorCode& status) const;
1095 void format(double number, NFRuleSet& rs, UnicodeString& toAppendTo, UErrorCode& status) const;
1096
1097 private:
1098 NFRuleSet **ruleSets;
1099 UnicodeString* ruleSetDescriptions;
1100 int32_t numRuleSets;
1101 NFRuleSet *defaultRuleSet;
1102 Locale locale;
1103 RuleBasedCollator* collator;
1104 DecimalFormatSymbols* decimalFormatSymbols;
1105 NFRule *defaultInfinityRule;
1106 NFRule *defaultNaNRule;
1107 ERoundingMode roundingMode;
1108 UBool lenient;
1109 UnicodeString* lenientParseRules;
1110 LocalizationInfo* localizations;
1111 UnicodeString originalDescription;
1112 UBool capitalizationInfoSet;
1113 UBool capitalizationForUIListMenu;
1114 UBool capitalizationForStandAlone;
1115 BreakIterator* capitalizationBrkIter;
1116 };
1117
1118 // ---------------
1119
1120 #if !UCONFIG_NO_COLLATION
1121
1122 inline UBool
1123 RuleBasedNumberFormat::isLenient(void) const {
1124 return lenient;
1125 }
1126
1127 #endif
1128
1129 inline NFRuleSet*
1130 RuleBasedNumberFormat::getDefaultRuleSet() const {
1131 return defaultRuleSet;
1132 }
1133
1134 U_NAMESPACE_END
1135
1136 /* U_HAVE_RBNF */
1137 #endif
1138
1139 /* RBNF_H */
1140 #endif
brkiter.h
C++ API: Break Iterator.
icu::Format
Base class for all formats.
Definition: format.h:96
icu::NumberFormat::getRoundingMode
virtual ERoundingMode getRoundingMode(void) const
Get the rounding mode.
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:88
icu::NumberFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:174
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:93
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).
icu::NumberFormat::isLenient
virtual UBool isLenient(void) const
Returns whether lenient parsing is enabled (it is off by default).
Definition: numfmt.h:1217
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:360
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:131
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:62
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:561
icu::NumberFormat::operator==
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
icu::NumberFormat::setContext
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
icu::RuleBasedNumberFormat::isLenient
virtual UBool isLenient(void) const
Returns true if lenient-parse mode is turned on.
Definition: rbnf.h:1123
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
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
icu::NumberFormat::ERoundingMode
ERoundingMode
Rounding mode.
Definition: numfmt.h:185
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::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
icu::NumberFormat::format
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
numfmt.h
C++ API: Abstract base class for all number formats.
icu::NumberFormat::operator=
NumberFormat & operator=(const NumberFormat &)
Assignment operator.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
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:188