rbnf.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 1997-2015, International Business Machines Corporation and others.
* All Rights Reserved.
*******************************************************************************
*/
#ifndef RBNF_H
#define RBNF_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if UCONFIG_NO_FORMATTING
#define U_HAVE_RBNF 0
#else
#define U_HAVE_RBNF 1
#include "unicode/dcfmtsym.h"
#include "unicode/fmtable.h"
#include "unicode/locid.h"
#include "unicode/numfmt.h"
#include "unicode/unistr.h"
#include "unicode/strenum.h"
#include "unicode/brkiter.h"
#include "unicode/upluralrules.h"
U_NAMESPACE_BEGIN
class NFRule;
class NFRuleSet;
class LocalizationInfo;
class PluralFormat;
class RuleBasedCollator;
enum URBNFRuleSetTag {
URBNF_SPELLOUT,
URBNF_ORDINAL,
#ifndef U_HIDE_DEPRECATED_API
URBNF_DURATION,
#endif // U_HIDE_DERECATED_API
URBNF_NUMBERING_SYSTEM = 3,
#ifndef U_HIDE_DEPRECATED_API
URBNF_COUNT
#endif // U_HIDE_DEPRECATED_API
};
class U_I18N_API RuleBasedNumberFormat : public NumberFormat {
public:
//-----------------------------------------------------------------------
// constructors
//-----------------------------------------------------------------------
RuleBasedNumberFormat(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
UParseError& perror, UErrorCode& status);
RuleBasedNumberFormat(const UnicodeString& rules, const Locale& locale,
UParseError& perror, UErrorCode& status);
RuleBasedNumberFormat(const UnicodeString& rules, const UnicodeString& localizations,
const Locale& locale, UParseError& perror, UErrorCode& status);
RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
//-----------------------------------------------------------------------
// boilerplate
//-----------------------------------------------------------------------
RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
virtual ~RuleBasedNumberFormat();
virtual RuleBasedNumberFormat* clone() const override;
virtual bool operator==(const Format& other) const override;
//-----------------------------------------------------------------------
// public API functions
//-----------------------------------------------------------------------
virtual UnicodeString getRules() const;
virtual int32_t getNumberOfRuleSetNames() const;
virtual UnicodeString getRuleSetName(int32_t index) const;
virtual int32_t getNumberOfRuleSetDisplayNameLocales(void) const;
virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
virtual UnicodeString getRuleSetDisplayName(int32_t index,
const Locale& locale = Locale::getDefault());
virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
const Locale& locale = Locale::getDefault());
using NumberFormat::format;
virtual UnicodeString& format(int32_t number,
UnicodeString& toAppendTo,
FieldPosition& pos) const override;
virtual UnicodeString& format(int64_t number,
UnicodeString& toAppendTo,
FieldPosition& pos) const override;
virtual UnicodeString& format(double number,
UnicodeString& toAppendTo,
FieldPosition& pos) const override;
virtual UnicodeString& format(int32_t number,
const UnicodeString& ruleSetName,
UnicodeString& toAppendTo,
FieldPosition& pos,
UErrorCode& status) const;
virtual UnicodeString& format(int64_t number,
const UnicodeString& ruleSetName,
UnicodeString& toAppendTo,
FieldPosition& pos,
UErrorCode& status) const;
virtual UnicodeString& format(double number,
const UnicodeString& ruleSetName,
UnicodeString& toAppendTo,
FieldPosition& pos,
UErrorCode& status) const;
protected:
virtual UnicodeString& format(const number::impl::DecimalQuantity &number,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const override;
public:
using NumberFormat::parse;
virtual void parse(const UnicodeString& text,
Formattable& result,
ParsePosition& parsePosition) const override;
#if !UCONFIG_NO_COLLATION
virtual void setLenient(UBool enabled) override;
virtual inline UBool isLenient(void) const override;
#endif
virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
virtual UnicodeString getDefaultRuleSetName() const;
virtual void setContext(UDisplayContext value, UErrorCode& status) override;
virtual ERoundingMode getRoundingMode(void) const override;
virtual void setRoundingMode(ERoundingMode roundingMode) override;
public:
static UClassID U_EXPORT2 getStaticClassID(void);
virtual UClassID getDynamicClassID(void) const override;
virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
private:
RuleBasedNumberFormat() = delete; // default constructor not implemented
// this will ref the localizations if they are not nullptr
// caller must deref to get adoption
RuleBasedNumberFormat(const UnicodeString& description, LocalizationInfo* localizations,
const Locale& locale, UParseError& perror, UErrorCode& status);
void init(const UnicodeString& rules, LocalizationInfo* localizations, UParseError& perror, UErrorCode& status);
void initCapitalizationContextInfo(const Locale& thelocale);
void dispose();
void stripWhitespace(UnicodeString& src);
void initDefaultRuleSet();
NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
/* friend access */
friend class NFSubstitution;
friend class NFRule;
friend class NFRuleSet;
friend class FractionalPartSubstitution;
inline NFRuleSet * getDefaultRuleSet() const;
const RuleBasedCollator * getCollator() const;
DecimalFormatSymbols * initializeDecimalFormatSymbols(UErrorCode &status);
const DecimalFormatSymbols * getDecimalFormatSymbols() const;
NFRule * initializeDefaultInfinityRule(UErrorCode &status);
const NFRule * getDefaultInfinityRule() const;
NFRule * initializeDefaultNaNRule(UErrorCode &status);
const NFRule * getDefaultNaNRule() const;
PluralFormat *createPluralFormat(UPluralType pluralType, const UnicodeString &pattern, UErrorCode& status) const;
UnicodeString& adjustForCapitalizationContext(int32_t startPos, UnicodeString& currentResult, UErrorCode& status) const;
UnicodeString& format(int64_t number, NFRuleSet *ruleSet, UnicodeString& toAppendTo, UErrorCode& status) const;
void format(double number, NFRuleSet& rs, UnicodeString& toAppendTo, UErrorCode& status) const;
private:
NFRuleSet **fRuleSets;
UnicodeString* ruleSetDescriptions;
int32_t numRuleSets;
NFRuleSet *defaultRuleSet;
Locale locale;
RuleBasedCollator* collator;
DecimalFormatSymbols* decimalFormatSymbols;
NFRule *defaultInfinityRule;
NFRule *defaultNaNRule;
ERoundingMode fRoundingMode;
UBool lenient;
UnicodeString* lenientParseRules;
LocalizationInfo* localizations;
UnicodeString originalDescription;
UBool capitalizationInfoSet;
UBool capitalizationForUIListMenu;
UBool capitalizationForStandAlone;
BreakIterator* capitalizationBrkIter;
};
// ---------------
#if !UCONFIG_NO_COLLATION
inline UBool
RuleBasedNumberFormat::isLenient(void) const {
return lenient;
}
#endif
inline NFRuleSet*
RuleBasedNumberFormat::getDefaultRuleSet() const {
return defaultRuleSet;
}
U_NAMESPACE_END
/* U_HAVE_RBNF */
#endif
#endif /* U_SHOW_CPLUSPLUS_API */
/* RBNF_H */
#endif
brkiter.h
C++ API: Break Iterator.
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:106
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:86
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
icu::Format
Base class for all formats.
Definition: format.h:98
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::NumberFormat
Definition: numfmt.h:175
icu::NumberFormat::isLenient
virtual UBool isLenient(void) const
Returns whether lenient parsing is enabled (it is off by default).
Definition: numfmt.h:1276
icu::NumberFormat::ERoundingMode
ERoundingMode
Rounding mode.
Definition: numfmt.h:186
icu::NumberFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
icu::NumberFormat::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
icu::PluralFormat
Definition: plurfmt.h:148
icu::RuleBasedCollator
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:115
icu::RuleBasedNumberFormat
The RuleBasedNumberFormat class formats numbers according to a set of rules.
Definition: rbnf.h:582
icu::RuleBasedNumberFormat::setLenient
virtual void setLenient(UBool enabled) override
Turns lenient parse mode on and off.
icu::RuleBasedNumberFormat::operator=
RuleBasedNumberFormat & operator=(const RuleBasedNumberFormat &rhs)
Assignment operator.
icu::RuleBasedNumberFormat::format
virtual UnicodeString & format(double number, UnicodeString &toAppendTo, FieldPosition &pos) const override
Formats the specified number using the default ruleset.
icu::RuleBasedNumberFormat::getRuleSetName
virtual UnicodeString getRuleSetName(int32_t index) const
Return the name of the index'th public ruleSet.
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::format
virtual UnicodeString & format(int32_t number, UnicodeString &toAppendTo, FieldPosition &pos) const override
Formats the specified 32-bit number using the default ruleset.
icu::RuleBasedNumberFormat::getRules
virtual UnicodeString getRules() const
return the rules that were provided to the RuleBasedNumberFormat.
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::RuleBasedNumberFormat::getNumberOfRuleSetNames
virtual int32_t getNumberOfRuleSetNames() const
Return the number of public rule set names.
icu::RuleBasedNumberFormat::getRoundingMode
virtual ERoundingMode getRoundingMode(void) const override
Get the rounding mode.
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::getDynamicClassID
virtual UClassID getDynamicClassID(void) const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::RuleBasedNumberFormat::format
virtual UnicodeString & format(int64_t number, UnicodeString &toAppendTo, FieldPosition &pos) const override
Formats the specified 64-bit number using the default 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::RuleBasedNumberFormat::setContext
virtual void setContext(UDisplayContext value, UErrorCode &status) override
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
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.
icu::RuleBasedNumberFormat::~RuleBasedNumberFormat
virtual ~RuleBasedNumberFormat()
Release memory allocated for a RuleBasedNumberFormat when you are finished with it.
icu::RuleBasedNumberFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const override
Parses the specified string, beginning at the specified position, according to this formatter's rules...
icu::RuleBasedNumberFormat::setRoundingMode
virtual void setRoundingMode(ERoundingMode roundingMode) override
Set the rounding mode.
icu::RuleBasedNumberFormat::setDefaultRuleSet
virtual void setDefaultRuleSet(const UnicodeString &ruleSetName, UErrorCode &status)
Override the default rule set to use.
icu::RuleBasedNumberFormat::clone
virtual RuleBasedNumberFormat * clone() const override
Clone this object polymorphically.
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::RuleBasedNumberFormat
RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale &locale, UErrorCode &status)
Creates a RuleBasedNumberFormat from a predefined ruleset.
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::RuleBasedNumberFormat
RuleBasedNumberFormat(const RuleBasedNumberFormat &rhs)
Copy constructor.
icu::RuleBasedNumberFormat::getDefaultRuleSetName
virtual UnicodeString getDefaultRuleSetName() const
Return the name of the current default rule set.
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::getRuleSetDisplayNameLocale
virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode &status) const
Return the index'th display name locale.
icu::RuleBasedNumberFormat::format
virtual UnicodeString & format(const number::impl::DecimalQuantity &number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Format a decimal number.
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::operator==
virtual bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
icu::RuleBasedNumberFormat::getStaticClassID
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
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::adoptDecimalFormatSymbols
virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols *symbolsToAdopt)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
RuleBasedNumberFormat(const UnicodeString &rules, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
dcfmtsym.h
C++ API: Symbols for formatting numbers.
fmtable.h
C++ API: Formattable is a thin wrapper for primitive types used for formatting and parsing.
locid.h
C++ API: Locale ID object.
icu::URBNFRuleSetTag
URBNFRuleSetTag
Tags for the predefined rulesets.
Definition: rbnf.h:56
icu::URBNF_COUNT
@ URBNF_COUNT
One more than the highest normal URBNFRuleSetTag value.
Definition: rbnf.h:86
icu::URBNF_DURATION
@ URBNF_DURATION
Requests predefined ruleset for formatting a value as a duration in hours, minutes,...
Definition: rbnf.h:72
icu::URBNF_ORDINAL
@ URBNF_ORDINAL
Requests predefined ruleset for the ordinal form of a number.
Definition: rbnf.h:66
icu::URBNF_SPELLOUT
@ URBNF_SPELLOUT
Requests predefined ruleset for spelling out numeric values in words.
Definition: rbnf.h:61
numfmt.h
C++ API: Compatibility APIs for number formatting.
strenum.h
C++ API: String Enumeration.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:64
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
unistr.h
C++ API: Unicode String.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
upluralrules.h
C API: Plural rules, select plural keywords for numeric values.
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:59
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
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:301