Loading...
Searching...
No Matches
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_CLASS RuleBasedNumberFormat : public NumberFormat {
public:
//-----------------------------------------------------------------------
// constructors
//-----------------------------------------------------------------------
U_I18N_API RuleBasedNumberFormat(const UnicodeString& rules,
UParseError& perror,
UErrorCode& status);
U_I18N_API RuleBasedNumberFormat(const UnicodeString& rules,
const UnicodeString& localizations,
UParseError& perror,
UErrorCode& status);
U_I18N_API RuleBasedNumberFormat(const UnicodeString& rules,
const Locale& locale,
UParseError& perror,
UErrorCode& status);
U_I18N_API RuleBasedNumberFormat(const UnicodeString& rules,
const UnicodeString& localizations,
const Locale& locale,
UParseError& perror,
UErrorCode& status);
U_I18N_API RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale& locale, UErrorCode& status);
//-----------------------------------------------------------------------
// boilerplate
//-----------------------------------------------------------------------
U_I18N_API RuleBasedNumberFormat(const RuleBasedNumberFormat& rhs);
U_I18N_API RuleBasedNumberFormat& operator=(const RuleBasedNumberFormat& rhs);
U_I18N_API virtual ~RuleBasedNumberFormat();
U_I18N_API virtual RuleBasedNumberFormat* clone() const override;
U_I18N_API virtual bool operator==(const Format& other) const override;
//-----------------------------------------------------------------------
// public API functions
//-----------------------------------------------------------------------
U_I18N_API virtual UnicodeString getRules() const;
U_I18N_API virtual int32_t getNumberOfRuleSetNames() const;
U_I18N_API virtual UnicodeString getRuleSetName(int32_t index) const;
U_I18N_API virtual int32_t getNumberOfRuleSetDisplayNameLocales() const;
U_I18N_API virtual Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const;
U_I18N_API virtual UnicodeString getRuleSetDisplayName(int32_t index,
const Locale& locale = Locale::getDefault());
U_I18N_API virtual UnicodeString getRuleSetDisplayName(const UnicodeString& ruleSetName,
const Locale& locale = Locale::getDefault());
using NumberFormat::format;
U_I18N_API virtual UnicodeString& format(int32_t number,
UnicodeString& toAppendTo,
FieldPosition& pos) const override;
U_I18N_API virtual UnicodeString& format(int64_t number,
UnicodeString& toAppendTo,
FieldPosition& pos) const override;
U_I18N_API virtual UnicodeString& format(double number,
UnicodeString& toAppendTo,
FieldPosition& pos) const override;
U_I18N_API virtual UnicodeString& format(int32_t number,
const UnicodeString& ruleSetName,
UnicodeString& toAppendTo,
FieldPosition& pos,
UErrorCode& status) const;
U_I18N_API virtual UnicodeString& format(int64_t number,
const UnicodeString& ruleSetName,
UnicodeString& toAppendTo,
FieldPosition& pos,
UErrorCode& status) const;
U_I18N_API 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;
U_I18N_API virtual void parse(const UnicodeString& text,
Formattable& result,
ParsePosition& parsePosition) const override;
#if !UCONFIG_NO_COLLATION
U_I18N_API virtual void setLenient(UBool enabled) override;
U_I18N_API virtual inline UBool isLenient() const override;
#endif
U_I18N_API virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
U_I18N_API virtual UnicodeString getDefaultRuleSetName() const;
U_I18N_API virtual void setContext(UDisplayContext value, UErrorCode& status) override;
U_I18N_API virtual ERoundingMode getRoundingMode() const override;
U_I18N_API virtual void setRoundingMode(ERoundingMode roundingMode) override;
public:
U_I18N_API static UClassID getStaticClassID();
U_I18N_API virtual UClassID getDynamicClassID() const override;
U_I18N_API virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
U_I18N_API 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() 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:63
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
icu::Locale::getDefault
static U_COMMON_API const Locale & getDefault()
Common methods of getting the current default Locale.
icu::NumberFormat::NumberFormat
NumberFormat()
Default constructor for subclass use only.
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
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Format an object to produce a string.
icu::NumberFormat::isLenient
virtual UBool isLenient() const
Returns whether lenient parsing is enabled (it is off by default).
Definition numfmt.h:1274
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::isLenient
virtual U_I18N_API UBool isLenient() const override
Returns true if lenient-parse mode is turned on.
Definition rbnf.h:1176
icu::RuleBasedNumberFormat::setContext
virtual U_I18N_API 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 U_I18N_API UnicodeString & format(int64_t number, UnicodeString &toAppendTo, FieldPosition &pos) const override
Formats the specified 64-bit number using the default ruleset.
icu::RuleBasedNumberFormat::getDynamicClassID
virtual U_I18N_API UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::RuleBasedNumberFormat::getRuleSetName
virtual U_I18N_API UnicodeString getRuleSetName(int32_t index) const
Return the name of the index'th public ruleSet.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
U_I18N_API RuleBasedNumberFormat(const UnicodeString &rules, const UnicodeString &localizations, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
icu::RuleBasedNumberFormat::getDefaultRuleSetName
virtual U_I18N_API UnicodeString getDefaultRuleSetName() const
Return the name of the current default rule set.
icu::RuleBasedNumberFormat::getNumberOfRuleSetDisplayNameLocales
virtual U_I18N_API int32_t getNumberOfRuleSetDisplayNameLocales() const
Return the number of locales for which we have localized rule set display names.
icu::RuleBasedNumberFormat::setRoundingMode
virtual U_I18N_API void setRoundingMode(ERoundingMode roundingMode) override
Set the rounding mode.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
U_I18N_API 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::getNumberOfRuleSetNames
virtual U_I18N_API int32_t getNumberOfRuleSetNames() const
Return the number of public rule set names.
icu::RuleBasedNumberFormat::getRuleSetDisplayName
virtual U_I18N_API UnicodeString getRuleSetDisplayName(int32_t index, const Locale &locale=Locale::getDefault())
Return the rule set display names for the provided locale.
icu::RuleBasedNumberFormat::setDefaultRuleSet
virtual U_I18N_API void setDefaultRuleSet(const UnicodeString &ruleSetName, UErrorCode &status)
Override the default rule set to use.
icu::RuleBasedNumberFormat::operator==
virtual U_I18N_API bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
icu::RuleBasedNumberFormat::format
virtual U_I18N_API UnicodeString & format(double number, const UnicodeString &ruleSetName, UnicodeString &toAppendTo, FieldPosition &pos, UErrorCode &status) const
Formats the specified number using the named ruleset.
icu::RuleBasedNumberFormat::clone
virtual U_I18N_API RuleBasedNumberFormat * clone() const override
Clone this object polymorphically.
icu::RuleBasedNumberFormat::~RuleBasedNumberFormat
virtual U_I18N_API ~RuleBasedNumberFormat()
Release memory allocated for a RuleBasedNumberFormat when you are finished with it.
icu::RuleBasedNumberFormat::format
virtual U_I18N_API 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::format
virtual U_I18N_API 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::getStaticClassID
static U_I18N_API UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::RuleBasedNumberFormat::getRoundingMode
virtual U_I18N_API ERoundingMode getRoundingMode() const override
Get the rounding mode.
icu::RuleBasedNumberFormat::setDecimalFormatSymbols
virtual U_I18N_API void setDecimalFormatSymbols(const DecimalFormatSymbols &symbols)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
U_I18N_API RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale &locale, UErrorCode &status)
Creates a RuleBasedNumberFormat from a predefined ruleset.
icu::RuleBasedNumberFormat::format
virtual U_I18N_API UnicodeString & format(int32_t number, UnicodeString &toAppendTo, FieldPosition &pos) const override
Formats the specified 32-bit number using the default ruleset.
icu::RuleBasedNumberFormat::getRuleSetDisplayName
virtual U_I18N_API 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::getRuleSetDisplayNameLocale
virtual U_I18N_API Locale getRuleSetDisplayNameLocale(int32_t index, UErrorCode &status) const
Return the index'th display name locale.
icu::RuleBasedNumberFormat::parse
virtual U_I18N_API 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::RuleBasedNumberFormat
U_I18N_API RuleBasedNumberFormat(const UnicodeString &rules, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the description passed in.
icu::RuleBasedNumberFormat::getRules
virtual U_I18N_API UnicodeString getRules() const
return the rules that were provided to the RuleBasedNumberFormat.
icu::RuleBasedNumberFormat::setLenient
virtual U_I18N_API void setLenient(UBool enabled) override
Turns lenient parse mode on and off.
icu::RuleBasedNumberFormat::operator=
U_I18N_API RuleBasedNumberFormat & operator=(const RuleBasedNumberFormat &rhs)
Assignment operator.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
U_I18N_API RuleBasedNumberFormat(const UnicodeString &rules, const Locale &locale, UParseError &perror, UErrorCode &status)
Creates a RuleBasedNumberFormat that behaves according to the rules passed in.
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::adoptDecimalFormatSymbols
virtual U_I18N_API void adoptDecimalFormatSymbols(DecimalFormatSymbols *symbolsToAdopt)
Sets the decimal format symbols, which is generally not changed by the programmer or user.
icu::RuleBasedNumberFormat::format
virtual U_I18N_API UnicodeString & format(double number, UnicodeString &toAppendTo, FieldPosition &pos) const override
Formats the specified number using the default ruleset.
icu::RuleBasedNumberFormat::RuleBasedNumberFormat
U_I18N_API RuleBasedNumberFormat(const RuleBasedNumberFormat &rhs)
Copy constructor.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
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_NUMBERING_SYSTEM
@ URBNF_NUMBERING_SYSTEM
Requests predefined ruleset for various non-place-value numbering systems.
Definition rbnf.h:80
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:269
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:509
U_I18N_API_CLASS
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition utypes.h:457
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:316