1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 4 ******************************************************************************** 5 * Copyright (C) 1997-2016, International Business Machines Corporation and others. 7 ******************************************************************************** 11 * Modification History: 13 * Date Name Description 14 * 02/19/97 aliu Converted from java. 15 * 03/18/97 clhuang Updated per C++ implementation. 16 * 04/17/97 aliu Changed DigitCount to int per code review. 17 * 07/20/98 stephen JDK 1.2 sync up. Added scientific support. 18 * Changed naming conventions to match C++ guidelines 19 * Deprecated Java style constants (eg, INTEGER_FIELD) 20 ******************************************************************************** 29 #if U_SHOW_CPLUSPLUS_API 36 #if !UCONFIG_NO_FORMATTING 46 classNumberFormatTest;
50 classSharedNumberFormat;
52 #if !UCONFIG_NO_SERVICE 53 classNumberFormatFactory;
54 classStringEnumeration;
587 // Can't use #ifndef U_HIDE_INTERNAL_API because these are virtual methods 708 UBool isParseIntegerOnly()
const;
736 virtualUBool isLenient()
const;
775 #ifndef U_HIDE_INTERNAL_API 783 constLocale& desiredLocale,
797 #endif/* U_HIDE_INTERNAL_API */ 866 #if !UCONFIG_NO_SERVICE 900 #endif/* UCONFIG_NO_SERVICE */ 1127 #ifndef U_HIDE_INTERNAL_API 1136 UBool mustBeDecimalFormat,
1138 #endif/* U_HIDE_INTERNAL_API */ 1155 UBool fGroupingUsed;
1156 int32_t fMaxIntegerDigits;
1157 int32_t fMinIntegerDigits;
1158 int32_t fMaxFractionDigits;
1159 int32_t fMinFractionDigits;
1168 UBool fParseIntegerOnly;
1169 UBool fLenient;
// true => lenient parse is enabled 1171 // ISO currency code 1172 char16_t fCurrency[4];
1176 friendclassICUNumberFormatFactory;
// access to makeInstance 1177 friendclassICUNumberFormatService;
1178 friend class ::NumberFormatTest;
// access to isStyleSupported() 1181 #if !UCONFIG_NO_SERVICE 1263 #endif/* #if !UCONFIG_NO_SERVICE */ 1265 // ------------------------------------- 1268 NumberFormat::isParseIntegerOnly()
const 1270 return fParseIntegerOnly;
1274 NumberFormat::isLenient()
const 1281 #endif/* #if !UCONFIG_NO_FORMATTING */ 1283 #endif/* U_SHOW_CPLUSPLUS_API */ A currency together with a numeric amount, such as 200 USD.
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Base class for all formats.
U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
Formattable objects can be passed to the Format class or its subclasses for formatting.
A Locale object represents a specific geographical, political, or cultural region.
A NumberFormatFactory is used to register new number formats.
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode &status) const =0
Return the locale names directly supported by this factory.
virtual UBool visible() const =0
Return true if this factory will be visible.
virtual NumberFormat * createFormat(const Locale &loc, UNumberFormatStyle formatType)=0
Return a number format of the appropriate type.
virtual ~NumberFormatFactory()
Destructor.
virtual void getEffectiveCurrency(char16_t *result, UErrorCode &ec) const
Returns the currency in effect for this formatter.
virtual void setMinimumIntegerDigits(int32_t newValue)
Sets the minimum number of digits allowed in the integer portion of a number.
static NumberFormat * createInstance(UErrorCode &)
Create a default style NumberFormat for the current default locale.
virtual void setParseIntegerOnly(UBool value)
Sets whether or not numbers should be parsed as integers only.
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an int64 number.
static const Locale * getAvailableLocales(int32_t &count)
Get the set of Locales for which NumberFormats are installed.
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format a long number.
virtual void setMaximumIntegerDigits(int32_t newValue)
Sets the maximum number of digits allowed in the integer portion of a number.
virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode &status) const
Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
virtual NumberFormat * clone() const override=0
Clones this object polymorphically.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const override
Parse a string to produce an object.
int32_t getMinimumFractionDigits() const
Returns the minimum number of digits allowed in the fraction portion of a number.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const override
Format an object to produce a string.
static NumberFormat * internalCreateInstance(const Locale &desiredLocale, UNumberFormatStyle style, UErrorCode &errorCode)
ICU use only.
static const int32_t gDefaultMaxIntegerDigits
virtual void setLenient(UBool enable)
Sets whether lenient parsing should be enabled (it is off by default).
static NumberFormat * createScientificInstance(UErrorCode &)
Returns a scientific format for the current default locale.
UnicodeString & format(int32_t number, UnicodeString &appendTo) const
Format a long number.
static NumberFormat * createScientificInstance(const Locale &inLocale, UErrorCode &)
Returns a scientific format for the specified locale.
static NumberFormat * makeInstance(const Locale &desiredLocale, UNumberFormatStyle style, UBool mustBeDecimalFormat, UErrorCode &errorCode)
Creates the specified number format style of the desired locale.
static NumberFormat * createInstance(const Locale &desiredLocale, UNumberFormatStyle style, UErrorCode &errorCode)
Create a specific style NumberFormat for the specified locale.
virtual ~NumberFormat()
Destructor.
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos) const =0
Format a long number.
UnicodeString & format(int64_t number, UnicodeString &appendTo) const
Format an int64 number.
virtual void setMinimumFractionDigits(int32_t newValue)
Sets the minimum number of digits allowed in the fraction portion of a number.
virtual CurrencyAmount * parseCurrency(const UnicodeString &text, ParsePosition &pos) const
Parses text from the given string as a currency amount.
NumberFormat()
Default constructor for subclass use only.
static const int32_t gDefaultMinIntegerDigits
EAlignmentFields
Alignment Field constants used to construct a FieldPosition object.
virtual UnicodeString & format(const number::impl::DecimalQuantity &number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a decimal number.
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format a double number.
int32_t getMaximumIntegerDigits() const
Returns the maximum number of digits allowed in the integer portion of a number.
virtual void setGroupingUsed(UBool newValue)
Set whether or not grouping will be used in this format.
static URegistryKey registerFactory(NumberFormatFactory *toAdopt, UErrorCode &status)
Register a new NumberFormatFactory.
static UClassID getStaticClassID()
Return the class ID for this class.
virtual void setCurrency(const char16_t *theCurrency, UErrorCode &ec)
Sets the currency used to display currency amounts.
const char16_t * getCurrency() const
Gets the currency used to display currency amounts.
virtual void setMaximumFractionDigits(int32_t newValue)
Sets the maximum number of digits allowed in the fraction portion of a number.
virtual bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
virtual ERoundingMode getRoundingMode() const
Get the rounding mode.
static const SharedNumberFormat * createSharedInstance(const Locale &inLocale, UNumberFormatStyle style, UErrorCode &status)
ICU use only.
ERoundingMode
Rounding mode.
@ kRoundDown
Round towards zero.
@ kRoundFloor
Round towards negative infinity.
@ kRoundCeiling
Round towards positive infinity.
@ kRoundUnnecessary
Return U_FORMAT_INEXACT_ERROR if number does not format exactly.
@ kRoundHalfFloor
Rounds ties toward -∞.
@ kRoundHalfOdd
Rounds ties toward the odd number.
@ kRoundHalfCeiling
Rounds ties toward +∞.
@ kRoundUp
Round away from zero.
static StringEnumeration * getAvailableLocales()
Return a StringEnumeration over the locales available at the time of the call, including registered l...
virtual UnicodeString & format(const number::impl::DecimalQuantity &number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format a decimal number.
virtual UnicodeString & format(StringPiece number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a decimal number.
virtual void setRoundingMode(ERoundingMode roundingMode)
Set the rounding mode.
static NumberFormat * createPercentInstance(const Locale &inLocale, UErrorCode &)
Returns a percentage format for the specified locale.
UBool isGroupingUsed() const
Returns true if grouping is used in this format.
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format an int32 number.
static NumberFormat * createCurrencyInstance(const Locale &inLocale, UErrorCode &)
Returns a currency format for the specified locale.
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos) const =0
Format a double number.
static UBool unregister(URegistryKey key, UErrorCode &status)
Unregister a previously-registered NumberFormatFactory using the key returned from the register call.
UnicodeString & format(double number, UnicodeString &appendTo) const
Format a double number.
virtual UClassID getDynamicClassID() const override=0
Returns a unique class ID POLYMORPHICALLY.
static NumberFormat * createPercentInstance(UErrorCode &)
Returns a percentage format for the current default locale.
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a double number.
NumberFormat & operator=(const NumberFormat &)
Assignment operator.
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPosition &pos) const
Format an int64 number.
int32_t getMaximumFractionDigits() const
Returns the maximum number of digits allowed in the fraction portion of a number.
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
static NumberFormat * createCurrencyInstance(UErrorCode &)
Returns a currency format for the current default locale.
NumberFormat(const NumberFormat &)
Copy constructor.
int32_t getMinimumIntegerDigits() const
Returns the minimum number of digits allowed in the integer portion of a number.
virtual void parse(const UnicodeString &text, Formattable &result, UErrorCode &status) const
Parse a string as a numeric value, and return a Formattable numeric object.
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format an int64 number.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Format an object to produce a string.
static NumberFormat * createInstance(const Locale &inLocale, UErrorCode &)
Create a default style NumberFormat for the specified locale.
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
A NumberFormatFactory that supports a single locale.
SimpleNumberFormatFactory(const Locale &locale, UBool visible=true)
virtual UBool visible() const override
virtual ~SimpleNumberFormatFactory()
virtual const UnicodeString * getSupportedIDs(int32_t &count, UErrorCode &status) const override
UnicodeString _id
The locale supported by this factory, as a UnicodeString.
const UBool _visible
True if the locale supported by this factory is visible.
Base class for 'pure' C++ implementations of uenum api.
A string-like object that points to a sized piece of memory.
UObject is the common ICU "boilerplate" class.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
C++ API: Currency Amount Object.
C++ API: Base class for all formats.
C++ API: Locale ID object.
C++ API: StringPiece: Read-only byte string wrapper class.
C API: Display context types (enum values)
UDisplayContextType
Display context types, for getting values of a particular setting.
UDisplayContext
Display context settings.
int8_t UBool
The ICU boolean type, a signed-byte integer.
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration.
C API: Compatibility APIs for number formatting.
UNumberFormatStyle
The possible number format styles.
@ UNUM_MEASURE_UNIT_FIELD
@ UNUM_EXPONENT_SYMBOL_FIELD
@ UNUM_GROUPING_SEPARATOR_FIELD
@ UNUM_DECIMAL_SEPARATOR_FIELD
@ UNUM_EXPONENT_SIGN_FIELD
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.