ICU 72.1 72.1
numberformatter.h
Go to the documentation of this file.
1// © 2017 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3
4#ifndef __NUMBERFORMATTER_H__
5#define __NUMBERFORMATTER_H__
6
7#include "unicode/utypes.h"
8
9#if U_SHOW_CPLUSPLUS_API
10
11#if !UCONFIG_NO_FORMATTING
12
13#include "unicode/appendable.h"
14#include "unicode/bytestream.h"
15#include "unicode/currunit.h"
16#include "unicode/dcfmtsym.h"
18#include "unicode/fieldpos.h"
20#include "unicode/fpositer.h"
21#include "unicode/measunit.h"
22#include "unicode/nounit.h"
23#include "unicode/parseerr.h"
24#include "unicode/plurrule.h"
25#include "unicode/ucurr.h"
27#include "unicode/unum.h"
29#include "unicode/uobject.h"
30
86U_NAMESPACE_BEGIN
87
88// Forward declarations:
89class IFixedDecimal;
90class FieldPositionIteratorHandler;
91class FormattedStringBuilder;
92
93namespace numparse {
94namespace impl {
95
96// Forward declarations:
97class NumberParserImpl;
98class MultiplierParseHandler;
99
100}
101}
102
103namespace units {
104
105// Forward declarations:
106class UnitsRouter;
107
108} // namespace units
109
110namespace number { // icu::number
111
112// Forward declarations:
113class UnlocalizedNumberFormatter;
114class LocalizedNumberFormatter;
115class FormattedNumber;
116class Notation;
117class ScientificNotation;
118class Precision;
119class FractionPrecision;
120class CurrencyPrecision;
121class IncrementPrecision;
122class IntegerWidth;
123
124namespace impl {
125
126// can't be #ifndef U_HIDE_INTERNAL_API; referenced throughout this file in public classes
132typedef int16_t digits_t;
133
134// can't be #ifndef U_HIDE_INTERNAL_API; needed for struct initialization
141static constexpr int32_t kInternalDefaultThreshold = 3;
142
143// Forward declarations:
144class Padder;
145struct MacroProps;
146struct MicroProps;
147class DecimalQuantity;
148class UFormattedNumberData;
149class NumberFormatterImpl;
150struct ParsedPatternInfo;
151class ScientificModifier;
152class MultiplierProducer;
153class RoundingImpl;
154class ScientificHandler;
155class Modifier;
156class AffixPatternProvider;
157class NumberPropertyMapper;
158struct DecimalFormatProperties;
159class MultiplierFormatHandler;
160class CurrencySymbols;
161class GeneratorHelpers;
162class DecNum;
163class NumberRangeFormatterImpl;
164struct RangeMacroProps;
165struct UFormattedNumberImpl;
166class MutablePatternModifier;
167class ImmutablePatternModifier;
168struct DecimalFormatWarehouse;
169
177
178} // namespace impl
179
186
193
200 public:
226
250
293
317
343
344 private:
345 enum NotationType {
346 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
347 } fType;
348
349 union NotationUnion {
350 // For NTN_SCIENTIFIC
361 } scientific;
362
363 // For NTN_COMPACT
364 UNumberCompactStyle compactStyle;
365
366 // For NTN_ERROR
367 UErrorCode errorCode;
368 } fUnion;
369
371
372 Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
373
374 Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
375 fUnion.errorCode = errorCode;
376 }
377
378 Notation() : fType(NTN_SIMPLE), fUnion() {}
379
380 UBool copyErrorTo(UErrorCode &status) const {
381 if (fType == NTN_ERROR) {
382 status = fUnion.errorCode;
383 return true;
384 }
385 return false;
386 }
387
388 // To allow MacroProps to initialize empty instances:
389 friend struct impl::MacroProps;
390 friend class ScientificNotation;
391
392 // To allow implementation to access internal types:
393 friend class impl::NumberFormatterImpl;
394 friend class impl::ScientificModifier;
395 friend class impl::ScientificHandler;
396
397 // To allow access to the skeleton generation code:
398 friend class impl::GeneratorHelpers;
399};
400
410 public:
424 ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
425
440
441 private:
442 // Inherit constructor
443 using Notation::Notation;
444
445 // Raw constructor for NumberPropertyMapper
446 ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
447 UNumberSignDisplay fExponentSignDisplay);
448
449 friend class Notation;
450
451 // So that NumberPropertyMapper can create instances
452 friend class impl::NumberPropertyMapper;
453};
454
461
471
472 public:
491
499
527 static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
528
542 static FractionPrecision minFraction(int32_t minFractionPlaces);
543
554 static FractionPrecision maxFraction(int32_t maxFractionPlaces);
555
569 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
570
584 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
585
598 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
599
608 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
609
621 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
622 int32_t maxSignificantDigits);
623
643 static IncrementPrecision increment(double roundingIncrement);
644
645#ifndef U_HIDE_DRAFT_API
669 static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude);
670#endif // U_HIDE_DRAFT_API
671
690
699
700 private:
701 enum PrecisionType {
702 RND_BOGUS,
703 RND_NONE,
704 RND_FRACTION,
705 RND_SIGNIFICANT,
706 RND_FRACTION_SIGNIFICANT,
707
708 // Used for strange increments like 3.14.
709 RND_INCREMENT,
710
711 // Used for increments with 1 as the only digit. This is different than fraction
712 // rounding because it supports having additional trailing zeros. For example, this
713 // class is used to round with the increment 0.010.
714 RND_INCREMENT_ONE,
715
716 // Used for increments with 5 as the only digit (nickel rounding).
717 RND_INCREMENT_FIVE,
718
719 RND_CURRENCY,
720 RND_ERROR
721 } fType;
722
723 union PrecisionUnion {
726 // For RND_FRACTION, RND_SIGNIFICANT, and RND_FRACTION_SIGNIFICANT
742 } fracSig;
745 // For RND_INCREMENT, RND_INCREMENT_ONE, and RND_INCREMENT_FIVE
746 // Note: This is a union, so we shouldn't own memory, since
747 // the default destructor would leak it.
749 uint64_t fIncrement;
754 } increment;
755 UCurrencyUsage currencyUsage; // For RND_CURRENCY
756 UErrorCode errorCode; // For RND_ERROR
757 } fUnion;
758
760
763
764 Precision(const PrecisionType& type, const PrecisionUnion& union_)
765 : fType(type), fUnion(union_) {}
766
767 Precision(UErrorCode errorCode) : fType(RND_ERROR) {
768 fUnion.errorCode = errorCode;
769 }
770
771 Precision() : fType(RND_BOGUS) {}
772
773 bool isBogus() const {
774 return fType == RND_BOGUS;
775 }
776
777 UBool copyErrorTo(UErrorCode &status) const {
778 if (fType == RND_ERROR) {
779 status = fUnion.errorCode;
780 return true;
781 }
782 return false;
783 }
784
785 // On the parent type so that this method can be called internally on Precision instances.
786 Precision withCurrency(const CurrencyUnit &currency, UErrorCode &status) const;
787
788 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
789
790 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
791
792 static Precision constructFractionSignificant(
793 const FractionPrecision &base,
794 int32_t minSig,
795 int32_t maxSig,
797 bool retain);
798
799 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
800
801 static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
802
803 // To allow MacroProps/MicroProps to initialize bogus instances:
804 friend struct impl::MacroProps;
805 friend struct impl::MicroProps;
806
807 // To allow NumberFormatterImpl to access isBogus() and other internal methods:
808 friend class impl::NumberFormatterImpl;
809
810 // To allow NumberPropertyMapper to create instances from DecimalFormatProperties:
811 friend class impl::NumberPropertyMapper;
812
813 // To allow access to the main implementation class:
814 friend class impl::RoundingImpl;
815
816 // To allow child classes to call private methods:
817 friend class FractionPrecision;
818 friend class CurrencyPrecision;
819 friend class IncrementPrecision;
820
821 // To allow access to the skeleton generation code:
822 friend class impl::GeneratorHelpers;
823
824 // To allow access to isBogus and the default (bogus) constructor:
825 friend class units::UnitsRouter;
826};
827
838 public:
854 int32_t minSignificantDigits,
855 int32_t maxSignificantDigits,
856 UNumberRoundingPriority priority) const;
857
875 Precision withMinDigits(int32_t minSignificantDigits) const;
876
894 Precision withMaxDigits(int32_t maxSignificantDigits) const;
895
896 private:
897 // Inherit constructor
898 using Precision::Precision;
899
900 // To allow parent class to call this class's constructor:
901 friend class Precision;
902};
903
914 public:
932 Precision withCurrency(const CurrencyUnit &currency) const;
933
934 private:
935 // Inherit constructor
936 using Precision::Precision;
937
938 // To allow parent class to call this class's constructor:
939 friend class Precision;
940};
941
952 public:
968 Precision withMinFraction(int32_t minFrac) const;
969
970 private:
971 // Inherit constructor
972 using Precision::Precision;
973
974 // To allow parent class to call this class's constructor:
975 friend class Precision;
976};
977
988 public:
1000 static IntegerWidth zeroFillTo(int32_t minInt);
1001
1013 IntegerWidth truncateAt(int32_t maxInt);
1014
1015 private:
1016 union {
1017 struct {
1018 impl::digits_t fMinInt;
1019 impl::digits_t fMaxInt;
1020 bool fFormatFailIfMoreThanMaxDigits;
1021 } minMaxInt;
1022 UErrorCode errorCode;
1023 } fUnion;
1024 bool fHasError = false;
1025
1026 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
1027
1028 IntegerWidth(UErrorCode errorCode) { // NOLINT
1029 fUnion.errorCode = errorCode;
1030 fHasError = true;
1031 }
1032
1033 IntegerWidth() { // NOLINT
1034 fUnion.minMaxInt.fMinInt = -1;
1035 }
1036
1038 static IntegerWidth standard() {
1039 return IntegerWidth::zeroFillTo(1);
1040 }
1041
1042 bool isBogus() const {
1043 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1044 }
1045
1046 UBool copyErrorTo(UErrorCode &status) const {
1047 if (fHasError) {
1048 status = fUnion.errorCode;
1049 return true;
1050 }
1051 return false;
1052 }
1053
1054 void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
1055
1056 bool operator==(const IntegerWidth& other) const;
1057
1058 // To allow MacroProps/MicroProps to initialize empty instances:
1059 friend struct impl::MacroProps;
1060 friend struct impl::MicroProps;
1061
1062 // To allow NumberFormatterImpl to access isBogus():
1063 friend class impl::NumberFormatterImpl;
1064
1065 // To allow the use of this class when formatting:
1066 friend class impl::MutablePatternModifier;
1067 friend class impl::ImmutablePatternModifier;
1068
1069 // So that NumberPropertyMapper can create instances
1070 friend class impl::NumberPropertyMapper;
1071
1072 // To allow access to the skeleton generation code:
1073 friend class impl::GeneratorHelpers;
1074};
1075
1084class U_I18N_API Scale : public UMemory {
1085 public:
1092 static Scale none();
1093
1104 static Scale powerOfTen(int32_t power);
1105
1118 static Scale byDecimal(StringPiece multiplicand);
1119
1128 static Scale byDouble(double multiplicand);
1129
1136 static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
1137
1138 // We need a custom destructor for the DecNum, which means we need to declare
1139 // the copy/move constructor/assignment quartet.
1140
1142 Scale(const Scale& other);
1143
1145 Scale& operator=(const Scale& other);
1146
1149
1152
1155
1156#ifndef U_HIDE_INTERNAL_API
1158 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1159#endif /* U_HIDE_INTERNAL_API */
1160
1161 private:
1162 int32_t fMagnitude;
1163 impl::DecNum* fArbitrary;
1164 UErrorCode fError;
1165
1166 Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
1167
1168 Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
1169
1170 bool isValid() const {
1171 return fMagnitude != 0 || fArbitrary != nullptr;
1172 }
1173
1174 UBool copyErrorTo(UErrorCode &status) const {
1175 if (U_FAILURE(fError)) {
1176 status = fError;
1177 return true;
1178 }
1179 return false;
1180 }
1181
1182 void applyTo(impl::DecimalQuantity& quantity) const;
1183
1184 void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
1185
1186 // To allow MacroProps/MicroProps to initialize empty instances:
1187 friend struct impl::MacroProps;
1188 friend struct impl::MicroProps;
1189
1190 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1191 friend class impl::NumberFormatterImpl;
1192
1193 // To allow the helper class MultiplierFormatHandler access to private fields:
1194 friend class impl::MultiplierFormatHandler;
1195
1196 // To allow access to the skeleton generation code:
1197 friend class impl::GeneratorHelpers;
1198
1199 // To allow access to parsing code:
1200 friend class ::icu::numparse::impl::NumberParserImpl;
1201 friend class ::icu::numparse::impl::MultiplierParseHandler;
1202};
1203
1204namespace impl {
1205
1206// Do not enclose entire StringProp with #ifndef U_HIDE_INTERNAL_API, needed for a protected field.
1207// And do not enclose its class boilerplate within #ifndef U_HIDE_INTERNAL_API.
1213
1214 public:
1217
1219 StringProp(const StringProp &other);
1220
1223
1224#ifndef U_HIDE_INTERNAL_API
1225
1228
1231
1233 int16_t length() const {
1234 return fLength;
1235 }
1236
1240 void set(StringPiece value);
1241
1243 bool isSet() const {
1244 return fLength > 0;
1245 }
1246
1247#endif // U_HIDE_INTERNAL_API
1248
1249 private:
1250 char *fValue;
1251 int16_t fLength;
1252 UErrorCode fError;
1253
1254 StringProp() : fValue(nullptr), fLength(0), fError(U_ZERO_ERROR) {
1255 }
1256
1258 UBool copyErrorTo(UErrorCode &status) const {
1259 if (U_FAILURE(fError)) {
1260 status = fError;
1261 return true;
1262 }
1263 return false;
1264 }
1265
1266 // Allow NumberFormatterImpl to access fValue.
1267 friend class impl::NumberFormatterImpl;
1268
1269 // Allow skeleton generation code to access private members.
1270 friend class impl::GeneratorHelpers;
1271
1272 // Allow MacroProps/MicroProps to initialize empty instances and to call
1273 // copyErrorTo().
1274 friend struct impl::MacroProps;
1275};
1276
1277// Do not enclose entire SymbolsWrapper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1280 public:
1282 SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
1283
1286
1289
1292
1295
1298
1299#ifndef U_HIDE_INTERNAL_API
1300
1305 void setTo(const DecimalFormatSymbols &dfs);
1306
1311 void setTo(const NumberingSystem *ns);
1312
1318
1323 bool isNumberingSystem() const;
1324
1330
1336
1337#endif // U_HIDE_INTERNAL_API
1338
1341 if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
1343 return true;
1344 } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
1346 return true;
1347 }
1348 return false;
1349 }
1350
1351 private:
1352 enum SymbolsPointerType {
1353 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1354 } fType;
1355
1356 union {
1357 const DecimalFormatSymbols *dfs;
1358 const NumberingSystem *ns;
1359 } fPtr;
1360
1361 void doCopyFrom(const SymbolsWrapper &other);
1362
1363 void doMoveFrom(SymbolsWrapper&& src);
1364
1365 void doCleanup();
1366};
1367
1368// Do not enclose entire Grouper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1371 public:
1372#ifndef U_HIDE_INTERNAL_API
1375
1380 static Grouper forProperties(const DecimalFormatProperties& properties);
1381
1382 // Future: static Grouper forProperties(DecimalFormatProperties& properties);
1383
1385 Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
1386 : fGrouping1(grouping1),
1387 fGrouping2(grouping2),
1388 fMinGrouping(minGrouping),
1389 fStrategy(strategy) {}
1390
1392 int16_t getPrimary() const;
1393
1395 int16_t getSecondary() const;
1396#endif // U_HIDE_INTERNAL_API
1397
1398 private:
1407 int16_t fGrouping1;
1408 int16_t fGrouping2;
1409
1417 int16_t fMinGrouping;
1418
1423 UNumberGroupingStrategy fStrategy;
1424
1425 Grouper() : fGrouping1(-3) {}
1426
1427 bool isBogus() const {
1428 return fGrouping1 == -3;
1429 }
1430
1432 void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
1433
1434 bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
1435
1436 // To allow MacroProps/MicroProps to initialize empty instances:
1437 friend struct MacroProps;
1438 friend struct MicroProps;
1439
1440 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1441 friend class NumberFormatterImpl;
1442
1443 // To allow NumberParserImpl to perform setLocaleData():
1444 friend class ::icu::numparse::impl::NumberParserImpl;
1445
1446 // To allow access to the skeleton generation code:
1447 friend class impl::GeneratorHelpers;
1448};
1449
1450// Do not enclose entire Padder with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1452class U_I18N_API Padder : public UMemory {
1453 public:
1454#ifndef U_HIDE_INTERNAL_API
1456 static Padder none();
1457
1459 static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
1460
1462 static Padder forProperties(const DecimalFormatProperties& properties);
1463#endif // U_HIDE_INTERNAL_API
1464
1465 private:
1466 UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding
1467 union {
1468 struct {
1469 int32_t fCp;
1470 UNumberFormatPadPosition fPosition;
1471 } padding;
1472 UErrorCode errorCode;
1473 } fUnion;
1474
1475 Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
1476
1477 Padder(int32_t width);
1478
1479 Padder(UErrorCode errorCode) : fWidth(-3) { // NOLINT
1480 fUnion.errorCode = errorCode;
1481 }
1482
1483 Padder() : fWidth(-2) {} // NOLINT
1484
1485 bool isBogus() const {
1486 return fWidth == -2;
1487 }
1488
1489 UBool copyErrorTo(UErrorCode &status) const {
1490 if (fWidth == -3) {
1491 status = fUnion.errorCode;
1492 return true;
1493 }
1494 return false;
1495 }
1496
1497 bool isValid() const {
1498 return fWidth > 0;
1499 }
1500
1501 int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
1502 FormattedStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
1503 UErrorCode &status) const;
1504
1505 // To allow MacroProps/MicroProps to initialize empty instances:
1506 friend struct MacroProps;
1507 friend struct MicroProps;
1508
1509 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1510 friend class impl::NumberFormatterImpl;
1511
1512 // To allow access to the skeleton generation code:
1513 friend class impl::GeneratorHelpers;
1514};
1515
1516// Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1521
1523 MeasureUnit unit; // = MeasureUnit(); (the base dimensionless unit)
1524
1526 MeasureUnit perUnit; // = MeasureUnit(); (the base dimensionless unit)
1527
1529 Precision precision; // = Precision(); (bogus)
1530
1533
1535 Grouper grouper; // = Grouper(); (bogus)
1536
1538 Padder padder; // = Padder(); (bogus)
1539
1541 IntegerWidth integerWidth; // = IntegerWidth(); (bogus)
1542
1545
1546 // UNUM_XYZ_COUNT denotes null (bogus) values.
1547
1550
1553
1555 bool approximately = false;
1556
1559
1561 Scale scale; // = Scale(); (benign value)
1562
1564 StringProp usage; // = StringProp(); (no usage)
1565
1567 StringProp unitDisplayCase; // = StringProp(); (nominative)
1568
1570 const AffixPatternProvider* affixProvider = nullptr; // no ownership
1571
1573 const PluralRules* rules = nullptr; // no ownership
1574
1576 int32_t threshold = kInternalDefaultThreshold;
1577
1580
1581 // NOTE: Uses default copy and move constructors.
1582
1587 bool copyErrorTo(UErrorCode &status) const {
1588 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1589 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1590 symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1591 unitDisplayCase.copyErrorTo(status);
1592 }
1593};
1594
1595} // namespace impl
1596
1597#if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1598// Ignore MSVC warning 4661. This is generated for NumberFormatterSettings<>::toSkeleton() as this method
1599// is defined elsewhere (in number_skeletons.cpp). The compiler is warning that the explicit template instantiation
1600// inside this single translation unit (CPP file) is incomplete, and thus it isn't sure if the template class is
1601// fully defined. However, since each translation unit explicitly instantiates all the necessary template classes,
1602// they will all be passed to the linker, and the linker will still find and export all the class members.
1603#pragma warning(push)
1604#pragma warning(disable: 4661)
1605#endif
1606
1612template<typename Derived>
1614 public:
1643 Derived notation(const Notation &notation) const &;
1644
1654 Derived notation(const Notation &notation) &&;
1655
1704 Derived unit(const icu::MeasureUnit &unit) const &;
1705
1715 Derived unit(const icu::MeasureUnit &unit) &&;
1716
1730 Derived adoptUnit(icu::MeasureUnit *unit) const &;
1731
1741 Derived adoptUnit(icu::MeasureUnit *unit) &&;
1742
1765 Derived perUnit(const icu::MeasureUnit &perUnit) const &;
1766
1776 Derived perUnit(const icu::MeasureUnit &perUnit) &&;
1777
1791 Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
1792
1802 Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
1803
1834 Derived precision(const Precision& precision) const &;
1835
1845 Derived precision(const Precision& precision) &&;
1846
1865 Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
1866
1875 Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
1876
1904 Derived grouping(UNumberGroupingStrategy strategy) const &;
1905
1915 Derived grouping(UNumberGroupingStrategy strategy) &&;
1916
1941 Derived integerWidth(const IntegerWidth &style) const &;
1942
1952 Derived integerWidth(const IntegerWidth &style) &&;
1953
1994 Derived symbols(const DecimalFormatSymbols &symbols) const &;
1995
2005 Derived symbols(const DecimalFormatSymbols &symbols) &&;
2006
2040 Derived adoptSymbols(NumberingSystem *symbols) const &;
2041
2051 Derived adoptSymbols(NumberingSystem *symbols) &&;
2052
2078 Derived unitWidth(UNumberUnitWidth width) const &;
2079
2089 Derived unitWidth(UNumberUnitWidth width) &&;
2090
2116 Derived sign(UNumberSignDisplay style) const &;
2117
2127 Derived sign(UNumberSignDisplay style) &&;
2128
2155
2166
2191 Derived scale(const Scale &scale) const &;
2192
2202 Derived scale(const Scale &scale) &&;
2203
2246 Derived usage(StringPiece usage) const &;
2247
2255 Derived usage(StringPiece usage) &&;
2256
2257#ifndef U_HIDE_DRAFT_API
2266 Derived displayOptions(const DisplayOptions &displayOptions) const &;
2267
2275 Derived displayOptions(const DisplayOptions &displayOptions) &&;
2276#endif // U_HIDE_DRAFT_API
2277
2278#ifndef U_HIDE_INTERNAL_API
2289 Derived unitDisplayCase(StringPiece unitDisplayCase) const &;
2290
2300 Derived unitDisplayCase(StringPiece unitDisplayCase) &&;
2301#endif // U_HIDE_INTERNAL_API
2302
2303#ifndef U_HIDE_INTERNAL_API
2304
2310 Derived padding(const impl::Padder &padder) const &;
2311
2313 Derived padding(const impl::Padder &padder) &&;
2314
2321 Derived threshold(int32_t threshold) const &;
2322
2324 Derived threshold(int32_t threshold) &&;
2325
2331 Derived macros(const impl::MacroProps& macros) const &;
2332
2334 Derived macros(const impl::MacroProps& macros) &&;
2335
2337 Derived macros(impl::MacroProps&& macros) const &;
2338
2340 Derived macros(impl::MacroProps&& macros) &&;
2341
2342#endif /* U_HIDE_INTERNAL_API */
2343
2362
2375
2383 LocalPointer<Derived> clone() &&;
2384
2391 UBool copyErrorTo(UErrorCode &outErrorCode) const {
2392 if (U_FAILURE(outErrorCode)) {
2393 // Do not overwrite the older error code
2394 return true;
2395 }
2396 fMacros.copyErrorTo(outErrorCode);
2397 return U_FAILURE(outErrorCode);
2398 }
2399
2400 // NOTE: Uses default copy and move constructors.
2401
2402 private:
2403 impl::MacroProps fMacros;
2404
2405 // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
2406 NumberFormatterSettings() = default;
2407
2408 friend class LocalizedNumberFormatter;
2409 friend class UnlocalizedNumberFormatter;
2410
2411 // Give NumberRangeFormatter access to the MacroProps
2412 friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
2413 friend class impl::NumberRangeFormatterImpl;
2414};
2415
2425 : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
2426
2427 public:
2438
2449
2456
2462
2469
2475
2482
2483 private:
2485
2488
2489 // To give the fluent setters access to this class's constructor:
2491
2492 // To give NumberFormatter::with() access to this class's constructor:
2493 friend class NumberFormatter;
2494};
2495
2505 : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
2506 public:
2518 FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
2519
2531 FormattedNumber formatDouble(double value, UErrorCode &status) const;
2532
2548
2549#ifndef U_HIDE_INTERNAL_API
2550
2551
2556
2560 FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
2561
2565 void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
2566
2571 const impl::NumberFormatterImpl* getCompiled() const;
2572
2577 int32_t getCallCount() const;
2578
2579#endif /* U_HIDE_INTERNAL_API */
2580
2594 Format* toFormat(UErrorCode& status) const;
2595
2602
2608
2615
2621
2628
2629#ifndef U_HIDE_INTERNAL_API
2630
2643 void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
2644
2645#endif /* U_HIDE_INTERNAL_API */
2646
2652
2653 private:
2654 // Note: fCompiled can't be a LocalPointer because impl::NumberFormatterImpl is defined in an internal
2655 // header, and LocalPointer needs the full class definition in order to delete the instance.
2656 const impl::NumberFormatterImpl* fCompiled {nullptr};
2657 char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t
2658
2659 // Owned pointer to a DecimalFormatWarehouse, used when copying a LocalizedNumberFormatter
2660 // from a DecimalFormat.
2661 const impl::DecimalFormatWarehouse* fWarehouse {nullptr};
2662
2663 explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
2664
2665 explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
2666
2667 LocalizedNumberFormatter(const impl::MacroProps &macros, const Locale &locale);
2668
2669 LocalizedNumberFormatter(impl::MacroProps &&macros, const Locale &locale);
2670
2671 void resetCompiled();
2672
2673 void lnfMoveHelper(LocalizedNumberFormatter&& src);
2674
2675 void lnfCopyHelper(const LocalizedNumberFormatter& src, UErrorCode& status);
2676
2680 bool computeCompiled(UErrorCode& status) const;
2681
2682 // To give the fluent setters access to this class's constructor:
2683 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2684 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
2685
2686 // To give UnlocalizedNumberFormatter::locale() access to this class's constructor:
2687 friend class UnlocalizedNumberFormatter;
2688};
2689
2690#if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2691// Warning 4661.
2692#pragma warning(pop)
2693#endif
2694
2704 public:
2705
2711 : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
2712
2718
2724
2727
2729 FormattedNumber& operator=(const FormattedNumber&) = delete;
2730
2736
2737 // Copybrief: this method is older than the parent method
2745 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
2746
2747 // Copydoc: this method is new in ICU 64
2749 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
2750
2751 // Copybrief: this method is older than the parent method
2759 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
2760
2761 // Copydoc: this method is new in ICU 64
2763 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
2764
2783 template<typename StringClass>
2784 inline StringClass toDecimalNumber(UErrorCode& status) const;
2785
2797 MeasureUnit getOutputUnit(UErrorCode& status) const;
2798
2799#ifndef U_HIDE_DRAFT_API
2800
2809
2810#endif // U_HIDE_DRAFT_API
2811
2812#ifndef U_HIDE_INTERNAL_API
2813
2818 void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
2819
2824 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
2825
2826#endif /* U_HIDE_INTERNAL_API */
2827
2828 private:
2829 // Can't use LocalPointer because UFormattedNumberData is forward-declared
2830 const impl::UFormattedNumberData *fData;
2831
2832 // Error code for the terminal methods
2833 UErrorCode fErrorCode;
2834
2839 explicit FormattedNumber(impl::UFormattedNumberData *results)
2840 : fData(results), fErrorCode(U_ZERO_ERROR) {}
2841
2842 explicit FormattedNumber(UErrorCode errorCode)
2843 : fData(nullptr), fErrorCode(errorCode) {}
2844
2845 void toDecimalNumber(ByteSink& sink, UErrorCode& status) const;
2846
2847 // To give LocalizedNumberFormatter format methods access to this class's constructor:
2848 friend class LocalizedNumberFormatter;
2849
2850 // To give C API access to internals
2851 friend struct impl::UFormattedNumberImpl;
2852};
2853
2854template<typename StringClass>
2855StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const {
2856 StringClass result;
2857 StringByteSink<StringClass> sink(&result);
2858 toDecimalNumber(sink, status);
2859 return result;
2860}
2861
2868 public:
2877
2888
2907
2929 UParseError& perror, UErrorCode& status);
2930
2935};
2936
2937} // namespace number
2938U_NAMESPACE_END
2939
2940#endif /* #if !UCONFIG_NO_FORMATTING */
2941
2942#endif /* U_SHOW_CPLUSPLUS_API */
2943
2944#endif // __NUMBERFORMATTER_H__
C++ API: Appendable class: Sink for Unicode code points and 16-bit code units (char16_ts).
C++ API: Interface for writing bytes, and implementation classes.
Base class for objects to which Unicode characters and strings can be appended.
Definition: appendable.h:54
A ByteSink can be filled with bytes.
Definition: bytestream.h:53
Represents a span of a string containing a given field.
A unit of currency, such as USD (U.S.
Definition: currunit.h:39
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:86
Represents all the display options that are supported by CLDR such as grammatical case,...
Base class for all formats.
Definition: format.h:98
An abstract formatted value: a string with associated field attributes.
"Smart pointer" class, deletes objects via the standard C++ delete operator.
Definition: localpointer.h:191
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:368
Defines numbering systems.
Definition: numsys.h:60
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:212
Implementation of ByteSink that writes to a "string".
Definition: bytestream.h:267
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
UMemory is the common ICU base class.
Definition: uobject.h:115
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
A class that defines a rounding precision parameterized by a currency to be used when formatting numb...
Precision withCurrency(const CurrencyUnit &currency) const
Associates a currency with this rounding precision.
The result of a number formatting operation.
void getDecimalQuantity(impl::DecimalQuantity &output, UErrorCode &status) const
Gets the raw DecimalQuantity for plural rule selection.
UDisplayOptionsNounClass getNounClass(UErrorCode &status) const
Gets the noun class of the formatted output.
FormattedNumber()
Default constructor; makes an empty FormattedNumber.
void getAllFieldPositionsImpl(FieldPositionIteratorHandler &fpih, UErrorCode &status) const
Populates the mutable builder type FieldPositionIteratorHandler.
virtual ~FormattedNumber() U_OVERRIDE
Destruct an instance of FormattedNumber.
FormattedNumber(FormattedNumber &&src) U_NOEXCEPT
Move constructor: Leaves the source FormattedNumber in an undefined state.
A class that defines a rounding precision based on a number of fraction places and optionally signifi...
Precision withMinDigits(int32_t minSignificantDigits) const
Ensure that no less than this number of significant digits are retained when rounding according to fr...
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...
Precision withMaxDigits(int32_t maxSignificantDigits) const
Ensure that no more than this number of significant digits are retained when rounding according to fr...
A class that defines a rounding precision parameterized by a rounding increment to be used when forma...
Precision withMinFraction(int32_t minFrac) const
Specifies the minimum number of fraction digits to render after the decimal separator,...
A class that defines the strategy for padding and truncating integers before the decimal separator.
static IntegerWidth zeroFillTo(int32_t minInt)
Pad numbers at the beginning with zeros to guarantee a certain number of numerals before the decimal ...
IntegerWidth truncateAt(int32_t maxInt)
Truncate numbers exceeding a certain number of numerals before the decimal separator.
A NumberFormatter that has a locale associated with it; this means .format() methods are available.
Format * toFormat(UErrorCode &status) const
Creates a representation of this LocalizedNumberFormat as an icu::Format, enabling the use of this nu...
const DecimalFormatSymbols * getDecimalFormatSymbols() const
FormattedNumber formatInt(int64_t value, UErrorCode &status) const
Format the given integer number to a string using the settings specified in the NumberFormatter fluen...
LocalizedNumberFormatter()=default
Default constructor: puts the formatter into a valid but undefined state.
LocalizedNumberFormatter(const LocalizedNumberFormatter &other)
Returns a copy of this LocalizedNumberFormatter.
const impl::NumberFormatterImpl * getCompiled() const
Internal method for testing.
int32_t getCallCount() const
Internal method for testing.
~LocalizedNumberFormatter()
Destruct this LocalizedNumberFormatter, cleaning up any memory it might own.
LocalizedNumberFormatter(LocalizedNumberFormatter &&src) U_NOEXCEPT
Move constructor: The source LocalizedNumberFormatter will be left in a valid but undefined state.
void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const
This is the core entrypoint to the number formatting pipeline.
FormattedNumber formatDecimal(StringPiece value, UErrorCode &status) const
Format the given decimal number to a string using the settings specified in the NumberFormatter fluen...
LocalizedNumberFormatter & operator=(LocalizedNumberFormatter &&src) U_NOEXCEPT
Move assignment operator: The source LocalizedNumberFormatter will be left in a valid but undefined s...
void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString &result, UErrorCode &status) const
Internal method for DecimalFormat compatibility.
FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity &dq, UErrorCode &status) const
Internal method.
FormattedNumber formatDouble(double value, UErrorCode &status) const
Format the given float or double to a string using the settings specified in the NumberFormatter flue...
LocalizedNumberFormatter & operator=(const LocalizedNumberFormatter &other)
Copy assignment operator.
A class that defines the notation style to be used when formatting numbers in NumberFormatter.
static CompactNotation compactShort()
Print the number using short-form compact notation.
static ScientificNotation engineering()
Print the number using engineering notation, a variant of scientific notation in which the exponent m...
static CompactNotation compactLong()
Print the number using long-form compact notation.
static SimpleNotation simple()
Print the number using simple notation without any scaling by powers of ten.
static ScientificNotation scientific()
Print the number using scientific notation (also known as scientific form, standard index form,...
An abstract base class for specifying settings related to number formatting.
Derived unitDisplayCase(StringPiece unitDisplayCase) &&
NOTE: Use displayOptions instead.
LocalPointer< Derived > clone() const &
Returns the current (Un)LocalizedNumberFormatter as a LocalPointer wrapping a heap-allocated copy of ...
Derived adoptSymbols(NumberingSystem *symbols) const &
Specifies that the given numbering system should be used when fetching symbols.
Derived precision(const Precision &precision) const &
Specifies the rounding precision to use when formatting numbers.
Derived decimal(UNumberDecimalSeparatorDisplay style) &&
Overload of decimal() for use on an rvalue reference.
Derived unitWidth(UNumberUnitWidth width) const &
Sets the width of the unit (measure unit or currency).
Derived adoptUnit(icu::MeasureUnit *unit) const &
Like unit(), but takes ownership of a pointer.
Derived perUnit(const icu::MeasureUnit &perUnit) &&
Overload of perUnit() for use on an rvalue reference.
Derived padding(const impl::Padder &padder) &&
Derived adoptSymbols(NumberingSystem *symbols) &&
Overload of adoptSymbols() for use on an rvalue reference.
Derived macros(const impl::MacroProps &macros) &&
Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&
Overload of roundingMode() for use on an rvalue reference.
Derived integerWidth(const IntegerWidth &style) const &
Specifies the minimum and maximum number of digits to render before the decimal mark.
Derived macros(const impl::MacroProps &macros) const &
Internal fluent setter to overwrite the entire macros object.
Derived threshold(int32_t threshold) const &
Internal fluent setter to support a custom regulation threshold.
Derived perUnit(const icu::MeasureUnit &perUnit) const &
Sets a unit to be used in the denominator.
Derived integerWidth(const IntegerWidth &style) &&
Overload of integerWidth() for use on an rvalue reference.
Derived unitDisplayCase(StringPiece unitDisplayCase) const &
NOTE: Use displayOptions instead.
Derived grouping(UNumberGroupingStrategy strategy) const &
Specifies the grouping strategy to use when formatting numbers.
Derived unit(const icu::MeasureUnit &unit) const &
Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
Derived displayOptions(const DisplayOptions &displayOptions) const &
Specifies the DisplayOptions.
Derived usage(StringPiece usage) &&
Overload of usage() for use on an rvalue reference.
Derived displayOptions(const DisplayOptions &displayOptions) &&
Overload of displayOptions() for use on an rvalue reference.
Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &
Like perUnit(), but takes ownership of a pointer.
Derived adoptUnit(icu::MeasureUnit *unit) &&
Overload of adoptUnit() for use on an rvalue reference.
Derived scale(const Scale &scale) &&
Overload of scale() for use on an rvalue reference.
Derived precision(const Precision &precision) &&
Overload of precision() for use on an rvalue reference.
Derived symbols(const DecimalFormatSymbols &symbols) &&
Overload of symbols() for use on an rvalue reference.
Derived padding(const impl::Padder &padder) const &
Set the padding strategy.
Derived notation(const Notation &notation) const &
Specifies the notation style (simple, scientific, or compact) for rendering numbers.
Derived sign(UNumberSignDisplay style) const &
Sets the plus/minus sign display strategy.
Derived threshold(int32_t threshold) &&
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...
Derived symbols(const DecimalFormatSymbols &symbols) const &
Specifies the symbols (decimal separator, grouping separator, percent sign, numerals,...
Derived macros(impl::MacroProps &&macros) &&
Derived sign(UNumberSignDisplay style) &&
Overload of sign() for use on an rvalue reference.
UnicodeString toSkeleton(UErrorCode &status) const
Creates a skeleton string representation of this number formatter.
Derived grouping(UNumberGroupingStrategy strategy) &&
Overload of grouping() for use on an rvalue reference.
Derived usage(StringPiece usage) const &
Specifies the usage for which numbers will be formatted ("person-height", "road", "rainfall",...
Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&
Overload of adoptPerUnit() for use on an rvalue reference.
Derived unitWidth(UNumberUnitWidth width) &&
Overload of unitWidth() for use on an rvalue reference.
Derived decimal(UNumberDecimalSeparatorDisplay style) const &
Sets the decimal separator display strategy.
Derived unit(const icu::MeasureUnit &unit) &&
Overload of unit() for use on an rvalue reference.
Derived macros(impl::MacroProps &&macros) const &
Derived scale(const Scale &scale) const &
Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting.
Derived notation(const Notation &notation) &&
Overload of notation() for use on an rvalue reference.
See the main description in numberformatter.h for documentation and examples.
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 ...
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 ...
static UnlocalizedNumberFormatter with()
Call this method at the beginning of a NumberFormatter fluent chain in which the locale is not curren...
NumberFormatter()=delete
Use factory methods instead of the constructor to create a NumberFormatter.
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...
A class that defines the rounding precision to be used when formatting numbers in NumberFormatter.
static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures.
static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits)
Always show at least a certain number of significant digits/figures, padding with zeros if necessary.
static FractionPrecision maxFraction(int32_t maxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
static IncrementPrecision increment(double roundingIncrement)
Show numbers rounded if necessary to the closest multiple of a certain rounding increment.
static CurrencyPrecision currency(UCurrencyUsage currencyUsage)
Show numbers rounded and padded according to the rules for the currency unit.
static FractionPrecision minFraction(int32_t minFractionPlaces)
Always show at least a certain number of fraction places after the decimal separator,...
Precision trailingZeroDisplay(UNumberTrailingZeroDisplay trailingZeroDisplay) const
Configure how trailing zeros are displayed on numbers.
static Precision unlimited()
Show all available digits to full precision.
static FractionPrecision integer()
Show numbers rounded if necessary to the nearest integer.
static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits or significant figures.
static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude)
Version of Precision::increment() that takes an integer at a particular power of 10.
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 ...
static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures; in addition,...
A class that defines a quantity by which a number should be multiplied when formatting.
static Scale none()
Do not change the value of numbers when formatting or parsing.
Scale(Scale &&src) U_NOEXCEPT
static Scale powerOfTen(int32_t power)
Multiply numbers by a power of ten before formatting.
Scale(const Scale &other)
static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power)
Multiply a number by both a power of ten and by an arbitrary double value.
static Scale byDecimal(StringPiece multiplicand)
Multiply numbers by an arbitrary value before formatting.
Scale(int32_t magnitude, impl::DecNum *arbitraryToAdopt)
Scale & operator=(const Scale &other)
Scale & operator=(Scale &&src) U_NOEXCEPT
static Scale byDouble(double multiplicand)
Multiply numbers by an arbitrary value before formatting.
A class that defines the scientific notation style to be used when formatting numbers in NumberFormat...
ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const
Sets whether to show the sign on positive and negative exponents in scientific notation.
ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const
Sets the minimum number of digits to show in the exponent of scientific notation, padding with zeros ...
A NumberFormatter that does not yet have a locale.
UnlocalizedNumberFormatter & operator=(UnlocalizedNumberFormatter &&src) U_NOEXCEPT
Move assignment operator: The source UnlocalizedNumberFormatter will be left in a valid but undefined...
UnlocalizedNumberFormatter()=default
Default constructor: puts the formatter into a valid but undefined state.
UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other)
Returns a copy of this UnlocalizedNumberFormatter.
LocalizedNumberFormatter locale(const icu::Locale &locale) &&
Overload of locale() for use on an rvalue reference.
UnlocalizedNumberFormatter & operator=(const UnlocalizedNumberFormatter &other)
Copy assignment operator.
LocalizedNumberFormatter locale(const icu::Locale &locale) const &
Associate the given locale with the number formatter.
UnlocalizedNumberFormatter(UnlocalizedNumberFormatter &&src) U_NOEXCEPT
Move constructor: The source UnlocalizedNumberFormatter will be left in a valid but undefined state.
static Grouper forStrategy(UNumberGroupingStrategy grouping)
Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
int16_t getSecondary() const
static Grouper forProperties(const DecimalFormatProperties &properties)
Resolve the values in Properties to a Grouper object.
int16_t getPrimary() const
static Padder forProperties(const DecimalFormatProperties &properties)
static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position)
Manages NumberFormatterSettings::usage()'s char* instance on the heap.
StringProp(const StringProp &other)
StringProp & operator=(StringProp &&src) U_NOEXCEPT
StringProp & operator=(const StringProp &other)
void set(StringPiece value)
StringProp(StringProp &&src) U_NOEXCEPT
SymbolsWrapper & operator=(const SymbolsWrapper &other)
bool isNumberingSystem() const
Whether the object is currently holding a NumberingSystem.
SymbolsWrapper(SymbolsWrapper &&src) U_NOEXCEPT
SymbolsWrapper & operator=(SymbolsWrapper &&src) U_NOEXCEPT
const DecimalFormatSymbols * getDecimalFormatSymbols() const
Get the DecimalFormatSymbols pointer.
SymbolsWrapper(const SymbolsWrapper &other)
void setTo(const DecimalFormatSymbols &dfs)
The provided object is copied, but we do not adopt it.
const NumberingSystem * getNumberingSystem() const
Get the NumberingSystem pointer.
void setTo(const NumberingSystem *ns)
Adopt the provided object.
UBool copyErrorTo(UErrorCode &status) const
bool isDecimalFormatSymbols() const
Whether the object is currently holding a DecimalFormatSymbols.
C++ API: Currency Unit Information.
C++ API: Symbols for formatting numbers.
C++ API: Display options class.
C++ API: FieldPosition identifies the fields in a formatted output.
C++ API: Abstract operations for localized strings.
C++ API: FieldPosition Iterator.
C++ API: A unit for measuring a quantity.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: units for percent and permille.
int16_t digits_t
Datatype for minimum/maximum fraction digits.
void touchRangeLocales(impl::RangeMacroProps &macros)
Used for NumberRangeFormatter and implemented in numrange_fluent.cpp.
C API: Parse Error Information.
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:529
C++ API: PluralRules object.
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
bool fRetain
Whether to retain trailing zeros based on the looser strategy.
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
C API: Encapsulates information about a currency.
UCurrencyUsage
Currency Usage used for Decimal Format.
Definition: ucurr.h:41
C API: Display options (enum types, values, helper functions)
UDisplayOptionsNounClass
Represents all the grammatical noun classes that are supported by CLDR.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:461
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
#define U_OVERRIDE
Defined to the C++11 "override" keyword if available.
Definition: umachine.h:130
C API: Compatibility APIs for number formatting.
UNumberFormatRoundingMode
The possible number format rounding modes.
Definition: unum.h:282
@ UNUM_ROUND_HALFEVEN
Half-even rounding.
Definition: unum.h:291
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:337
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:326
C API: Localized number formatting; not recommended for C++.
UNumberRoundingPriority
An enum declaring how to resolve conflicts between maximum fraction digits and maximum significant di...
UNumberSignDisplay
An enum declaring how to denote positive and negative numbers.
@ UNUM_SIGN_COUNT
One more than the highest UNumberSignDisplay value.
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
@ UNUM_DECIMAL_SEPARATOR_COUNT
One more than the highest UNumberDecimalSeparatorDisplay value.
UNumberTrailingZeroDisplay
An enum declaring how to render trailing zeros.
@ UNUM_TRAILING_ZERO_AUTO
Display trailing zeros according to the settings for minimum fraction and significant digits.
UNumberUnitWidth
An enum declaring how to render units, including currencies.
@ UNUM_UNIT_WIDTH_COUNT
One more than the highest UNumberUnitWidth value.
UNumberGroupingStrategy
An enum declaring the strategy for when and how to display grouping separators (i....
C++ API: Common ICU base class UObject.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition: utypes.h:457
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition: utypes.h:478
@ U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:449
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition: utypes.h:717
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301