ICU 57.1 57.1
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
17
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"
38
40
41class NFRule;
42class NFRuleSet;
43class LocalizationInfo;
44class PluralFormat;
46
53 URBNF_SPELLOUT,
54 URBNF_ORDINAL,
55 URBNF_DURATION,
56 URBNF_NUMBERING_SYSTEM,
57 URBNF_COUNT
58};
59
554public:
555
556 //-----------------------------------------------------------------------
557 // constructors
558 //-----------------------------------------------------------------------
559
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
661
662 //-----------------------------------------------------------------------
663 // boilerplate
664 //-----------------------------------------------------------------------
665
672
679
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
761 const Locale& locale = Locale::getDefault());
762
772 const Locale& locale = Locale::getDefault());
773
774
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
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
946
957 virtual void setContext(UDisplayContext value, UErrorCode& status);
958
959public:
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
995private:
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
1028private:
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
1052inline UBool
1054 return lenient;
1055}
1056
1057#endif
1058
1059inline NFRuleSet*
1060RuleBasedNumberFormat::getDefaultRuleSet() const {
1061 return defaultRuleSet;
1062}
1063
1065
1066/* U_HAVE_RBNF */
1067#endif
1068
1069/* RBNF_H */
1070#endif
C++ API: Break Iterator.
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition brkiter.h:100
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition dcfmtsym.h:84
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:106
Format()
Default constructor for subclass use only.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:66
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:185
static const Locale & getDefault(void)
Common methods of getting the current default Locale.
NumberFormat()
Default constructor for subclass use only.
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
virtual UBool isLenient(void) const
Returns whether lenient parsing is enabled (it is off by default).
Definition numfmt.h:1168
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition tblcoll.h:111
RuleBasedNumberFormat(const UnicodeString &rules, const UnicodeString &localizations, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
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.
RuleBasedNumberFormat(const RuleBasedNumberFormat &rhs)
Copy constructor.
RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale &locale, UErrorCode &status)
Creates a RuleBasedNumberFormat from a predefined ruleset.
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 void setDecimalFormatSymbols(const DecimalFormatSymbols &symbols)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
virtual int32_t getNumberOfRuleSetNames() const
Return the number of public rule set names.
virtual UnicodeString getRules() const
return the rules that were provided to the RuleBasedNumberFormat.
virtual UnicodeString & format(int64_t number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified 64-bit number using the default ruleset.
virtual UnicodeString getRuleSetDisplayName(int32_t index, const Locale &locale=Locale::getDefault())
Return the rule set display names for the provided locale.
RuleBasedNumberFormat(const UnicodeString &rules, const Locale &locale, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the rules passed in.
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
virtual UnicodeString & format(double 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.
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 UnicodeString getRuleSetName(int32_t index) const
Return the name of the index'th public ruleSet.
RuleBasedNumberFormat(const UnicodeString &rules, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
virtual void setLenient(UBool enabled)
Turns lenient parse mode on and off.
virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode &status) const
Return the index'th display name locale.
virtual UnicodeString & format(double number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified number using the default ruleset.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
virtual ~RuleBasedNumberFormat()
Release memory allocated for a RuleBasedNumberFormat when you are finished with it.
RuleBasedNumberFormat & operator=(const RuleBasedNumberFormat &rhs)
Assignment operator.
virtual UnicodeString & format(int32_t number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified 32-bit number using the default ruleset.
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 UClassID getDynamicClassID(void) const
ICU "poor man's RTTI", returns a UClassID for the actual 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 int32_t getNumberOfRuleSetDisplayNameLocales(void) const
Return the number of locales for which we have localized rule set display names.
virtual void setDefaultRuleSet(const UnicodeString &ruleSetName, UErrorCode &status)
Override the default rule set to use.
virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols *symbolsToAdopt)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
virtual UnicodeString getDefaultRuleSetName() const
Return the name of the current default rule set.
virtual UBool isLenient(void) const
Returns true if lenient-parse mode is turned on.
Definition rbnf.h:1053
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:294
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.
C++ API: Abstract base class for all number formats.
URBNFRuleSetTag
Tags for the predefined rulesets.
Definition rbnf.h:52
C++ API: String Enumeration.
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:56
UDisplayContext
Display context settings.
int8_t UBool
The ICU boolean type.
Definition umachine.h:234
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:91
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:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129