ICU 62.1 62.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"
40
42
43class NFRule;
44class NFRuleSet;
45class LocalizationInfo;
46class PluralFormat;
47class RuleBasedCollator;
48
55 URBNF_SPELLOUT,
56 URBNF_ORDINAL,
57 URBNF_DURATION,
58 URBNF_NUMBERING_SYSTEM,
59#ifndef U_HIDE_DEPRECATED_API
65#endif // U_HIDE_DEPRECATED_API
66};
67
562public:
563
564 //-----------------------------------------------------------------------
565 // constructors
566 //-----------------------------------------------------------------------
567
579
603 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
605
621 RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
623
650 RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
651 const Locale& locale, UParseError& perror, UErrorCode& status);
652
669
670 //-----------------------------------------------------------------------
671 // boilerplate
672 //-----------------------------------------------------------------------
673
680
687
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
769 const Locale& locale = Locale::getDefault());
770
780 const Locale& locale = Locale::getDefault());
781
782
783 using NumberFormat::format;
784
793 virtual UnicodeString& format(int32_t number,
795 FieldPosition& pos) const;
796
805 virtual UnicodeString& format(int64_t number,
807 FieldPosition& pos) const;
816 virtual UnicodeString& format(double number,
818 FieldPosition& pos) const;
819
831 virtual UnicodeString& format(int32_t number,
834 FieldPosition& pos,
835 UErrorCode& status) const;
847 virtual UnicodeString& format(int64_t number,
850 FieldPosition& pos,
851 UErrorCode& status) const;
863 virtual UnicodeString& format(double number,
866 FieldPosition& pos,
867 UErrorCode& status) const;
868
869protected:
887 virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
888 UnicodeString& appendTo,
890 UErrorCode& status) const;
891
909 virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
910 UnicodeString& appendTo,
911 FieldPosition& pos,
912 UErrorCode& status) const;
913public:
914
915 using NumberFormat::parse;
916
931 virtual void parse(const UnicodeString& text,
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
992
1000
1012
1018 virtual ERoundingMode getRoundingMode(void) const;
1019
1025 virtual void setRoundingMode(ERoundingMode roundingMode);
1026
1027public:
1034
1040 virtual UClassID getDynamicClassID(void) const;
1041
1051
1061 virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
1062
1063private:
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
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
1097private:
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
1122inline UBool
1123RuleBasedNumberFormat::isLenient(void) const {
1124 return lenient;
1125}
1126
1127#endif
1128
1129inline NFRuleSet*
1130RuleBasedNumberFormat::getDefaultRuleSet() const {
1131 return defaultRuleSet;
1132}
1133
1135
1136/* U_HAVE_RBNF */
1137#endif
1138
1139/* RBNF_H */
1140#endif
C++ API: Break Iterator.
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition brkiter.h:102
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition dcfmtsym.h:84
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition fpositer.h:55
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:108
Base class for all formats.
Definition format.h:96
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:188
virtual UBool isLenient(void) const
Returns whether lenient parsing is enabled (it is off by default).
Definition numfmt.h:1244
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
ERoundingMode
Rounding mode.
Definition numfmt.h:185
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:49
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:113
The RuleBasedNumberFormat class formats numbers according to a set of rules.
Definition rbnf.h:561
virtual UClassID getDynamicClassID(void) const
ICU "poor man's RTTI", returns a UClassID for the actual class.
virtual UnicodeString getRuleSetName(int32_t index) const
Return the name of the index'th public ruleSet.
RuleBasedNumberFormat(const UnicodeString &rules, const UnicodeString &localizations, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
virtual UnicodeString & format(int32_t number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified 32-bit number using the default ruleset.
virtual void setRoundingMode(ERoundingMode roundingMode)
Set the rounding mode.
virtual UnicodeString getRules() const
return the rules that were provided to the RuleBasedNumberFormat.
RuleBasedNumberFormat(const UnicodeString &rules, const Locale &locale, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the rules passed in.
virtual int32_t getNumberOfRuleSetNames() const
Return the number of public rule set names.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
virtual UnicodeString & format(double number, const UnicodeString &ruleSetName, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
Formats the specified number using the named ruleset.
virtual UnicodeString & format(const number::impl::DecimalQuantity &number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format a decimal number.
virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const
Return the number of locales for which we have localized rule set display names.
virtual UnicodeString & format(int64_t number, const UnicodeString &ruleSetName, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
Formats the specified 64-bit number using the named ruleset.
virtual void setDecimalFormatSymbols(const DecimalFormatSymbols &symbols)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
virtual UnicodeString & format(int64_t number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified 64-bit number using the default ruleset.
virtual ~RuleBasedNumberFormat()
Release memory allocated for a RuleBasedNumberFormat when you are finished with it.
virtual UnicodeString & format(int32_t number, const UnicodeString &ruleSetName, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
Formats the specified number using the named ruleset.
virtual Format * clone(void) const
Clone this object polymorphically.
virtual void setDefaultRuleSet(const UnicodeString &ruleSetName, UErrorCode &status)
Override the default rule set to use.
RuleBasedNumberFormat & operator=(const RuleBasedNumberFormat &rhs)
Assignment operator.
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const
Parses the specfied string, beginning at the specified position, according to this formatter's rules.
virtual void setLenient(UBool enabled)
Turns lenient parse mode on and off.
RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale &locale, UErrorCode &status)
Creates a RuleBasedNumberFormat from a predefined ruleset.
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
virtual UnicodeString getRuleSetDisplayName(int32_t index, const Locale &locale=Locale::getDefault())
Return the rule set display names for the provided locale.
RuleBasedNumberFormat(const RuleBasedNumberFormat &rhs)
Copy constructor.
virtual UnicodeString getDefaultRuleSetName() const
Return the name of the current default rule set.
RuleBasedNumberFormat(const UnicodeString &rules, const UnicodeString &localizations, const Locale &locale, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode &status) const
Return the index'th display name locale.
virtual ERoundingMode getRoundingMode(void) const
Get the rounding mode.
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
virtual UnicodeString getRuleSetDisplayName(const UnicodeString &ruleSetName, const Locale &locale=Locale::getDefault())
Return the rule set display name for the provided rule set and locale.
virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols *symbolsToAdopt)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
virtual UnicodeString & format(const number::impl::DecimalQuantity &number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a decimal number.
RuleBasedNumberFormat(const UnicodeString &rules, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
virtual UnicodeString & format(double number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified number using the default ruleset.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
C++ API: Symbols for formatting numbers.
C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing.
C++ API: Locale ID object.
URBNFRuleSetTag
Tags for the predefined rulesets.
Definition rbnf.h:54
@ URBNF_COUNT
One more than the highest normal URBNFRuleSetTag value.
Definition rbnf.h:64
C++ API: Compatibility APIs for number formatting.
C++ API: String Enumeration.
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:58
UDisplayContext
Display context settings.
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:93
C API: Plural rules, select plural keywords for numeric values.
UPluralType
Type of plurals and PluralRules.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137