ICU 55.1  55.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 
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 
40 
41 class NFRuleSet;
42 class LocalizationInfo;
43 class PluralFormat;
44 class RuleBasedCollator;
45 
52  URBNF_SPELLOUT,
53  URBNF_ORDINAL,
54  URBNF_DURATION,
55  URBNF_NUMBERING_SYSTEM,
56  URBNF_COUNT
57 };
58 
523 public:
524 
525  //-----------------------------------------------------------------------
526  // constructors
527  //-----------------------------------------------------------------------
528 
540 
564  RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
565  UParseError& perror, UErrorCode& status);
566 
582  RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
583  UParseError& perror, UErrorCode& status);
584 
611  RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
612  const Locale& locale, UParseError& perror, UErrorCode& status);
613 
630 
631  //-----------------------------------------------------------------------
632  // boilerplate
633  //-----------------------------------------------------------------------
634 
641 
648 
654 
661  virtual Format* clone(void) const;
662 
670  virtual UBool operator==(const Format& other) const;
671 
672 //-----------------------------------------------------------------------
673 // public API functions
674 //-----------------------------------------------------------------------
675 
681  virtual UnicodeString getRules() const;
682 
688  virtual int32_t getNumberOfRuleSetNames() const;
689 
697  virtual UnicodeString getRuleSetName(int32_t index) const;
698 
704  virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
705 
714  virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
715 
729  virtual UnicodeString getRuleSetDisplayName(int32_t index,
730  const Locale& locale = Locale::getDefault());
731 
741  const Locale& locale = Locale::getDefault());
742 
743 
744  using NumberFormat::format;
745 
754  virtual UnicodeString& format(int32_t number,
755  UnicodeString& toAppendTo,
756  FieldPosition& pos) const;
757 
766  virtual UnicodeString& format(int64_t number,
767  UnicodeString& toAppendTo,
768  FieldPosition& pos) const;
777  virtual UnicodeString& format(double number,
778  UnicodeString& toAppendTo,
779  FieldPosition& pos) const;
780 
792  virtual UnicodeString& format(int32_t number,
793  const UnicodeString& ruleSetName,
794  UnicodeString& toAppendTo,
795  FieldPosition& pos,
796  UErrorCode& status) const;
808  virtual UnicodeString& format(int64_t number,
809  const UnicodeString& ruleSetName,
810  UnicodeString& toAppendTo,
811  FieldPosition& pos,
812  UErrorCode& status) const;
824  virtual UnicodeString& format(double number,
825  const UnicodeString& ruleSetName,
826  UnicodeString& toAppendTo,
827  FieldPosition& pos,
828  UErrorCode& status) const;
829 
830  using NumberFormat::parse;
831 
846  virtual void parse(const UnicodeString& text,
847  Formattable& result,
848  ParsePosition& parsePosition) const;
849 
850 #if !UCONFIG_NO_COLLATION
851 
885  virtual void setLenient(UBool enabled);
886 
894  virtual inline UBool isLenient(void) const;
895 
896 #endif
897 
906  virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
907 
915 
926  virtual void setContext(UDisplayContext value, UErrorCode& status);
927 
928 public:
934  static UClassID U_EXPORT2 getStaticClassID(void);
935 
941  virtual UClassID getDynamicClassID(void) const;
942 
951  virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
952 
962  virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
963 
964 private:
965  RuleBasedNumberFormat(); // default constructor not implemented
966 
967  // this will ref the localizations if they are not NULL
968  // caller must deref to get adoption
969  RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
970  const Locale& locale, UParseError& perror, UErrorCode& status);
971 
972  void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
973  void initCapitalizationContextInfo(const Locale& thelocale);
974  void dispose();
975  void stripWhitespace(UnicodeString& src);
976  void initDefaultRuleSet();
977  void format(double number, NFRuleSet& ruleSet);
978  NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
979 
980  /* friend access */
981  friend class NFSubstitution;
982  friend class NFRule;
983  friend class FractionalPartSubstitution;
984 
985  inline NFRuleSet * getDefaultRuleSet() const;
986  const RuleBasedCollator * getCollator() const;
987  DecimalFormatSymbols * getDecimalFormatSymbols() const;
988  PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
989  UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult) const;
990 
991 private:
992  NFRuleSet **ruleSets;
993  UnicodeString* ruleSetDescriptions;
994  int32_t numRuleSets;
995  NFRuleSet *defaultRuleSet;
996  Locale locale;
997  RuleBasedCollator* collator;
998  DecimalFormatSymbols* decimalFormatSymbols;
999  UBool lenient;
1000  UnicodeString* lenientParseRules;
1001  LocalizationInfo* localizations;
1002  UnicodeString originalDescription;
1003  UBool capitalizationInfoSet;
1004  UBool capitalizationForUIListMenu;
1005  UBool capitalizationForStandAlone;
1006  BreakIterator* capitalizationBrkIter;
1007 };
1008 
1009 // ---------------
1010 
1011 #if !UCONFIG_NO_COLLATION
1012 
1013 inline UBool
1014 RuleBasedNumberFormat::isLenient(void) const {
1015  return lenient;
1016 }
1017 
1018 #endif
1019 
1020 inline NFRuleSet*
1021 RuleBasedNumberFormat::getDefaultRuleSet() const {
1022  return defaultRuleSet;
1023 }
1024 
1026 
1027 /* U_HAVE_RBNF */
1028 #endif
1029 
1030 /* RBNF_H */
1031 #endif
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:84
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:44
icu::RuleBasedNumberFormat::adoptDecimalFormatSymbols
virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols *symbolsToAdopt)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:100
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
RuleBasedNumberFormat(const UnicodeString &rules, const Locale &locale, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the rules passed in.
icu::URBNFRuleSetTag
URBNFRuleSetTag
Tags for the predefined rulesets.
Definition: rbnf.h:51
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:172
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
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.
icu::RuleBasedNumberFormat::format
virtual UnicodeString & format(int32_t number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified 32-bit number using the default ruleset.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale &locale, UErrorCode &status)
Creates a RuleBasedNumberFormat from a predefined ruleset.
icu::RuleBasedNumberFormat::getRuleSetDisplayName
virtual UnicodeString getRuleSetDisplayName(const UnicodeString &ruleSetName, const Locale &locale=Locale::getDefault())
Return the rule set display name for the provided rule set and locale.
icu::RuleBasedNumberFormat::format
virtual UnicodeString & format(double number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified number using the default ruleset.
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
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
icu::RuleBasedNumberFormat::getDefaultRuleSetName
virtual UnicodeString getDefaultRuleSetName() const
Return the name of the current default rule set.
icu::RuleBasedNumberFormat::getRuleSetDisplayNameLocale
virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode &status) const
Return the index'th display name locale.
icu::RuleBasedNumberFormat::setContext
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
icu::PluralFormat
Definition: plurfmt.h:144
icu::RuleBasedNumberFormat::clone
virtual Format * clone(void) const
Clone this object polymorphically.
brkiter.h
C++ API: Break Iterator.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
icu::RuleBasedNumberFormat::operator==
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
icu::RuleBasedNumberFormat::format
virtual UnicodeString & format(double number, const UnicodeString &ruleSetName, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
Formats the specified number using the named ruleset.
icu::RuleBasedNumberFormat::setDecimalFormatSymbols
virtual void setDecimalFormatSymbols(const DecimalFormatSymbols &symbols)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
icu::Format
Base class for all formats.
Definition: format.h:94
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:476
icu::RuleBasedNumberFormat::format
virtual UnicodeString & format(int64_t number, UnicodeString &toAppendTo, FieldPosition &pos) const
Formats the specified 64-bit number using the default ruleset.
icu::RuleBasedNumberFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const
ICU "poor man's RTTI", returns a UClassID for the actual class.
fmtable.h
C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing.
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:111
dcfmtsym.h
C++ API: Symbols for formatting numbers.
icu::RuleBasedNumberFormat::getNumberOfRuleSetDisplayNameLocales
virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const
Return the number of locales for which we have localized rule set display names.
icu::RuleBasedNumberFormat::getRuleSetDisplayName
virtual UnicodeString getRuleSetDisplayName(int32_t index, const Locale &locale=Locale::getDefault())
Return the rule set display names for the provided locale.
icu::RuleBasedNumberFormat::format
virtual UnicodeString & format(int32_t number, const UnicodeString &ruleSetName, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
Formats the specified number using the named ruleset.
icu::RuleBasedNumberFormat::getNumberOfRuleSetNames
virtual int32_t getNumberOfRuleSetNames() const
Return the number of public rule set names.
icu::NumberFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
RuleBasedNumberFormat(const UnicodeString &rules, const UnicodeString &localizations, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
icu::RuleBasedNumberFormat::parse
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.
icu::RuleBasedNumberFormat::setLenient
virtual void setLenient(UBool enabled)
Turns lenient parse mode on and off.
icu::RuleBasedNumberFormat::format
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.
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:59
strenum.h
C++ API: String Enumeration.
icu::RuleBasedNumberFormat::operator=
RuleBasedNumberFormat & operator=(const RuleBasedNumberFormat &rhs)
Assignment operator.
icu::RuleBasedNumberFormat::setDefaultRuleSet
virtual void setDefaultRuleSet(const UnicodeString &ruleSetName, UErrorCode &status)
Override the default rule set to use.
numfmt.h
C++ API: Abstract base class for all number formats.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
RuleBasedNumberFormat(const UnicodeString &rules, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
icu::NumberFormat::isLenient
virtual UBool isLenient(void) const
Returns whether lenient parsing is enabled (it is off by default).
Definition: numfmt.h:1175
locid.h
C++ API: Locale ID object.
icu::RuleBasedNumberFormat::getRules
virtual UnicodeString getRules() const
return the rules that were provided to the RuleBasedNumberFormat.
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::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
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::RuleBasedNumberFormat::RuleBasedNumberFormat
RuleBasedNumberFormat(const RuleBasedNumberFormat &rhs)
Copy constructor.
icu::RuleBasedNumberFormat::~RuleBasedNumberFormat
virtual ~RuleBasedNumberFormat()
Release memory allocated for a RuleBasedNumberFormat when you are finished with it.
icu::RuleBasedNumberFormat::getRuleSetName
virtual UnicodeString getRuleSetName(int32_t index) const
Return the name of the index'th public ruleSet.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
icu::RuleBasedNumberFormat::getStaticClassID
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
unistr.h
C++ API: Unicode String.
icu::RuleBasedNumberFormat
The RuleBasedNumberFormat class formats numbers according to a set of rules.
Definition: rbnf.h:522
icu::NumberFormat::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
upluralrules.h
C API: Plural rules, select plural keywords for numeric values.