ICU 58.2 58.2

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

- File List
- Globals

rbnf.h
Go to the documentation of this file.
1 // Copyright (C) 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 using NumberFormat::parse;
870
885 virtual void parse(const UnicodeString& text,
886 Formattable& result,
887 ParsePosition& parsePosition) const;
888
889 #if !UCONFIG_NO_COLLATION
890
924 virtual void setLenient(UBool enabled);
925
933 virtual inline UBool isLenient(void) const;
934
935 #endif
936
945 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
946
953 virtual UnicodeString getDefaultRuleSetName() const;
954
965 virtual void setContext(UDisplayContext value, UErrorCode& status);
966
967 public:
973 static UClassID U_EXPORT2 getStaticClassID(void);
974
980 virtual UClassID getDynamicClassID(void) const;
981
990 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
991
1001 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1002
1003 private:
1004 RuleBasedNumberFormat(); // default constructor not implemented
1005
1006 // this will ref the localizations if they are not NULL
1007 // caller must deref to get adoption
1008 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
1009 const Locale& locale, UParseError& perror, UErrorCode& status);
1010
1011 void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
1012 void initCapitalizationContextInfo(const Locale& thelocale);
1013 void dispose();
1014 void stripWhitespace(UnicodeString& src);
1015 void initDefaultRuleSet();
1016 void format(double number, NFRuleSet& ruleSet);
1017 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
1018
1019 /* friend access */
1020 friend class NFSubstitution;
1021 friend class NFRule;
1022 friend class NFRuleSet;
1023 friend class FractionalPartSubstitution;
1024
1025 inline NFRuleSet * getDefaultRuleSet() const;
1026 const RuleBasedCollator * getCollator() const;
1027 DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status);
1028 const DecimalFormatSymbols * getDecimalFormatSymbols() const;
1029 NFRule * initializeDefaultInfinityRule(UErrorCode &status);
1030 const NFRule * getDefaultInfinityRule() const;
1031 NFRule * initializeDefaultNaNRule(UErrorCode &status);
1032 const NFRule * getDefaultNaNRule() const;
1033 PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
1034 UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult) const;
1035
1036 private:
1037 NFRuleSet **ruleSets;
1038 UnicodeString* ruleSetDescriptions;
1039 int32_t numRuleSets;
1040 NFRuleSet *defaultRuleSet;
1041 Locale locale;
1042 RuleBasedCollator* collator;
1043 DecimalFormatSymbols* decimalFormatSymbols;
1044 NFRule *defaultInfinityRule;
1045 NFRule *defaultNaNRule;
1046 UBool lenient;
1047 UnicodeString* lenientParseRules;
1048 LocalizationInfo* localizations;
1049 UnicodeString originalDescription;
1050 UBool capitalizationInfoSet;
1051 UBool capitalizationForUIListMenu;
1052 UBool capitalizationForStandAlone;
1053 BreakIterator* capitalizationBrkIter;
1054 };
1055
1056 // ---------------
1057
1058 #if !UCONFIG_NO_COLLATION
1059
1060 inline UBool
1061 RuleBasedNumberFormat::isLenient(void) const {
1062 return lenient;
1063 }
1064
1065 #endif
1066
1067 inline NFRuleSet*
1068 RuleBasedNumberFormat::getDefaultRuleSet() const {
1069 return defaultRuleSet;
1070 }
1071
1072 U_NAMESPACE_END
1073
1074 /* U_HAVE_RBNF */
1075 #endif
1076
1077 /* RBNF_H */
1078 #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:86
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:169
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:66
unistr.h
C++ API: Unicode String.
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:1170
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::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:1061
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:46
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:295
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:259
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:187