numberformatter.h
Go to the documentation of this file.
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#ifndef __NUMBERFORMATTER_H__
#define __NUMBERFORMATTER_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/appendable.h"
#include "unicode/bytestream.h"
#include "unicode/currunit.h"
#include "unicode/dcfmtsym.h"
#include "unicode/displayoptions.h"
#include "unicode/fieldpos.h"
#include "unicode/fpositer.h"
#include "unicode/measunit.h"
#include "unicode/nounit.h"
#include "unicode/parseerr.h"
#include "unicode/plurrule.h"
#include "unicode/ucurr.h"
#include "unicode/unum.h"
#include "unicode/unumberformatter.h"
#include "unicode/uobject.h"
#include "unicode/unumberoptions.h"
#include "unicode/formattednumber.h"
U_NAMESPACE_BEGIN
// Forward declarations:
class IFixedDecimal;
class FieldPositionIteratorHandler;
class FormattedStringBuilder;
namespace numparse::impl {
// Forward declarations:
class NumberParserImpl;
class MultiplierParseHandler;
} // namespace numparse::impl
namespace units {
// Forward declarations:
class UnitsRouter;
} // namespace units
namespace number { // icu::number
// Forward declarations:
class UnlocalizedNumberFormatter;
class LocalizedNumberFormatter;
class SimpleNumberFormatter;
class FormattedNumber;
class Notation;
class ScientificNotation;
class Precision;
class FractionPrecision;
class CurrencyPrecision;
class IncrementPrecision;
class IntegerWidth;
namespace impl {
// can't be #ifndef U_HIDE_INTERNAL_API; referenced throughout this file in public classes
typedef int16_t digits_t;
// can't be #ifndef U_HIDE_INTERNAL_API; needed for struct initialization
static constexpr int32_t kInternalDefaultThreshold = 3;
// Forward declarations:
class Padder;
struct MacroProps;
struct MicroProps;
class DecimalQuantity;
class UFormattedNumberData;
class NumberFormatterImpl;
struct ParsedPatternInfo;
class ScientificModifier;
class MultiplierProducer;
class RoundingImpl;
class ScientificHandler;
class Modifier;
class AffixPatternProvider;
class NumberPropertyMapper;
struct DecimalFormatProperties;
class MultiplierFormatHandler;
class CurrencySymbols;
class GeneratorHelpers;
class DecNum;
class NumberRangeFormatterImpl;
struct RangeMacroProps;
struct UFormattedNumberImpl;
class MutablePatternModifier;
class ImmutablePatternModifier;
struct DecimalFormatWarehouse;
struct SimpleMicroProps;
class AdoptingSignumModifierStore;
void touchRangeLocales(impl::RangeMacroProps& macros);
} // namespace impl
typedef Notation CompactNotation;
typedef Notation SimpleNotation;
class U_I18N_API Notation : public UMemory {
public:
static ScientificNotation scientific();
static ScientificNotation engineering();
static CompactNotation compactShort();
static CompactNotation compactLong();
static SimpleNotation simple();
private:
enum NotationType {
NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
} fType;
union NotationUnion {
// For NTN_SCIENTIFIC
struct ScientificSettings {
int8_t fEngineeringInterval;
bool fRequireMinInt;
impl::digits_t fMinExponentDigits;
UNumberSignDisplay fExponentSignDisplay;
} scientific;
// For NTN_COMPACT
UNumberCompactStyle compactStyle;
// For NTN_ERROR
UErrorCode errorCode;
} fUnion;
typedef NotationUnion::ScientificSettings ScientificSettings;
Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
fUnion.errorCode = errorCode;
}
Notation() : fType(NTN_SIMPLE), fUnion() {}
UBool copyErrorTo(UErrorCode &status) const {
if (fType == NTN_ERROR) {
status = fUnion.errorCode;
return true;
}
return false;
}
// To allow MacroProps to initialize empty instances:
friend struct impl::MacroProps;
friend class ScientificNotation;
// To allow implementation to access internal types:
friend class impl::NumberFormatterImpl;
friend class impl::ScientificModifier;
friend class impl::ScientificHandler;
// To allow access to the skeleton generation code:
friend class impl::GeneratorHelpers;
};
class U_I18N_API ScientificNotation : public Notation {
public:
ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const;
private:
// Inherit constructor
using Notation::Notation;
// Raw constructor for NumberPropertyMapper
ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
UNumberSignDisplay fExponentSignDisplay);
friend class Notation;
// So that NumberPropertyMapper can create instances
friend class impl::NumberPropertyMapper;
};
typedef Precision SignificantDigitsPrecision;
class U_I18N_API Precision : public UMemory {
public:
static Precision unlimited();
static FractionPrecision integer();
static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
static FractionPrecision minFraction(int32_t minFractionPlaces);
static FractionPrecision maxFraction(int32_t maxFractionPlaces);
static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
int32_t maxSignificantDigits);
static IncrementPrecision increment(double roundingIncrement);
static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude);
static CurrencyPrecision currency(UCurrencyUsage currencyUsage);
Precision trailingZeroDisplay(UNumberTrailingZeroDisplay trailingZeroDisplay) const;
private:
enum PrecisionType {
RND_BOGUS,
RND_NONE,
RND_FRACTION,
RND_SIGNIFICANT,
RND_FRACTION_SIGNIFICANT,
// Used for strange increments like 3.14.
RND_INCREMENT,
// Used for increments with 1 as the only digit. This is different than fraction
// rounding because it supports having additional trailing zeros. For example, this
// class is used to round with the increment 0.010.
RND_INCREMENT_ONE,
// Used for increments with 5 as the only digit (nickel rounding).
RND_INCREMENT_FIVE,
RND_CURRENCY,
RND_ERROR
} fType;
union PrecisionUnion {
struct FractionSignificantSettings {
// For RND_FRACTION, RND_SIGNIFICANT, and RND_FRACTION_SIGNIFICANT
impl::digits_t fMinFrac;
impl::digits_t fMaxFrac;
impl::digits_t fMinSig;
impl::digits_t fMaxSig;
UNumberRoundingPriority fPriority;
bool fRetain;
} fracSig;
struct IncrementSettings {
// For RND_INCREMENT, RND_INCREMENT_ONE, and RND_INCREMENT_FIVE
// Note: This is a union, so we shouldn't own memory, since
// the default destructor would leak it.
uint64_t fIncrement;
impl::digits_t fIncrementMagnitude;
impl::digits_t fMinFrac;
} increment;
UCurrencyUsage currencyUsage; // For RND_CURRENCY
UErrorCode errorCode; // For RND_ERROR
} fUnion;
UNumberTrailingZeroDisplay fTrailingZeroDisplay = UNUM_TRAILING_ZERO_AUTO;
typedef PrecisionUnion::FractionSignificantSettings FractionSignificantSettings;
typedef PrecisionUnion::IncrementSettings IncrementSettings;
Precision(const PrecisionType& type, const PrecisionUnion& union_)
: fType(type), fUnion(union_) {}
Precision(UErrorCode errorCode) : fType(RND_ERROR) {
fUnion.errorCode = errorCode;
}
Precision() : fType(RND_BOGUS) {}
bool isBogus() const {
return fType == RND_BOGUS;
}
UBool copyErrorTo(UErrorCode &status) const {
if (fType == RND_ERROR) {
status = fUnion.errorCode;
return true;
}
return false;
}
// On the parent type so that this method can be called internally on Precision instances.
Precision withCurrency(const CurrencyUnit &currency, UErrorCode &status) const;
static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
static Precision constructSignificant(int32_t minSig, int32_t maxSig);
static Precision constructFractionSignificant(
const FractionPrecision &base,
int32_t minSig,
int32_t maxSig,
UNumberRoundingPriority priority,
bool retain);
static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
// To allow MacroProps/MicroProps to initialize bogus instances:
friend struct impl::MacroProps;
friend struct impl::MicroProps;
// To allow NumberFormatterImpl to access isBogus() and other internal methods:
friend class impl::NumberFormatterImpl;
// To allow NumberPropertyMapper to create instances from DecimalFormatProperties:
friend class impl::NumberPropertyMapper;
// To allow access to the main implementation class:
friend class impl::RoundingImpl;
// To allow child classes to call private methods:
friend class FractionPrecision;
friend class CurrencyPrecision;
friend class IncrementPrecision;
// To allow access to the skeleton generation code:
friend class impl::GeneratorHelpers;
// To allow access to isBogus and the default (bogus) constructor:
friend class units::UnitsRouter;
};
class U_I18N_API FractionPrecision : public Precision {
public:
Precision withSignificantDigits(
int32_t minSignificantDigits,
int32_t maxSignificantDigits,
UNumberRoundingPriority priority) const;
Precision withMinDigits(int32_t minSignificantDigits) const;
Precision withMaxDigits(int32_t maxSignificantDigits) const;
private:
// Inherit constructor
using Precision::Precision;
// To allow parent class to call this class's constructor:
friend class Precision;
};
class U_I18N_API CurrencyPrecision : public Precision {
public:
Precision withCurrency(const CurrencyUnit &currency) const;
private:
// Inherit constructor
using Precision::Precision;
// To allow parent class to call this class's constructor:
friend class Precision;
};
class U_I18N_API IncrementPrecision : public Precision {
public:
Precision withMinFraction(int32_t minFrac) const;
private:
// Inherit constructor
using Precision::Precision;
// To allow parent class to call this class's constructor:
friend class Precision;
};
class U_I18N_API IntegerWidth : public UMemory {
public:
static IntegerWidth zeroFillTo(int32_t minInt);
IntegerWidth truncateAt(int32_t maxInt);
private:
union {
struct {
impl::digits_t fMinInt;
impl::digits_t fMaxInt;
bool fFormatFailIfMoreThanMaxDigits;
} minMaxInt;
UErrorCode errorCode;
} fUnion;
bool fHasError = false;
IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
IntegerWidth(UErrorCode errorCode) { // NOLINT
fUnion.errorCode = errorCode;
fHasError = true;
}
IntegerWidth() { // NOLINT
fUnion.minMaxInt.fMinInt = -1;
}
static IntegerWidth standard() {
return IntegerWidth::zeroFillTo(1);
}
bool isBogus() const {
return !fHasError && fUnion.minMaxInt.fMinInt == -1;
}
UBool copyErrorTo(UErrorCode &status) const {
if (fHasError) {
status = fUnion.errorCode;
return true;
}
return false;
}
void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
bool operator==(const IntegerWidth& other) const;
// To allow MacroProps/MicroProps to initialize empty instances:
friend struct impl::MacroProps;
friend struct impl::MicroProps;
// To allow NumberFormatterImpl to access isBogus():
friend class impl::NumberFormatterImpl;
// To allow the use of this class when formatting:
friend class impl::MutablePatternModifier;
friend class impl::ImmutablePatternModifier;
// So that NumberPropertyMapper can create instances
friend class impl::NumberPropertyMapper;
// To allow access to the skeleton generation code:
friend class impl::GeneratorHelpers;
};
class U_I18N_API Scale : public UMemory {
public:
static Scale none();
static Scale powerOfTen(int32_t power);
static Scale byDecimal(StringPiece multiplicand);
static Scale byDouble(double multiplicand);
static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
// We need a custom destructor for the DecNum, which means we need to declare
// the copy/move constructor/assignment quartet.
Scale(const Scale& other);
Scale& operator=(const Scale& other);
Scale(Scale&& src) noexcept;
Scale& operator=(Scale&& src) noexcept;
~Scale();
#ifndef U_HIDE_INTERNAL_API
Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
#endif /* U_HIDE_INTERNAL_API */
private:
int32_t fMagnitude;
impl::DecNum* fArbitrary;
UErrorCode fError;
Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
bool isValid() const {
return fMagnitude != 0 || fArbitrary != nullptr;
}
UBool copyErrorTo(UErrorCode &status) const {
if (U_FAILURE(fError)) {
status = fError;
return true;
}
return false;
}
void applyTo(impl::DecimalQuantity& quantity) const;
void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
// To allow MacroProps/MicroProps to initialize empty instances:
friend struct impl::MacroProps;
friend struct impl::MicroProps;
// To allow NumberFormatterImpl to access isBogus() and perform other operations:
friend class impl::NumberFormatterImpl;
// To allow the helper class MultiplierFormatHandler access to private fields:
friend class impl::MultiplierFormatHandler;
// To allow access to the skeleton generation code:
friend class impl::GeneratorHelpers;
// To allow access to parsing code:
friend class ::icu::numparse::impl::NumberParserImpl;
friend class ::icu::numparse::impl::MultiplierParseHandler;
};
namespace impl {
// Do not enclose entire StringProp with #ifndef U_HIDE_INTERNAL_API, needed for a protected field.
// And do not enclose its class boilerplate within #ifndef U_HIDE_INTERNAL_API.
class U_I18N_API StringProp : public UMemory {
public:
~StringProp();
StringProp(const StringProp &other);
StringProp &operator=(const StringProp &other);
#ifndef U_HIDE_INTERNAL_API
StringProp(StringProp &&src) noexcept;
StringProp &operator=(StringProp &&src) noexcept;
int16_t length() const {
return fLength;
}
void set(StringPiece value);
bool isSet() const {
return fLength > 0;
}
#endif // U_HIDE_INTERNAL_API
private:
char *fValue;
int16_t fLength;
UErrorCode fError;
StringProp() : fValue(nullptr), fLength(0), fError(U_ZERO_ERROR) {
}
UBool copyErrorTo(UErrorCode &status) const {
if (U_FAILURE(fError)) {
status = fError;
return true;
}
return false;
}
// Allow NumberFormatterImpl to access fValue.
friend class impl::NumberFormatterImpl;
// Allow skeleton generation code to access private members.
friend class impl::GeneratorHelpers;
// Allow MacroProps/MicroProps to initialize empty instances and to call
// copyErrorTo().
friend struct impl::MacroProps;
};
// Do not enclose entire SymbolsWrapper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
class U_I18N_API SymbolsWrapper : public UMemory {
public:
SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
SymbolsWrapper(const SymbolsWrapper &other);
SymbolsWrapper &operator=(const SymbolsWrapper &other);
SymbolsWrapper(SymbolsWrapper&& src) noexcept;
SymbolsWrapper &operator=(SymbolsWrapper&& src) noexcept;
~SymbolsWrapper();
#ifndef U_HIDE_INTERNAL_API
void setTo(const DecimalFormatSymbols &dfs);
void setTo(const NumberingSystem *ns);
bool isDecimalFormatSymbols() const;
bool isNumberingSystem() const;
const DecimalFormatSymbols *getDecimalFormatSymbols() const;
const NumberingSystem *getNumberingSystem() const;
#endif // U_HIDE_INTERNAL_API
UBool copyErrorTo(UErrorCode &status) const {
if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return true;
} else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return true;
}
return false;
}
private:
enum SymbolsPointerType {
SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
} fType;
union {
const DecimalFormatSymbols *dfs;
const NumberingSystem *ns;
} fPtr;
void doCopyFrom(const SymbolsWrapper &other);
void doMoveFrom(SymbolsWrapper&& src);
void doCleanup();
};
// Do not enclose entire Grouper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
class U_I18N_API Grouper : public UMemory {
public:
#ifndef U_HIDE_INTERNAL_API
static Grouper forStrategy(UNumberGroupingStrategy grouping);
static Grouper forProperties(const DecimalFormatProperties& properties);
// Future: static Grouper forProperties(DecimalFormatProperties& properties);
Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
: fGrouping1(grouping1),
fGrouping2(grouping2),
fMinGrouping(minGrouping),
fStrategy(strategy) {}
int16_t getPrimary() const;
int16_t getSecondary() const;
#endif // U_HIDE_INTERNAL_API
private:
int16_t fGrouping1;
int16_t fGrouping2;
int16_t fMinGrouping;
UNumberGroupingStrategy fStrategy;
Grouper() : fGrouping1(-3) {}
bool isBogus() const {
return fGrouping1 == -3;
}
void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
// To allow MacroProps/MicroProps to initialize empty instances:
friend struct MacroProps;
friend struct MicroProps;
friend struct SimpleMicroProps;
// To allow NumberFormatterImpl to access isBogus() and perform other operations:
friend class NumberFormatterImpl;
friend class ::icu::number::SimpleNumberFormatter;
// To allow NumberParserImpl to perform setLocaleData():
friend class ::icu::numparse::impl::NumberParserImpl;
// To allow access to the skeleton generation code:
friend class impl::GeneratorHelpers;
};
// Do not enclose entire Padder with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
class U_I18N_API Padder : public UMemory {
public:
#ifndef U_HIDE_INTERNAL_API
static Padder none();
static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
static Padder forProperties(const DecimalFormatProperties& properties);
#endif // U_HIDE_INTERNAL_API
private:
UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding
union {
struct {
int32_t fCp;
UNumberFormatPadPosition fPosition;
} padding;
UErrorCode errorCode;
} fUnion;
Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
Padder(int32_t width);
Padder(UErrorCode errorCode) : fWidth(-3) { // NOLINT
fUnion.errorCode = errorCode;
}
Padder() : fWidth(-2) {} // NOLINT
bool isBogus() const {
return fWidth == -2;
}
UBool copyErrorTo(UErrorCode &status) const {
if (fWidth == -3) {
status = fUnion.errorCode;
return true;
}
return false;
}
bool isValid() const {
return fWidth > 0;
}
int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
FormattedStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
UErrorCode &status) const;
// To allow MacroProps/MicroProps to initialize empty instances:
friend struct MacroProps;
friend struct MicroProps;
// To allow NumberFormatterImpl to access isBogus() and perform other operations:
friend class impl::NumberFormatterImpl;
// To allow access to the skeleton generation code:
friend class impl::GeneratorHelpers;
};
// Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
struct U_I18N_API MacroProps : public UMemory {
Notation notation;
MeasureUnit unit; // = MeasureUnit(); (the base dimensionless unit)
MeasureUnit perUnit; // = MeasureUnit(); (the base dimensionless unit)
Precision precision; // = Precision(); (bogus)
UNumberFormatRoundingMode roundingMode = UNUM_ROUND_HALFEVEN;
Grouper grouper; // = Grouper(); (bogus)
Padder padder; // = Padder(); (bogus)
IntegerWidth integerWidth; // = IntegerWidth(); (bogus)
SymbolsWrapper symbols;
// UNUM_XYZ_COUNT denotes null (bogus) values.
UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_COUNT;
UNumberSignDisplay sign = UNUM_SIGN_COUNT;
bool approximately = false;
UNumberDecimalSeparatorDisplay decimal = UNUM_DECIMAL_SEPARATOR_COUNT;
Scale scale; // = Scale(); (benign value)
StringProp usage; // = StringProp(); (no usage)
StringProp unitDisplayCase; // = StringProp(); (nominative)
const AffixPatternProvider* affixProvider = nullptr; // no ownership
const PluralRules* rules = nullptr; // no ownership
int32_t threshold = kInternalDefaultThreshold;
Locale locale;
// NOTE: Uses default copy and move constructors.
bool copyErrorTo(UErrorCode &status) const {
return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
unitDisplayCase.copyErrorTo(status);
}
};
} // namespace impl
#if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
// Ignore MSVC warning 4661. This is generated for NumberFormatterSettings<>::toSkeleton() as this method
// is defined elsewhere (in number_skeletons.cpp). The compiler is warning that the explicit template instantiation
// inside this single translation unit (CPP file) is incomplete, and thus it isn't sure if the template class is
// fully defined. However, since each translation unit explicitly instantiates all the necessary template classes,
// they will all be passed to the linker, and the linker will still find and export all the class members.
#pragma warning(push)
#pragma warning(disable: 4661)
#endif
template<typename Derived>
class U_I18N_API NumberFormatterSettings {
public:
Derived notation(const Notation &notation) const &;
Derived notation(const Notation &notation) &&;
Derived unit(const icu::MeasureUnit &unit) const &;
Derived unit(const icu::MeasureUnit &unit) &&;
Derived adoptUnit(icu::MeasureUnit *unit) const &;
Derived adoptUnit(icu::MeasureUnit *unit) &&;
Derived perUnit(const icu::MeasureUnit &perUnit) const &;
Derived perUnit(const icu::MeasureUnit &perUnit) &&;
Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
Derived precision(const Precision& precision) const &;
Derived precision(const Precision& precision) &&;
Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
Derived grouping(UNumberGroupingStrategy strategy) const &;
Derived grouping(UNumberGroupingStrategy strategy) &&;
Derived integerWidth(const IntegerWidth &style) const &;
Derived integerWidth(const IntegerWidth &style) &&;
Derived symbols(const DecimalFormatSymbols &symbols) const &;
Derived symbols(const DecimalFormatSymbols &symbols) &&;
Derived adoptSymbols(NumberingSystem *symbols) const &;
Derived adoptSymbols(NumberingSystem *symbols) &&;
Derived unitWidth(UNumberUnitWidth width) const &;
Derived unitWidth(UNumberUnitWidth width) &&;
Derived sign(UNumberSignDisplay style) const &;
Derived sign(UNumberSignDisplay style) &&;
Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
Derived decimal(UNumberDecimalSeparatorDisplay style) &&;
Derived scale(const Scale &scale) const &;
Derived scale(const Scale &scale) &&;
Derived usage(StringPiece usage) const &;
Derived usage(StringPiece usage) &&;
Derived displayOptions(const DisplayOptions &displayOptions) const &;
Derived displayOptions(const DisplayOptions &displayOptions) &&;
#ifndef U_HIDE_INTERNAL_API
Derived unitDisplayCase(StringPiece unitDisplayCase) const &;
Derived unitDisplayCase(StringPiece unitDisplayCase) &&;
#endif // U_HIDE_INTERNAL_API
#ifndef U_HIDE_INTERNAL_API
Derived padding(const impl::Padder &padder) const &;
Derived padding(const impl::Padder &padder) &&;
Derived threshold(int32_t threshold) const &;
Derived threshold(int32_t threshold) &&;
Derived macros(const impl::MacroProps& macros) const &;
Derived macros(const impl::MacroProps& macros) &&;
Derived macros(impl::MacroProps&& macros) const &;
Derived macros(impl::MacroProps&& macros) &&;
#endif /* U_HIDE_INTERNAL_API */
UnicodeString toSkeleton(UErrorCode& status) const;
LocalPointer<Derived> clone() const &;
LocalPointer<Derived> clone() &&;
UBool copyErrorTo(UErrorCode &outErrorCode) const {
if (U_FAILURE(outErrorCode)) {
// Do not overwrite the older error code
return true;
}
fMacros.copyErrorTo(outErrorCode);
return U_FAILURE(outErrorCode);
}
// NOTE: Uses default copy and move constructors.
private:
impl::MacroProps fMacros;
// Don't construct me directly! Use (Un)LocalizedNumberFormatter.
NumberFormatterSettings() = default;
friend class LocalizedNumberFormatter;
friend class UnlocalizedNumberFormatter;
// Give NumberRangeFormatter access to the MacroProps
friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
friend class impl::NumberRangeFormatterImpl;
};
// Explicit instantiations in source/i18n/number_fluent.cpp.
// (MSVC treats imports/exports of explicit instantiations differently.)
#ifndef _MSC_VER
extern template class NumberFormatterSettings<UnlocalizedNumberFormatter>;
extern template class NumberFormatterSettings<LocalizedNumberFormatter>;
#endif
class U_I18N_API UnlocalizedNumberFormatter
: public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
public:
LocalizedNumberFormatter locale(const icu::Locale &locale) const &;
LocalizedNumberFormatter locale(const icu::Locale &locale) &&;
UnlocalizedNumberFormatter() = default;
UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other);
UnlocalizedNumberFormatter(UnlocalizedNumberFormatter&& src) noexcept;
UnlocalizedNumberFormatter& operator=(const UnlocalizedNumberFormatter& other);
UnlocalizedNumberFormatter& operator=(UnlocalizedNumberFormatter&& src) noexcept;
private:
explicit UnlocalizedNumberFormatter(const NumberFormatterSettings<UnlocalizedNumberFormatter>& other);
explicit UnlocalizedNumberFormatter(
NumberFormatterSettings<UnlocalizedNumberFormatter>&& src) noexcept;
explicit UnlocalizedNumberFormatter(const impl::MacroProps &macros);
explicit UnlocalizedNumberFormatter(impl::MacroProps &&macros);
// To give the fluent setters access to this class's constructor:
friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
// To give NumberFormatter::with() access to this class's constructor:
friend class NumberFormatter;
// To give LNF::withoutLocale() access to this class's constructor:
friend class LocalizedNumberFormatter;
};
class U_I18N_API LocalizedNumberFormatter
: public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
public:
FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
FormattedNumber formatDouble(double value, UErrorCode &status) const;
FormattedNumber formatDecimal(StringPiece value, UErrorCode& status) const;
#ifndef U_HIDE_INTERNAL_API
const DecimalFormatSymbols* getDecimalFormatSymbols() const;
FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
const impl::NumberFormatterImpl* getCompiled() const;
int32_t getCallCount() const;
#endif /* U_HIDE_INTERNAL_API */
Format* toFormat(UErrorCode& status) const;
#ifndef U_HIDE_DRAFT_API
UnlocalizedNumberFormatter withoutLocale() const &;
UnlocalizedNumberFormatter withoutLocale() &&;
#endif // U_HIDE_DRAFT_API
LocalizedNumberFormatter() = default;
LocalizedNumberFormatter(const LocalizedNumberFormatter &other);
LocalizedNumberFormatter(LocalizedNumberFormatter&& src) noexcept;
LocalizedNumberFormatter& operator=(const LocalizedNumberFormatter& other);
LocalizedNumberFormatter& operator=(LocalizedNumberFormatter&& src) noexcept;
#ifndef U_HIDE_INTERNAL_API
void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
#endif /* U_HIDE_INTERNAL_API */
~LocalizedNumberFormatter();
private:
// Note: fCompiled can't be a LocalPointer because impl::NumberFormatterImpl is defined in an internal
// header, and LocalPointer needs the full class definition in order to delete the instance.
const impl::NumberFormatterImpl* fCompiled {nullptr};
char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t
// Owned pointer to a DecimalFormatWarehouse, used when copying a LocalizedNumberFormatter
// from a DecimalFormat.
const impl::DecimalFormatWarehouse* fWarehouse {nullptr};
explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) noexcept;
LocalizedNumberFormatter(const impl::MacroProps &macros, const Locale &locale);
LocalizedNumberFormatter(impl::MacroProps &&macros, const Locale &locale);
void resetCompiled();
void lnfMoveHelper(LocalizedNumberFormatter&& src);
void lnfCopyHelper(const LocalizedNumberFormatter& src, UErrorCode& status);
bool computeCompiled(UErrorCode& status) const;
// To give the fluent setters access to this class's constructor:
friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
friend class NumberFormatterSettings<LocalizedNumberFormatter>;
// To give UnlocalizedNumberFormatter::locale() access to this class's constructor:
friend class UnlocalizedNumberFormatter;
};
#if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
// Warning 4661.
#pragma warning(pop)
#endif
class U_I18N_API NumberFormatter final {
public:
static UnlocalizedNumberFormatter with();
static LocalizedNumberFormatter withLocale(const Locale &locale);
static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton, UErrorCode& status);
static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton,
UParseError& perror, UErrorCode& status);
NumberFormatter() = delete;
};
} // namespace number
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __NUMBERFORMATTER_H__
appendable.h
C++ API: Appendable class: Sink for Unicode code points and 16-bit code units (char16_ts).
bytestream.h
C++ API: Interface for writing bytes, and implementation classes.
icu::CurrencyUnit
A unit of currency, such as USD (U.S.
Definition: currunit.h:39
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:86
icu::DisplayOptions
Represents all the display options that are supported by CLDR such as grammatical case,...
Definition: displayoptions.h:43
icu::Format
Base class for all formats.
Definition: format.h:98
icu::LocalPointer
"Smart pointer" class, deletes objects via the standard C++ delete operator.
Definition: localpointer.h:191
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::MeasureUnit
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:409
icu::NumberingSystem
Defines numbering systems.
Definition: numsys.h:60
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:212
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::number::CurrencyPrecision
A class that defines a rounding precision parameterized by a currency to be used when formatting numb...
Definition: numberformatter.h:915
icu::number::CurrencyPrecision::withCurrency
Precision withCurrency(const CurrencyUnit &currency) const
Associates a currency with this rounding precision.
icu::number::FormattedNumber
The result of a number formatting operation.
Definition: formattednumber.h:48
icu::number::FractionPrecision
A class that defines a rounding precision based on a number of fraction places and optionally signifi...
Definition: numberformatter.h:839
icu::number::FractionPrecision::withMinDigits
Precision withMinDigits(int32_t minSignificantDigits) const
Ensure that no less than this number of significant digits are retained when rounding according to fr...
icu::number::FractionPrecision::withSignificantDigits
Precision withSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits, UNumberRoundingPriority priority) const
Override maximum fraction digits with maximum significant digits depending on the magnitude of the nu...
icu::number::FractionPrecision::withMaxDigits
Precision withMaxDigits(int32_t maxSignificantDigits) const
Ensure that no more than this number of significant digits are retained when rounding according to fr...
icu::number::IncrementPrecision
A class that defines a rounding precision parameterized by a rounding increment to be used when forma...
Definition: numberformatter.h:953
icu::number::IncrementPrecision::withMinFraction
Precision withMinFraction(int32_t minFrac) const
Specifies the minimum number of fraction digits to render after the decimal separator,...
icu::number::IntegerWidth
A class that defines the strategy for padding and truncating integers before the decimal separator.
Definition: numberformatter.h:989
icu::number::IntegerWidth::zeroFillTo
static IntegerWidth zeroFillTo(int32_t minInt)
Pad numbers at the beginning with zeros to guarantee a certain number of numerals before the decimal ...
icu::number::IntegerWidth::truncateAt
IntegerWidth truncateAt(int32_t maxInt)
Truncate numbers exceeding a certain number of numerals before the decimal separator.
icu::number::LocalizedNumberFormatter
A NumberFormatter that has a locale associated with it; this means .format() methods are available.
Definition: numberformatter.h:2521
icu::number::LocalizedNumberFormatter::getDecimalFormatSymbols
const DecimalFormatSymbols * getDecimalFormatSymbols() const
icu::number::LocalizedNumberFormatter::getCompiled
const impl::NumberFormatterImpl * getCompiled() const
Internal method for testing.
icu::number::LocalizedNumberFormatter::operator=
LocalizedNumberFormatter & operator=(const LocalizedNumberFormatter &other)
Copy assignment operator.
icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter
LocalizedNumberFormatter(LocalizedNumberFormatter &&src) noexcept
Move constructor: The source LocalizedNumberFormatter will be left in a valid but undefined state.
icu::number::LocalizedNumberFormatter::operator=
LocalizedNumberFormatter & operator=(LocalizedNumberFormatter &&src) noexcept
Move assignment operator: The source LocalizedNumberFormatter will be left in a valid but undefined s...
icu::number::LocalizedNumberFormatter::withoutLocale
UnlocalizedNumberFormatter withoutLocale() const &
Disassociate the locale from this formatter.
icu::number::LocalizedNumberFormatter::formatInt
FormattedNumber formatInt(int64_t value, UErrorCode &status) const
Format the given integer number to a string using the settings specified in the NumberFormatter fluen...
icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter
LocalizedNumberFormatter()=default
Default constructor: puts the formatter into a valid but undefined state.
icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter
LocalizedNumberFormatter(const LocalizedNumberFormatter &other)
Returns a copy of this LocalizedNumberFormatter.
icu::number::LocalizedNumberFormatter::getCallCount
int32_t getCallCount() const
Internal method for testing.
icu::number::LocalizedNumberFormatter::~LocalizedNumberFormatter
~LocalizedNumberFormatter()
Destruct this LocalizedNumberFormatter, cleaning up any memory it might own.
icu::number::LocalizedNumberFormatter::toFormat
Format * toFormat(UErrorCode &status) const
Creates a representation of this LocalizedNumberFormat as an icu::Format, enabling the use of this nu...
icu::number::LocalizedNumberFormatter::formatImpl
void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const
This is the core entrypoint to the number formatting pipeline.
icu::number::LocalizedNumberFormatter::formatDecimal
FormattedNumber formatDecimal(StringPiece value, UErrorCode &status) const
Format the given decimal number to a string using the settings specified in the NumberFormatter fluen...
icu::number::LocalizedNumberFormatter::getAffixImpl
void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString &result, UErrorCode &status) const
Internal method for DecimalFormat compatibility.
icu::number::LocalizedNumberFormatter::formatDecimalQuantity
FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity &dq, UErrorCode &status) const
Internal method.
icu::number::LocalizedNumberFormatter::formatDouble
FormattedNumber formatDouble(double value, UErrorCode &status) const
Format the given float or double to a string using the settings specified in the NumberFormatter flue...
icu::number::Notation
A class that defines the notation style to be used when formatting numbers in NumberFormatter.
Definition: numberformatter.h:203
icu::number::Notation::compactShort
static CompactNotation compactShort()
Print the number using short-form compact notation.
icu::number::Notation::engineering
static ScientificNotation engineering()
Print the number using engineering notation, a variant of scientific notation in which the exponent m...
icu::number::Notation::compactLong
static CompactNotation compactLong()
Print the number using long-form compact notation.
icu::number::Notation::simple
static SimpleNotation simple()
Print the number using simple notation without any scaling by powers of ten.
icu::number::Notation::scientific
static ScientificNotation scientific()
Print the number using scientific notation (also known as scientific form, standard index form,...
icu::number::NumberFormatterSettings
An abstract base class for specifying settings related to number formatting.
Definition: numberformatter.h:1617
icu::number::NumberFormatterSettings::unitDisplayCase
Derived unitDisplayCase(StringPiece unitDisplayCase) &&
NOTE: Use displayOptions instead.
icu::number::NumberFormatterSettings::adoptSymbols
Derived adoptSymbols(NumberingSystem *symbols) const &
Specifies that the given numbering system should be used when fetching symbols.
icu::number::NumberFormatterSettings::precision
Derived precision(const Precision &precision) const &
Specifies the rounding precision to use when formatting numbers.
icu::number::NumberFormatterSettings::decimal
Derived decimal(UNumberDecimalSeparatorDisplay style) &&
Overload of decimal() for use on an rvalue reference.
icu::number::NumberFormatterSettings::unitWidth
Derived unitWidth(UNumberUnitWidth width) const &
Sets the width of the unit (measure unit or currency).
icu::number::NumberFormatterSettings::adoptUnit
Derived adoptUnit(icu::MeasureUnit *unit) const &
Like unit(), but takes ownership of a pointer.
icu::number::NumberFormatterSettings::perUnit
Derived perUnit(const icu::MeasureUnit &perUnit) &&
Overload of perUnit() for use on an rvalue reference.
icu::number::NumberFormatterSettings::padding
Derived padding(const impl::Padder &padder) &&
icu::number::NumberFormatterSettings::adoptSymbols
Derived adoptSymbols(NumberingSystem *symbols) &&
Overload of adoptSymbols() for use on an rvalue reference.
icu::number::NumberFormatterSettings::macros
Derived macros(const impl::MacroProps &macros) &&
icu::number::NumberFormatterSettings::roundingMode
Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&
Overload of roundingMode() for use on an rvalue reference.
icu::number::NumberFormatterSettings::integerWidth
Derived integerWidth(const IntegerWidth &style) const &
Specifies the minimum and maximum number of digits to render before the decimal mark.
icu::number::NumberFormatterSettings::macros
Derived macros(const impl::MacroProps &macros) const &
Internal fluent setter to overwrite the entire macros object.
icu::number::NumberFormatterSettings::threshold
Derived threshold(int32_t threshold) const &
Internal fluent setter to support a custom regulation threshold.
icu::number::NumberFormatterSettings::perUnit
Derived perUnit(const icu::MeasureUnit &perUnit) const &
Sets a unit to be used in the denominator.
icu::number::NumberFormatterSettings::integerWidth
Derived integerWidth(const IntegerWidth &style) &&
Overload of integerWidth() for use on an rvalue reference.
icu::number::NumberFormatterSettings::unitDisplayCase
Derived unitDisplayCase(StringPiece unitDisplayCase) const &
NOTE: Use displayOptions instead.
icu::number::NumberFormatterSettings::grouping
Derived grouping(UNumberGroupingStrategy strategy) const &
Specifies the grouping strategy to use when formatting numbers.
icu::number::NumberFormatterSettings::unit
Derived unit(const icu::MeasureUnit &unit) const &
Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
icu::number::NumberFormatterSettings::displayOptions
Derived displayOptions(const DisplayOptions &displayOptions) const &
Specifies the DisplayOptions.
icu::number::NumberFormatterSettings::usage
Derived usage(StringPiece usage) &&
Overload of usage() for use on an rvalue reference.
icu::number::NumberFormatterSettings::displayOptions
Derived displayOptions(const DisplayOptions &displayOptions) &&
Overload of displayOptions() for use on an rvalue reference.
icu::number::NumberFormatterSettings::adoptPerUnit
Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &
Like perUnit(), but takes ownership of a pointer.
icu::number::NumberFormatterSettings::adoptUnit
Derived adoptUnit(icu::MeasureUnit *unit) &&
Overload of adoptUnit() for use on an rvalue reference.
icu::number::NumberFormatterSettings::scale
Derived scale(const Scale &scale) &&
Overload of scale() for use on an rvalue reference.
icu::number::NumberFormatterSettings::precision
Derived precision(const Precision &precision) &&
Overload of precision() for use on an rvalue reference.
icu::number::NumberFormatterSettings::symbols
Derived symbols(const DecimalFormatSymbols &symbols) &&
Overload of symbols() for use on an rvalue reference.
icu::number::NumberFormatterSettings::padding
Derived padding(const impl::Padder &padder) const &
Set the padding strategy.
icu::number::NumberFormatterSettings::notation
Derived notation(const Notation &notation) const &
Specifies the notation style (simple, scientific, or compact) for rendering numbers.
icu::number::NumberFormatterSettings::sign
Derived sign(UNumberSignDisplay style) const &
Sets the plus/minus sign display strategy.
icu::number::NumberFormatterSettings::threshold
Derived threshold(int32_t threshold) &&
icu::number::NumberFormatterSettings::roundingMode
Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &
Specifies how to determine the direction to round a number when it has more digits than fit in the de...
icu::number::NumberFormatterSettings::symbols
Derived symbols(const DecimalFormatSymbols &symbols) const &
Specifies the symbols (decimal separator, grouping separator, percent sign, numerals,...
icu::number::NumberFormatterSettings::macros
Derived macros(impl::MacroProps &&macros) &&
icu::number::NumberFormatterSettings::clone
LocalPointer< Derived > clone() const &
Returns the current (Un)LocalizedNumberFormatter as a LocalPointer wrapping a heap-allocated copy of ...
icu::number::NumberFormatterSettings::sign
Derived sign(UNumberSignDisplay style) &&
Overload of sign() for use on an rvalue reference.
icu::number::NumberFormatterSettings::toSkeleton
UnicodeString toSkeleton(UErrorCode &status) const
Creates a skeleton string representation of this number formatter.
icu::number::NumberFormatterSettings::grouping
Derived grouping(UNumberGroupingStrategy strategy) &&
Overload of grouping() for use on an rvalue reference.
icu::number::NumberFormatterSettings::usage
Derived usage(StringPiece usage) const &
Specifies the usage for which numbers will be formatted ("person-height", "road", "rainfall",...
icu::number::NumberFormatterSettings::adoptPerUnit
Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&
Overload of adoptPerUnit() for use on an rvalue reference.
icu::number::NumberFormatterSettings::unitWidth
Derived unitWidth(UNumberUnitWidth width) &&
Overload of unitWidth() for use on an rvalue reference.
icu::number::NumberFormatterSettings::decimal
Derived decimal(UNumberDecimalSeparatorDisplay style) const &
Sets the decimal separator display strategy.
icu::number::NumberFormatterSettings::unit
Derived unit(const icu::MeasureUnit &unit) &&
Overload of unit() for use on an rvalue reference.
icu::number::NumberFormatterSettings::macros
Derived macros(impl::MacroProps &&macros) const &
icu::number::NumberFormatterSettings::scale
Derived scale(const Scale &scale) const &
Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting.
icu::number::NumberFormatterSettings::notation
Derived notation(const Notation &notation) &&
Overload of notation() for use on an rvalue reference.
icu::number::NumberFormatter
See the main description in numberformatter.h for documentation and examples.
Definition: numberformatter.h:2735
icu::number::NumberFormatter::forSkeleton
static UnlocalizedNumberFormatter forSkeleton(const UnicodeString &skeleton, UParseError &perror, UErrorCode &status)
Call this method at the beginning of a NumberFormatter fluent chain to create an instance based on a ...
icu::number::NumberFormatter::forSkeleton
static UnlocalizedNumberFormatter forSkeleton(const UnicodeString &skeleton, UErrorCode &status)
Call this method at the beginning of a NumberFormatter fluent chain to create an instance based on a ...
icu::number::NumberFormatter::with
static UnlocalizedNumberFormatter with()
Call this method at the beginning of a NumberFormatter fluent chain in which the locale is not curren...
icu::number::NumberFormatter::NumberFormatter
NumberFormatter()=delete
Use factory methods instead of the constructor to create a NumberFormatter.
icu::number::NumberFormatter::withLocale
static LocalizedNumberFormatter withLocale(const Locale &locale)
Call this method at the beginning of a NumberFormatter fluent chain in which the locale is known at t...
icu::number::Precision
A class that defines the rounding precision to be used when formatting numbers in NumberFormatter.
Definition: numberformatter.h:474
icu::number::Precision::maxSignificantDigits
static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures.
icu::number::Precision::fixedFraction
static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
icu::number::Precision::minSignificantDigits
static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits)
Always show at least a certain number of significant digits/figures, padding with zeros if necessary.
icu::number::Precision::maxFraction
static FractionPrecision maxFraction(int32_t maxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
icu::number::Precision::increment
static IncrementPrecision increment(double roundingIncrement)
Show numbers rounded if necessary to the closest multiple of a certain rounding increment.
icu::number::Precision::currency
static CurrencyPrecision currency(UCurrencyUsage currencyUsage)
Show numbers rounded and padded according to the rules for the currency unit.
icu::number::Precision::minFraction
static FractionPrecision minFraction(int32_t minFractionPlaces)
Always show at least a certain number of fraction places after the decimal separator,...
icu::number::Precision::trailingZeroDisplay
Precision trailingZeroDisplay(UNumberTrailingZeroDisplay trailingZeroDisplay) const
Configure how trailing zeros are displayed on numbers.
icu::number::Precision::unlimited
static Precision unlimited()
Show all available digits to full precision.
icu::number::Precision::integer
static FractionPrecision integer()
Show numbers rounded if necessary to the nearest integer.
icu::number::Precision::fixedSignificantDigits
static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits or significant figures.
icu::number::Precision::incrementExact
static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude)
Version of Precision::increment() that takes an integer at a particular power of 10.
icu::number::Precision::minMaxFraction
static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
icu::number::Precision::minMaxSignificantDigits
static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures; in addition,...
icu::number::Scale
A class that defines a quantity by which a number should be multiplied when formatting.
Definition: numberformatter.h:1086
icu::number::Scale::none
static Scale none()
Do not change the value of numbers when formatting or parsing.
icu::number::Scale::operator=
Scale & operator=(const Scale &other)
icu::number::Scale::powerOfTen
static Scale powerOfTen(int32_t power)
Multiply numbers by a power of ten before formatting.
icu::number::Scale::Scale
Scale(const Scale &other)
icu::number::Scale::byDoubleAndPowerOfTen
static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power)
Multiply a number by both a power of ten and by an arbitrary double value.
icu::number::Scale::byDecimal
static Scale byDecimal(StringPiece multiplicand)
Multiply numbers by an arbitrary value before formatting.
icu::number::Scale::Scale
Scale(int32_t magnitude, impl::DecNum *arbitraryToAdopt)
icu::number::Scale::Scale
Scale(Scale &&src) noexcept
icu::number::Scale::~Scale
~Scale()
icu::number::Scale::byDouble
static Scale byDouble(double multiplicand)
Multiply numbers by an arbitrary value before formatting.
icu::number::Scale::operator=
Scale & operator=(Scale &&src) noexcept
icu::number::ScientificNotation
A class that defines the scientific notation style to be used when formatting numbers in NumberFormat...
Definition: numberformatter.h:413
icu::number::ScientificNotation::withExponentSignDisplay
ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const
Sets whether to show the sign on positive and negative exponents in scientific notation.
icu::number::ScientificNotation::withMinExponentDigits
ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const
Sets the minimum number of digits to show in the exponent of scientific notation, padding with zeros ...
icu::number::UnlocalizedNumberFormatter
A NumberFormatter that does not yet have a locale.
Definition: numberformatter.h:2434
icu::number::UnlocalizedNumberFormatter::UnlocalizedNumberFormatter
UnlocalizedNumberFormatter()=default
Default constructor: puts the formatter into a valid but undefined state.
icu::number::UnlocalizedNumberFormatter::operator=
UnlocalizedNumberFormatter & operator=(const UnlocalizedNumberFormatter &other)
Copy assignment operator.
icu::number::UnlocalizedNumberFormatter::UnlocalizedNumberFormatter
UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other)
Returns a copy of this UnlocalizedNumberFormatter.
icu::number::UnlocalizedNumberFormatter::locale
LocalizedNumberFormatter locale(const icu::Locale &locale) &&
Overload of locale() for use on an rvalue reference.
icu::number::UnlocalizedNumberFormatter::UnlocalizedNumberFormatter
UnlocalizedNumberFormatter(UnlocalizedNumberFormatter &&src) noexcept
Move constructor: The source UnlocalizedNumberFormatter will be left in a valid but undefined state.
icu::number::UnlocalizedNumberFormatter::operator=
UnlocalizedNumberFormatter & operator=(UnlocalizedNumberFormatter &&src) noexcept
Move assignment operator: The source UnlocalizedNumberFormatter will be left in a valid but undefined...
icu::number::UnlocalizedNumberFormatter::locale
LocalizedNumberFormatter locale(const icu::Locale &locale) const &
Associate the given locale with the number formatter.
icu::number::impl::Grouper
Definition: numberformatter.h:1372
icu::number::impl::Grouper::forStrategy
static Grouper forStrategy(UNumberGroupingStrategy grouping)
icu::number::impl::Grouper::Grouper
Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
Definition: numberformatter.h:1387
icu::number::impl::Grouper::getSecondary
int16_t getSecondary() const
icu::number::impl::Grouper::forProperties
static Grouper forProperties(const DecimalFormatProperties &properties)
Resolve the values in Properties to a Grouper object.
icu::number::impl::Grouper::getPrimary
int16_t getPrimary() const
icu::number::impl::Padder
Definition: numberformatter.h:1456
icu::number::impl::Padder::forProperties
static Padder forProperties(const DecimalFormatProperties &properties)
icu::number::impl::Padder::codePoints
static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position)
icu::number::impl::Padder::none
static Padder none()
icu::number::impl::StringProp
Manages NumberFormatterSettings::usage()'s char* instance on the heap.
Definition: numberformatter.h:1214
icu::number::impl::StringProp::StringProp
StringProp(StringProp &&src) noexcept
icu::number::impl::StringProp::StringProp
StringProp(const StringProp &other)
icu::number::impl::StringProp::length
int16_t length() const
Definition: numberformatter.h:1235
icu::number::impl::StringProp::isSet
bool isSet() const
Definition: numberformatter.h:1245
icu::number::impl::StringProp::~StringProp
~StringProp()
icu::number::impl::StringProp::operator=
StringProp & operator=(StringProp &&src) noexcept
icu::number::impl::StringProp::operator=
StringProp & operator=(const StringProp &other)
icu::number::impl::StringProp::set
void set(StringPiece value)
icu::number::impl::SymbolsWrapper
Definition: numberformatter.h:1281
icu::number::impl::SymbolsWrapper::SymbolsWrapper
SymbolsWrapper()
Definition: numberformatter.h:1284
icu::number::impl::SymbolsWrapper::operator=
SymbolsWrapper & operator=(const SymbolsWrapper &other)
icu::number::impl::SymbolsWrapper::getNumberingSystem
const NumberingSystem * getNumberingSystem() const
Get the NumberingSystem pointer.
icu::number::impl::SymbolsWrapper::isNumberingSystem
bool isNumberingSystem() const
Whether the object is currently holding a NumberingSystem.
icu::number::impl::SymbolsWrapper::getDecimalFormatSymbols
const DecimalFormatSymbols * getDecimalFormatSymbols() const
Get the DecimalFormatSymbols pointer.
icu::number::impl::SymbolsWrapper::~SymbolsWrapper
~SymbolsWrapper()
icu::number::impl::SymbolsWrapper::SymbolsWrapper
SymbolsWrapper(const SymbolsWrapper &other)
icu::number::impl::SymbolsWrapper::SymbolsWrapper
SymbolsWrapper(SymbolsWrapper &&src) noexcept
icu::number::impl::SymbolsWrapper::setTo
void setTo(const DecimalFormatSymbols &dfs)
The provided object is copied, but we do not adopt it.
icu::number::impl::SymbolsWrapper::operator=
SymbolsWrapper & operator=(SymbolsWrapper &&src) noexcept
icu::number::impl::SymbolsWrapper::setTo
void setTo(const NumberingSystem *ns)
Adopt the provided object.
icu::number::impl::SymbolsWrapper::copyErrorTo
UBool copyErrorTo(UErrorCode &status) const
Definition: numberformatter.h:1342
icu::number::impl::SymbolsWrapper::isDecimalFormatSymbols
bool isDecimalFormatSymbols() const
Whether the object is currently holding a DecimalFormatSymbols.
currunit.h
C++ API: Currency Unit Information.
dcfmtsym.h
C++ API: Symbols for formatting numbers.
displayoptions.h
C++ API: Display options class.
fieldpos.h
C++ API: FieldPosition identifies the fields in a formatted output.
formattednumber.h
C API: Formatted number result from various number formatting functions.
fpositer.h
C++ API: FieldPosition Iterator.
measunit.h
C++ API: A unit for measuring a quantity.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
nounit.h
C++ API: units for percent and permille.
icu::number::impl::digits_t
int16_t digits_t
Datatype for minimum/maximum fraction digits.
Definition: numberformatter.h:134
icu::number::impl::touchRangeLocales
void touchRangeLocales(impl::RangeMacroProps &macros)
Used for NumberRangeFormatter and implemented in numrange_fluent.cpp.
parseerr.h
C API: Parse Error Information.
plurrule.h
C++ API: PluralRules object.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
icu::number::Notation::NotationUnion::ScientificSettings
Definition: numberformatter.h:356
icu::number::Notation::NotationUnion::ScientificSettings::fRequireMinInt
bool fRequireMinInt
Definition: numberformatter.h:360
icu::number::Notation::NotationUnion::ScientificSettings::fMinExponentDigits
impl::digits_t fMinExponentDigits
Definition: numberformatter.h:362
icu::number::Notation::NotationUnion::ScientificSettings::fExponentSignDisplay
UNumberSignDisplay fExponentSignDisplay
Definition: numberformatter.h:364
icu::number::Notation::NotationUnion::ScientificSettings::fEngineeringInterval
int8_t fEngineeringInterval
Definition: numberformatter.h:358
icu::number::Precision::PrecisionUnion::FractionSignificantSettings
Definition: numberformatter.h:727
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fMinFrac
impl::digits_t fMinFrac
Definition: numberformatter.h:730
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fRetain
bool fRetain
Whether to retain trailing zeros based on the looser strategy.
Definition: numberformatter.h:743
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fMaxSig
impl::digits_t fMaxSig
Definition: numberformatter.h:736
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fPriority
UNumberRoundingPriority fPriority
Definition: numberformatter.h:738
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fMaxFrac
impl::digits_t fMaxFrac
Definition: numberformatter.h:732
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fMinSig
impl::digits_t fMinSig
Definition: numberformatter.h:734
icu::number::Precision::PrecisionUnion::IncrementSettings
Definition: numberformatter.h:746
icu::number::Precision::PrecisionUnion::IncrementSettings::fIncrementMagnitude
impl::digits_t fIncrementMagnitude
Definition: numberformatter.h:753
icu::number::Precision::PrecisionUnion::IncrementSettings::fIncrement
uint64_t fIncrement
Definition: numberformatter.h:751
icu::number::Precision::PrecisionUnion::IncrementSettings::fMinFrac
impl::digits_t fMinFrac
Definition: numberformatter.h:755
icu::number::impl::MacroProps
Definition: numberformatter.h:1522
icu::number::impl::MacroProps::perUnit
MeasureUnit perUnit
Definition: numberformatter.h:1530
icu::number::impl::MacroProps::scale
Scale scale
Definition: numberformatter.h:1565
icu::number::impl::MacroProps::copyErrorTo
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
Definition: numberformatter.h:1591
icu::number::impl::MacroProps::usage
StringProp usage
Definition: numberformatter.h:1568
icu::number::impl::MacroProps::unitDisplayCase
StringProp unitDisplayCase
Definition: numberformatter.h:1571
icu::number::impl::MacroProps::locale
Locale locale
Definition: numberformatter.h:1583
icu::number::impl::MacroProps::precision
Precision precision
Definition: numberformatter.h:1533
icu::number::impl::MacroProps::integerWidth
IntegerWidth integerWidth
Definition: numberformatter.h:1545
icu::number::impl::MacroProps::padder
Padder padder
Definition: numberformatter.h:1542
icu::number::impl::MacroProps::grouper
Grouper grouper
Definition: numberformatter.h:1539
icu::number::impl::MacroProps::unit
MeasureUnit unit
Definition: numberformatter.h:1527
icu::number::impl::MacroProps::notation
Notation notation
Definition: numberformatter.h:1524
icu::number::impl::MacroProps::symbols
SymbolsWrapper symbols
Definition: numberformatter.h:1548
icu::number::impl::RangeMacroProps
Definition: numberrangeformatter.h:93
ucurr.h
C API: Encapsulates information about a currency.
UCurrencyUsage
UCurrencyUsage
Currency Usage used for Decimal Format.
Definition: ucurr.h:41
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:427
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
unum.h
C API: Compatibility APIs for number formatting.
UNumberCompactStyle
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:289
UNumberFormatPadPosition
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:278
unumberformatter.h
C API: Localized number formatting; not recommended for C++.
UNumberRoundingPriority
UNumberRoundingPriority
An enum declaring how to resolve conflicts between maximum fraction digits and maximum significant di...
Definition: unumberformatter.h:118
UNumberSignDisplay
UNumberSignDisplay
An enum declaring how to denote positive and negative numbers.
Definition: unumberformatter.h:264
UNUM_SIGN_COUNT
@ UNUM_SIGN_COUNT
One more than the highest UNumberSignDisplay value.
Definition: unumberformatter.h:355
UNumberDecimalSeparatorDisplay
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
Definition: unumberformatter.h:369
UNUM_DECIMAL_SEPARATOR_COUNT
@ UNUM_DECIMAL_SEPARATOR_COUNT
One more than the highest UNumberDecimalSeparatorDisplay value.
Definition: unumberformatter.h:392
UNumberTrailingZeroDisplay
UNumberTrailingZeroDisplay
An enum declaring how to render trailing zeros.
Definition: unumberformatter.h:403
UNUM_TRAILING_ZERO_AUTO
@ UNUM_TRAILING_ZERO_AUTO
Display trailing zeros according to the settings for minimum fraction and significant digits.
Definition: unumberformatter.h:409
UNumberUnitWidth
UNumberUnitWidth
An enum declaring how to render units, including currencies.
Definition: unumberformatter.h:152
UNUM_UNIT_WIDTH_COUNT
@ UNUM_UNIT_WIDTH_COUNT
One more than the highest UNumberUnitWidth value.
Definition: unumberformatter.h:242
unumberoptions.h
C API: Header-only input options for various number formatting APIs.
UNumberFormatRoundingMode
UNumberFormatRoundingMode
The possible number format rounding modes.
Definition: unumberoptions.h:28
UNUM_ROUND_HALFEVEN
@ UNUM_ROUND_HALFEVEN
Half-even rounding.
Definition: unumberoptions.h:37
UNumberGroupingStrategy
UNumberGroupingStrategy
An enum declaring the strategy for when and how to display grouping separators (i....
Definition: unumberoptions.h:96
uobject.h
C++ API: Common ICU base class UObject.
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_MEMORY_ALLOCATION_ERROR
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition: utypes.h:458
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:450
U_FAILURE
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition: utypes.h:733
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