ICU 56.1: rbnf.h Source File

ICU 56.1 56.1

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

- File List
- Globals

rbnf.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 * Copyright (C) 1997-2015, International Business Machines Corporation and others.
4 * All Rights Reserved.
5 *******************************************************************************
6 */
7
8 #ifndef RBNF_H
9 #define RBNF_H
10
11 #include "unicode/utypes.h"
12
25 #if UCONFIG_NO_FORMATTING
26 #define U_HAVE_RBNF 0
27 #else
28 #define U_HAVE_RBNF 1
29
30 #include "unicode/dcfmtsym.h"
31 #include "unicode/fmtable.h"
32 #include "unicode/locid.h"
33 #include "unicode/numfmt.h"
34 #include "unicode/unistr.h"
35 #include "unicode/strenum.h"
36 #include "unicode/brkiter.h"
37 #include "unicode/upluralrules.h"
38
39 U_NAMESPACE_BEGIN
40
41 class NFRule;
42 class NFRuleSet;
43 class LocalizationInfo;
44 class PluralFormat;
45 class RuleBasedCollator;
46
52 enum URBNFRuleSetTag {
53 URBNF_SPELLOUT,
54 URBNF_ORDINAL,
55 URBNF_DURATION,
56 URBNF_NUMBERING_SYSTEM,
57 URBNF_COUNT
58 };
59
553 class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
554 public:
555
556 //-----------------------------------------------------------------------
557 // constructors
558 //-----------------------------------------------------------------------
559
570 RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
571
595 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
596 UParseError& perror, UErrorCode& status);
597
613 RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
614 UParseError& perror, UErrorCode& status);
615
642 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
643 const Locale& locale, UParseError& perror, UErrorCode& status);
644
660 RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
661
662 //-----------------------------------------------------------------------
663 // boilerplate
664 //-----------------------------------------------------------------------
665
671 RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
672
678 RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
679
684 virtual ~RuleBasedNumberFormat();
685
692 virtual Format* clone(void) const;
693
701 virtual UBool operator==(const Format& other) const;
702
703 //-----------------------------------------------------------------------
704 // public API functions
705 //-----------------------------------------------------------------------
706
712 virtual UnicodeString getRules() const;
713
719 virtual int32_t getNumberOfRuleSetNames() const;
720
728 virtual UnicodeString getRuleSetName(int32_t index) const;
729
735 virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
736
745 virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
746
760 virtual UnicodeString getRuleSetDisplayName(int32_t index,
761 const Locale& locale = Locale::getDefault());
762
771 virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
772 const Locale& locale = Locale::getDefault());
773
774
775 using NumberFormat::format;
776
785 virtual UnicodeString& format(int32_t number,
786 UnicodeString& toAppendTo,
787 FieldPosition& pos) const;
788
797 virtual UnicodeString& format(int64_t number,
798 UnicodeString& toAppendTo,
799 FieldPosition& pos) const;
808 virtual UnicodeString& format(double number,
809 UnicodeString& toAppendTo,
810 FieldPosition& pos) const;
811
823 virtual UnicodeString& format(int32_t number,
824 const UnicodeString& ruleSetName,
825 UnicodeString& toAppendTo,
826 FieldPosition& pos,
827 UErrorCode& status) const;
839 virtual UnicodeString& format(int64_t number,
840 const UnicodeString& ruleSetName,
841 UnicodeString& toAppendTo,
842 FieldPosition& pos,
843 UErrorCode& status) const;
855 virtual UnicodeString& format(double number,
856 const UnicodeString& ruleSetName,
857 UnicodeString& toAppendTo,
858 FieldPosition& pos,
859 UErrorCode& status) const;
860
861 using NumberFormat::parse;
862
877 virtual void parse(const UnicodeString& text,
878 Formattable& result,
879 ParsePosition& parsePosition) const;
880
881 #if !UCONFIG_NO_COLLATION
882
916 virtual void setLenient(UBool enabled);
917
925 virtual inline UBool isLenient(void) const;
926
927 #endif
928
937 virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
938
945 virtual UnicodeString getDefaultRuleSetName() const;
946
957 virtual void setContext(UDisplayContext value, UErrorCode& status);
958
959 public:
965 static UClassID U_EXPORT2 getStaticClassID(void);
966
972 virtual UClassID getDynamicClassID(void) const;
973
982 virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
983
993 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
994
995 private:
996 RuleBasedNumberFormat(); // default constructor not implemented
997
998 // this will ref the localizations if they are not NULL
999 // caller must deref to get adoption
1000 RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
1001 const Locale& locale, UParseError& perror, UErrorCode& status);
1002
1003 void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
1004 void initCapitalizationContextInfo(const Locale& thelocale);
1005 void dispose();
1006 void stripWhitespace(UnicodeString& src);
1007 void initDefaultRuleSet();
1008 void format(double number, NFRuleSet& ruleSet);
1009 NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
1010
1011 /* friend access */
1012 friend class NFSubstitution;
1013 friend class NFRule;
1014 friend class NFRuleSet;
1015 friend class FractionalPartSubstitution;
1016
1017 inline NFRuleSet * getDefaultRuleSet() const;
1018 const RuleBasedCollator * getCollator() const;
1019 DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status);
1020 const DecimalFormatSymbols * getDecimalFormatSymbols() const;
1021 NFRule * initializeDefaultInfinityRule(UErrorCode &status);
1022 const NFRule * getDefaultInfinityRule() const;
1023 NFRule * initializeDefaultNaNRule(UErrorCode &status);
1024 const NFRule * getDefaultNaNRule() const;
1025 PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
1026 UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult) const;
1027
1028 private:
1029 NFRuleSet **ruleSets;
1030 UnicodeString* ruleSetDescriptions;
1031 int32_t numRuleSets;
1032 NFRuleSet *defaultRuleSet;
1033 Locale locale;
1034 RuleBasedCollator* collator;
1035 DecimalFormatSymbols* decimalFormatSymbols;
1036 NFRule *defaultInfinityRule;
1037 NFRule *defaultNaNRule;
1038 UBool lenient;
1039 UnicodeString* lenientParseRules;
1040 LocalizationInfo* localizations;
1041 UnicodeString originalDescription;
1042 UBool capitalizationInfoSet;
1043 UBool capitalizationForUIListMenu;
1044 UBool capitalizationForStandAlone;
1045 BreakIterator* capitalizationBrkIter;
1046 };
1047
1048 // ---------------
1049
1050 #if !UCONFIG_NO_COLLATION
1051
1052 inline UBool
1053 RuleBasedNumberFormat::isLenient(void) const {
1054 return lenient;
1055 }
1056
1057 #endif
1058
1059 inline NFRuleSet*
1060 RuleBasedNumberFormat::getDefaultRuleSet() const {
1061 return defaultRuleSet;
1062 }
1063
1064 U_NAMESPACE_END
1065
1066 /* U_HAVE_RBNF */
1067 #endif
1068
1069 /* RBNF_H */
1070 #endif
brkiter.h
C++ API: Break Iterator.
icu::Format
Base class for all formats.
Definition: format.h:94
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:84
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:172
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:56
unistr.h
C++ API: Unicode String.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
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:1175
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:358
icu::URBNFRuleSetTag
URBNFRuleSetTag
Tags for the predefined rulesets.
Definition: rbnf.h:52
icu::NumberFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables...
Definition: tblcoll.h:111
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text...
Definition: brkiter.h:100
upluralrules.h
C API: Plural rules, select plural keywords for numeric values.
icu::PluralFormat
Definition: plurfmt.h:144
icu::RuleBasedNumberFormat
The RuleBasedNumberFormat class formats numbers according to a set of rules.
Definition: rbnf.h:553
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:130
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:476
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:106
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:44
icu::NumberFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
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:47
locid.h
C++ API: Locale ID object.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
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:293
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
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.
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
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:185