ICU 71.1 71.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"
17#include "unicode/fieldpos.h"
19#include "unicode/fpositer.h"
20#include "unicode/measunit.h"
21#include "unicode/nounit.h"
22#include "unicode/parseerr.h"
23#include "unicode/plurrule.h"
24#include "unicode/ucurr.h"
25#include "unicode/unounclass.h"
26#include "unicode/unum.h"
28#include "unicode/uobject.h"
29
85U_NAMESPACE_BEGIN
86
87// Forward declarations:
88class IFixedDecimal;
89class FieldPositionIteratorHandler;
90class FormattedStringBuilder;
91
92namespace numparse {
93namespace impl {
94
95// Forward declarations:
96class NumberParserImpl;
97class MultiplierParseHandler;
98
99}
100}
101
102namespace units {
103
104// Forward declarations:
105class UnitsRouter;
106
107} // namespace units
108
109namespace number { // icu::number
110
111// Forward declarations:
112class UnlocalizedNumberFormatter;
113class LocalizedNumberFormatter;
114class FormattedNumber;
115class Notation;
116class ScientificNotation;
117class Precision;
118class FractionPrecision;
119class CurrencyPrecision;
120class IncrementPrecision;
121class IntegerWidth;
122
123namespace impl {
124
125// can't be #ifndef U_HIDE_INTERNAL_API; referenced throughout this file in public classes
131typedef int16_t digits_t;
132
133// can't be #ifndef U_HIDE_INTERNAL_API; needed for struct initialization
140static constexpr int32_t kInternalDefaultThreshold = 3;
141
142// Forward declarations:
143class Padder;
144struct MacroProps;
145struct MicroProps;
146class DecimalQuantity;
147class UFormattedNumberData;
148class NumberFormatterImpl;
149struct ParsedPatternInfo;
150class ScientificModifier;
151class MultiplierProducer;
152class RoundingImpl;
153class ScientificHandler;
154class Modifier;
155class AffixPatternProvider;
156class NumberPropertyMapper;
157struct DecimalFormatProperties;
158class MultiplierFormatHandler;
159class CurrencySymbols;
160class GeneratorHelpers;
161class DecNum;
162class NumberRangeFormatterImpl;
163struct RangeMacroProps;
164struct UFormattedNumberImpl;
165class MutablePatternModifier;
166class ImmutablePatternModifier;
167struct DecimalFormatWarehouse;
168
176
177} // namespace impl
178
185
192
199 public:
225
249
292
316
342
343 private:
344 enum NotationType {
345 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
346 } fType;
347
348 union NotationUnion {
349 // For NTN_SCIENTIFIC
360 } scientific;
361
362 // For NTN_COMPACT
363 UNumberCompactStyle compactStyle;
364
365 // For NTN_ERROR
366 UErrorCode errorCode;
367 } fUnion;
368
370
371 Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
372
373 Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
374 fUnion.errorCode = errorCode;
375 }
376
377 Notation() : fType(NTN_SIMPLE), fUnion() {}
378
379 UBool copyErrorTo(UErrorCode &status) const {
380 if (fType == NTN_ERROR) {
381 status = fUnion.errorCode;
382 return true;
383 }
384 return false;
385 }
386
387 // To allow MacroProps to initialize empty instances:
388 friend struct impl::MacroProps;
389 friend class ScientificNotation;
390
391 // To allow implementation to access internal types:
392 friend class impl::NumberFormatterImpl;
393 friend class impl::ScientificModifier;
394 friend class impl::ScientificHandler;
395
396 // To allow access to the skeleton generation code:
397 friend class impl::GeneratorHelpers;
398};
399
409 public:
423 ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
424
439
440 private:
441 // Inherit constructor
442 using Notation::Notation;
443
444 // Raw constructor for NumberPropertyMapper
445 ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
446 UNumberSignDisplay fExponentSignDisplay);
447
448 friend class Notation;
449
450 // So that NumberPropertyMapper can create instances
451 friend class impl::NumberPropertyMapper;
452};
453
460
470
471 public:
490
498
526 static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
527
541 static FractionPrecision minFraction(int32_t minFractionPlaces);
542
553 static FractionPrecision maxFraction(int32_t maxFractionPlaces);
554
568 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
569
583 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
584
597 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
598
607 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
608
620 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
621 int32_t maxSignificantDigits);
622
642 static IncrementPrecision increment(double roundingIncrement);
643
644#ifndef U_HIDE_DRAFT_API
668 static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude);
669#endif // U_HIDE_DRAFT_API
670
689
698
699 private:
700 enum PrecisionType {
701 RND_BOGUS,
702 RND_NONE,
703 RND_FRACTION,
704 RND_SIGNIFICANT,
705 RND_FRACTION_SIGNIFICANT,
706
707 // Used for strange increments like 3.14.
708 RND_INCREMENT,
709
710 // Used for increments with 1 as the only digit. This is different than fraction
711 // rounding because it supports having additional trailing zeros. For example, this
712 // class is used to round with the increment 0.010.
713 RND_INCREMENT_ONE,
714
715 // Used for increments with 5 as the only digit (nickel rounding).
716 RND_INCREMENT_FIVE,
717
718 RND_CURRENCY,
719 RND_ERROR
720 } fType;
721
722 union PrecisionUnion {
725 // For RND_FRACTION, RND_SIGNIFICANT, and RND_FRACTION_SIGNIFICANT
741 } fracSig;
744 // For RND_INCREMENT, RND_INCREMENT_ONE, and RND_INCREMENT_FIVE
745 // Note: This is a union, so we shouldn't own memory, since
746 // the default destructor would leak it.
748 uint64_t fIncrement;
753 } increment;
754 UCurrencyUsage currencyUsage; // For RND_CURRENCY
755 UErrorCode errorCode; // For RND_ERROR
756 } fUnion;
757
759
762
763 Precision(const PrecisionType& type, const PrecisionUnion& union_)
764 : fType(type), fUnion(union_) {}
765
766 Precision(UErrorCode errorCode) : fType(RND_ERROR) {
767 fUnion.errorCode = errorCode;
768 }
769
770 Precision() : fType(RND_BOGUS) {}
771
772 bool isBogus() const {
773 return fType == RND_BOGUS;
774 }
775
776 UBool copyErrorTo(UErrorCode &status) const {
777 if (fType == RND_ERROR) {
778 status = fUnion.errorCode;
779 return true;
780 }
781 return false;
782 }
783
784 // On the parent type so that this method can be called internally on Precision instances.
785 Precision withCurrency(const CurrencyUnit &currency, UErrorCode &status) const;
786
787 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
788
789 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
790
791 static Precision constructFractionSignificant(
792 const FractionPrecision &base,
793 int32_t minSig,
794 int32_t maxSig,
796 bool retain);
797
798 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
799
800 static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
801
802 // To allow MacroProps/MicroProps to initialize bogus instances:
803 friend struct impl::MacroProps;
804 friend struct impl::MicroProps;
805
806 // To allow NumberFormatterImpl to access isBogus() and other internal methods:
807 friend class impl::NumberFormatterImpl;
808
809 // To allow NumberPropertyMapper to create instances from DecimalFormatProperties:
810 friend class impl::NumberPropertyMapper;
811
812 // To allow access to the main implementation class:
813 friend class impl::RoundingImpl;
814
815 // To allow child classes to call private methods:
816 friend class FractionPrecision;
817 friend class CurrencyPrecision;
818 friend class IncrementPrecision;
819
820 // To allow access to the skeleton generation code:
821 friend class impl::GeneratorHelpers;
822
823 // To allow access to isBogus and the default (bogus) constructor:
824 friend class units::UnitsRouter;
825};
826
837 public:
853 int32_t minSignificantDigits,
854 int32_t maxSignificantDigits,
855 UNumberRoundingPriority priority) const;
856
874 Precision withMinDigits(int32_t minSignificantDigits) const;
875
893 Precision withMaxDigits(int32_t maxSignificantDigits) const;
894
895 private:
896 // Inherit constructor
897 using Precision::Precision;
898
899 // To allow parent class to call this class's constructor:
900 friend class Precision;
901};
902
913 public:
931 Precision withCurrency(const CurrencyUnit &currency) const;
932
933 private:
934 // Inherit constructor
935 using Precision::Precision;
936
937 // To allow parent class to call this class's constructor:
938 friend class Precision;
939};
940
951 public:
967 Precision withMinFraction(int32_t minFrac) const;
968
969 private:
970 // Inherit constructor
971 using Precision::Precision;
972
973 // To allow parent class to call this class's constructor:
974 friend class Precision;
975};
976
987 public:
999 static IntegerWidth zeroFillTo(int32_t minInt);
1000
1012 IntegerWidth truncateAt(int32_t maxInt);
1013
1014 private:
1015 union {
1016 struct {
1017 impl::digits_t fMinInt;
1018 impl::digits_t fMaxInt;
1019 bool fFormatFailIfMoreThanMaxDigits;
1020 } minMaxInt;
1021 UErrorCode errorCode;
1022 } fUnion;
1023 bool fHasError = false;
1024
1025 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
1026
1027 IntegerWidth(UErrorCode errorCode) { // NOLINT
1028 fUnion.errorCode = errorCode;
1029 fHasError = true;
1030 }
1031
1032 IntegerWidth() { // NOLINT
1033 fUnion.minMaxInt.fMinInt = -1;
1034 }
1035
1037 static IntegerWidth standard() {
1038 return IntegerWidth::zeroFillTo(1);
1039 }
1040
1041 bool isBogus() const {
1042 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1043 }
1044
1045 UBool copyErrorTo(UErrorCode &status) const {
1046 if (fHasError) {
1047 status = fUnion.errorCode;
1048 return true;
1049 }
1050 return false;
1051 }
1052
1053 void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
1054
1055 bool operator==(const IntegerWidth& other) const;
1056
1057 // To allow MacroProps/MicroProps to initialize empty instances:
1058 friend struct impl::MacroProps;
1059 friend struct impl::MicroProps;
1060
1061 // To allow NumberFormatterImpl to access isBogus():
1062 friend class impl::NumberFormatterImpl;
1063
1064 // To allow the use of this class when formatting:
1065 friend class impl::MutablePatternModifier;
1066 friend class impl::ImmutablePatternModifier;
1067
1068 // So that NumberPropertyMapper can create instances
1069 friend class impl::NumberPropertyMapper;
1070
1071 // To allow access to the skeleton generation code:
1072 friend class impl::GeneratorHelpers;
1073};
1074
1083class U_I18N_API Scale : public UMemory {
1084 public:
1091 static Scale none();
1092
1103 static Scale powerOfTen(int32_t power);
1104
1117 static Scale byDecimal(StringPiece multiplicand);
1118
1127 static Scale byDouble(double multiplicand);
1128
1135 static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
1136
1137 // We need a custom destructor for the DecNum, which means we need to declare
1138 // the copy/move constructor/assignment quartet.
1139
1141 Scale(const Scale& other);
1142
1144 Scale& operator=(const Scale& other);
1145
1148
1151
1154
1155#ifndef U_HIDE_INTERNAL_API
1157 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1158#endif /* U_HIDE_INTERNAL_API */
1159
1160 private:
1161 int32_t fMagnitude;
1162 impl::DecNum* fArbitrary;
1163 UErrorCode fError;
1164
1165 Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
1166
1167 Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
1168
1169 bool isValid() const {
1170 return fMagnitude != 0 || fArbitrary != nullptr;
1171 }
1172
1173 UBool copyErrorTo(UErrorCode &status) const {
1174 if (U_FAILURE(fError)) {
1175 status = fError;
1176 return true;
1177 }
1178 return false;
1179 }
1180
1181 void applyTo(impl::DecimalQuantity& quantity) const;
1182
1183 void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
1184
1185 // To allow MacroProps/MicroProps to initialize empty instances:
1186 friend struct impl::MacroProps;
1187 friend struct impl::MicroProps;
1188
1189 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1190 friend class impl::NumberFormatterImpl;
1191
1192 // To allow the helper class MultiplierFormatHandler access to private fields:
1193 friend class impl::MultiplierFormatHandler;
1194
1195 // To allow access to the skeleton generation code:
1196 friend class impl::GeneratorHelpers;
1197
1198 // To allow access to parsing code:
1199 friend class ::icu::numparse::impl::NumberParserImpl;
1200 friend class ::icu::numparse::impl::MultiplierParseHandler;
1201};
1202
1203namespace impl {
1204
1205// Do not enclose entire StringProp with #ifndef U_HIDE_INTERNAL_API, needed for a protected field.
1206// And do not enclose its class boilerplate within #ifndef U_HIDE_INTERNAL_API.
1212
1213 public:
1216
1218 StringProp(const StringProp &other);
1219
1222
1223#ifndef U_HIDE_INTERNAL_API
1224
1227
1230
1232 int16_t length() const {
1233 return fLength;
1234 }
1235
1239 void set(StringPiece value);
1240
1242 bool isSet() const {
1243 return fLength > 0;
1244 }
1245
1246#endif // U_HIDE_INTERNAL_API
1247
1248 private:
1249 char *fValue;
1250 int16_t fLength;
1251 UErrorCode fError;
1252
1253 StringProp() : fValue(nullptr), fLength(0), fError(U_ZERO_ERROR) {
1254 }
1255
1257 UBool copyErrorTo(UErrorCode &status) const {
1258 if (U_FAILURE(fError)) {
1259 status = fError;
1260 return true;
1261 }
1262 return false;
1263 }
1264
1265 // Allow NumberFormatterImpl to access fValue.
1266 friend class impl::NumberFormatterImpl;
1267
1268 // Allow skeleton generation code to access private members.
1269 friend class impl::GeneratorHelpers;
1270
1271 // Allow MacroProps/MicroProps to initialize empty instances and to call
1272 // copyErrorTo().
1273 friend struct impl::MacroProps;
1274};
1275
1276// Do not enclose entire SymbolsWrapper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1279 public:
1281 SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
1282
1285
1288
1291
1294
1297
1298#ifndef U_HIDE_INTERNAL_API
1299
1304 void setTo(const DecimalFormatSymbols &dfs);
1305
1310 void setTo(const NumberingSystem *ns);
1311
1317
1322 bool isNumberingSystem() const;
1323
1329
1335
1336#endif // U_HIDE_INTERNAL_API
1337
1340 if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
1342 return true;
1343 } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
1345 return true;
1346 }
1347 return false;
1348 }
1349
1350 private:
1351 enum SymbolsPointerType {
1352 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1353 } fType;
1354
1355 union {
1356 const DecimalFormatSymbols *dfs;
1357 const NumberingSystem *ns;
1358 } fPtr;
1359
1360 void doCopyFrom(const SymbolsWrapper &other);
1361
1362 void doMoveFrom(SymbolsWrapper&& src);
1363
1364 void doCleanup();
1365};
1366
1367// Do not enclose entire Grouper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1370 public:
1371#ifndef U_HIDE_INTERNAL_API
1374
1379 static Grouper forProperties(const DecimalFormatProperties& properties);
1380
1381 // Future: static Grouper forProperties(DecimalFormatProperties& properties);
1382
1384 Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
1385 : fGrouping1(grouping1),
1386 fGrouping2(grouping2),
1387 fMinGrouping(minGrouping),
1388 fStrategy(strategy) {}
1389
1391 int16_t getPrimary() const;
1392
1394 int16_t getSecondary() const;
1395#endif // U_HIDE_INTERNAL_API
1396
1397 private:
1406 int16_t fGrouping1;
1407 int16_t fGrouping2;
1408
1416 int16_t fMinGrouping;
1417
1422 UNumberGroupingStrategy fStrategy;
1423
1424 Grouper() : fGrouping1(-3) {}
1425
1426 bool isBogus() const {
1427 return fGrouping1 == -3;
1428 }
1429
1431 void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
1432
1433 bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
1434
1435 // To allow MacroProps/MicroProps to initialize empty instances:
1436 friend struct MacroProps;
1437 friend struct MicroProps;
1438
1439 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1440 friend class NumberFormatterImpl;
1441
1442 // To allow NumberParserImpl to perform setLocaleData():
1443 friend class ::icu::numparse::impl::NumberParserImpl;
1444
1445 // To allow access to the skeleton generation code:
1446 friend class impl::GeneratorHelpers;
1447};
1448
1449// Do not enclose entire Padder with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1451class U_I18N_API Padder : public UMemory {
1452 public:
1453#ifndef U_HIDE_INTERNAL_API
1455 static Padder none();
1456
1458 static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
1459
1461 static Padder forProperties(const DecimalFormatProperties& properties);
1462#endif // U_HIDE_INTERNAL_API
1463
1464 private:
1465 UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding
1466 union {
1467 struct {
1468 int32_t fCp;
1469 UNumberFormatPadPosition fPosition;
1470 } padding;
1471 UErrorCode errorCode;
1472 } fUnion;
1473
1474 Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
1475
1476 Padder(int32_t width);
1477
1478 Padder(UErrorCode errorCode) : fWidth(-3) { // NOLINT
1479 fUnion.errorCode = errorCode;
1480 }
1481
1482 Padder() : fWidth(-2) {} // NOLINT
1483
1484 bool isBogus() const {
1485 return fWidth == -2;
1486 }
1487
1488 UBool copyErrorTo(UErrorCode &status) const {
1489 if (fWidth == -3) {
1490 status = fUnion.errorCode;
1491 return true;
1492 }
1493 return false;
1494 }
1495
1496 bool isValid() const {
1497 return fWidth > 0;
1498 }
1499
1500 int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
1501 FormattedStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
1502 UErrorCode &status) const;
1503
1504 // To allow MacroProps/MicroProps to initialize empty instances:
1505 friend struct MacroProps;
1506 friend struct MicroProps;
1507
1508 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1509 friend class impl::NumberFormatterImpl;
1510
1511 // To allow access to the skeleton generation code:
1512 friend class impl::GeneratorHelpers;
1513};
1514
1515// Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1520
1522 MeasureUnit unit; // = MeasureUnit(); (the base dimensionless unit)
1523
1525 MeasureUnit perUnit; // = MeasureUnit(); (the base dimensionless unit)
1526
1528 Precision precision; // = Precision(); (bogus)
1529
1532
1534 Grouper grouper; // = Grouper(); (bogus)
1535
1537 Padder padder; // = Padder(); (bogus)
1538
1540 IntegerWidth integerWidth; // = IntegerWidth(); (bogus)
1541
1544
1545 // UNUM_XYZ_COUNT denotes null (bogus) values.
1546
1549
1552
1554 bool approximately = false;
1555
1558
1560 Scale scale; // = Scale(); (benign value)
1561
1563 StringProp usage; // = StringProp(); (no usage)
1564
1566 StringProp unitDisplayCase; // = StringProp(); (nominative)
1567
1569 const AffixPatternProvider* affixProvider = nullptr; // no ownership
1570
1572 const PluralRules* rules = nullptr; // no ownership
1573
1575 int32_t threshold = kInternalDefaultThreshold;
1576
1579
1580 // NOTE: Uses default copy and move constructors.
1581
1586 bool copyErrorTo(UErrorCode &status) const {
1587 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1588 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1589 symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1590 unitDisplayCase.copyErrorTo(status);
1591 }
1592};
1593
1594} // namespace impl
1595
1596#if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1597// Ignore MSVC warning 4661. This is generated for NumberFormatterSettings<>::toSkeleton() as this method
1598// is defined elsewhere (in number_skeletons.cpp). The compiler is warning that the explicit template instantiation
1599// inside this single translation unit (CPP file) is incomplete, and thus it isn't sure if the template class is
1600// fully defined. However, since each translation unit explicitly instantiates all the necessary template classes,
1601// they will all be passed to the linker, and the linker will still find and export all the class members.
1602#pragma warning(push)
1603#pragma warning(disable: 4661)
1604#endif
1605
1611template<typename Derived>
1613 public:
1642 Derived notation(const Notation &notation) const &;
1643
1653 Derived notation(const Notation &notation) &&;
1654
1703 Derived unit(const icu::MeasureUnit &unit) const &;
1704
1714 Derived unit(const icu::MeasureUnit &unit) &&;
1715
1729 Derived adoptUnit(icu::MeasureUnit *unit) const &;
1730
1740 Derived adoptUnit(icu::MeasureUnit *unit) &&;
1741
1764 Derived perUnit(const icu::MeasureUnit &perUnit) const &;
1765
1775 Derived perUnit(const icu::MeasureUnit &perUnit) &&;
1776
1790 Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
1791
1801 Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
1802
1833 Derived precision(const Precision& precision) const &;
1834
1844 Derived precision(const Precision& precision) &&;
1845
1864 Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
1865
1874 Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
1875
1903 Derived grouping(UNumberGroupingStrategy strategy) const &;
1904
1914 Derived grouping(UNumberGroupingStrategy strategy) &&;
1915
1940 Derived integerWidth(const IntegerWidth &style) const &;
1941
1951 Derived integerWidth(const IntegerWidth &style) &&;
1952
1993 Derived symbols(const DecimalFormatSymbols &symbols) const &;
1994
2004 Derived symbols(const DecimalFormatSymbols &symbols) &&;
2005
2039 Derived adoptSymbols(NumberingSystem *symbols) const &;
2040
2050 Derived adoptSymbols(NumberingSystem *symbols) &&;
2051
2077 Derived unitWidth(UNumberUnitWidth width) const &;
2078
2088 Derived unitWidth(UNumberUnitWidth width) &&;
2089
2115 Derived sign(UNumberSignDisplay style) const &;
2116
2126 Derived sign(UNumberSignDisplay style) &&;
2127
2154
2165
2190 Derived scale(const Scale &scale) const &;
2191
2201 Derived scale(const Scale &scale) &&;
2202
2245 Derived usage(StringPiece usage) const &;
2246
2254 Derived usage(StringPiece usage) &&;
2255
2256#ifndef U_HIDE_DRAFT_API
2257#ifndef U_HIDE_INTERNAL_API
2264 Derived unitDisplayCase(StringPiece unitDisplayCase) const &;
2265
2271 Derived unitDisplayCase(StringPiece unitDisplayCase) &&;
2272#endif // U_HIDE_INTERNAL_API
2273#endif // U_HIDE_DRAFT_API
2274
2275#ifndef U_HIDE_INTERNAL_API
2276
2282 Derived padding(const impl::Padder &padder) const &;
2283
2285 Derived padding(const impl::Padder &padder) &&;
2286
2293 Derived threshold(int32_t threshold) const &;
2294
2296 Derived threshold(int32_t threshold) &&;
2297
2303 Derived macros(const impl::MacroProps& macros) const &;
2304
2306 Derived macros(const impl::MacroProps& macros) &&;
2307
2309 Derived macros(impl::MacroProps&& macros) const &;
2310
2312 Derived macros(impl::MacroProps&& macros) &&;
2313
2314#endif /* U_HIDE_INTERNAL_API */
2315
2334
2347
2355 LocalPointer<Derived> clone() &&;
2356
2363 UBool copyErrorTo(UErrorCode &outErrorCode) const {
2364 if (U_FAILURE(outErrorCode)) {
2365 // Do not overwrite the older error code
2366 return true;
2367 }
2368 fMacros.copyErrorTo(outErrorCode);
2369 return U_FAILURE(outErrorCode);
2370 }
2371
2372 // NOTE: Uses default copy and move constructors.
2373
2374 private:
2375 impl::MacroProps fMacros;
2376
2377 // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
2378 NumberFormatterSettings() = default;
2379
2380 friend class LocalizedNumberFormatter;
2381 friend class UnlocalizedNumberFormatter;
2382
2383 // Give NumberRangeFormatter access to the MacroProps
2384 friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
2385 friend class impl::NumberRangeFormatterImpl;
2386};
2387
2397 : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
2398
2399 public:
2410
2421
2428
2434
2441
2447
2454
2455 private:
2457
2460
2461 // To give the fluent setters access to this class's constructor:
2463
2464 // To give NumberFormatter::with() access to this class's constructor:
2465 friend class NumberFormatter;
2466};
2467
2477 : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
2478 public:
2490 FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
2491
2503 FormattedNumber formatDouble(double value, UErrorCode &status) const;
2504
2520
2521#ifndef U_HIDE_INTERNAL_API
2522
2523
2528
2532 FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
2533
2537 void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
2538
2543 const impl::NumberFormatterImpl* getCompiled() const;
2544
2549 int32_t getCallCount() const;
2550
2551#endif /* U_HIDE_INTERNAL_API */
2552
2566 Format* toFormat(UErrorCode& status) const;
2567
2574
2580
2587
2593
2600
2601#ifndef U_HIDE_INTERNAL_API
2602
2615 void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
2616
2617#endif /* U_HIDE_INTERNAL_API */
2618
2624
2625 private:
2626 // Note: fCompiled can't be a LocalPointer because impl::NumberFormatterImpl is defined in an internal
2627 // header, and LocalPointer needs the full class definition in order to delete the instance.
2628 const impl::NumberFormatterImpl* fCompiled {nullptr};
2629 char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t
2630
2631 // Owned pointer to a DecimalFormatWarehouse, used when copying a LocalizedNumberFormatter
2632 // from a DecimalFormat.
2633 const impl::DecimalFormatWarehouse* fWarehouse {nullptr};
2634
2635 explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
2636
2637 explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
2638
2639 LocalizedNumberFormatter(const impl::MacroProps &macros, const Locale &locale);
2640
2641 LocalizedNumberFormatter(impl::MacroProps &&macros, const Locale &locale);
2642
2643 void resetCompiled();
2644
2645 void lnfMoveHelper(LocalizedNumberFormatter&& src);
2646
2647 void lnfCopyHelper(const LocalizedNumberFormatter& src, UErrorCode& status);
2648
2652 bool computeCompiled(UErrorCode& status) const;
2653
2654 // To give the fluent setters access to this class's constructor:
2655 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2656 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
2657
2658 // To give UnlocalizedNumberFormatter::locale() access to this class's constructor:
2659 friend class UnlocalizedNumberFormatter;
2660};
2661
2662#if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2663// Warning 4661.
2664#pragma warning(pop)
2665#endif
2666
2676 public:
2677
2683 : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
2684
2690
2696
2699
2701 FormattedNumber& operator=(const FormattedNumber&) = delete;
2702
2708
2709 // Copybrief: this method is older than the parent method
2717 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
2718
2719 // Copydoc: this method is new in ICU 64
2721 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
2722
2723 // Copybrief: this method is older than the parent method
2731 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
2732
2733 // Copydoc: this method is new in ICU 64
2735 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
2736
2755 template<typename StringClass>
2756 inline StringClass toDecimalNumber(UErrorCode& status) const;
2757
2769 MeasureUnit getOutputUnit(UErrorCode& status) const;
2770
2771#ifndef U_HIDE_DRAFT_API
2772
2781
2782#endif // U_HIDE_DRAFT_API
2783
2784#ifndef U_HIDE_INTERNAL_API
2785
2790 void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
2791
2796 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
2797
2798#endif /* U_HIDE_INTERNAL_API */
2799
2800#ifndef U_HIDE_DEPRECATED_API
2801
2808 const char *getGender(UErrorCode &status) const;
2809
2810#endif /* U_HIDE_DEPRECATED_API */
2811
2812 private:
2813 // Can't use LocalPointer because UFormattedNumberData is forward-declared
2814 const impl::UFormattedNumberData *fData;
2815
2816 // Error code for the terminal methods
2817 UErrorCode fErrorCode;
2818
2823 explicit FormattedNumber(impl::UFormattedNumberData *results)
2824 : fData(results), fErrorCode(U_ZERO_ERROR) {}
2825
2826 explicit FormattedNumber(UErrorCode errorCode)
2827 : fData(nullptr), fErrorCode(errorCode) {}
2828
2829 void toDecimalNumber(ByteSink& sink, UErrorCode& status) const;
2830
2831 // To give LocalizedNumberFormatter format methods access to this class's constructor:
2832 friend class LocalizedNumberFormatter;
2833
2834 // To give C API access to internals
2835 friend struct impl::UFormattedNumberImpl;
2836};
2837
2838template<typename StringClass>
2839StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const {
2840 StringClass result;
2841 StringByteSink<StringClass> sink(&result);
2842 toDecimalNumber(sink, status);
2843 return result;
2844}
2845
2852 public:
2861
2872
2891
2913 UParseError& perror, UErrorCode& status);
2914
2919};
2920
2921} // namespace number
2922U_NAMESPACE_END
2923
2924#endif /* #if !UCONFIG_NO_FORMATTING */
2925
2926#endif /* U_SHOW_CPLUSPLUS_API */
2927
2928#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
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:206
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.
FormattedNumber()
Default constructor; makes an empty FormattedNumber.
void getAllFieldPositionsImpl(FieldPositionIteratorHandler &fpih, UErrorCode &status) const
Populates the mutable builder type FieldPositionIteratorHandler.
NounClass getNounClass(UErrorCode &status) const
Gets the noun class of the formatted output.
virtual ~FormattedNumber() U_OVERRIDE
Destruct an instance of FormattedNumber.
const char * getGender(UErrorCode &status) const
Gets the gender of the formatted output.
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) &&
Overload of unitDisplayCase() for use on an rvalue reference.
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 &
Specifies the desired case for a unit formatter's output (e.g.
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 usage(StringPiece usage) &&
Overload of usage() 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: 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.
NounClass
Represents all the grammatical noun classes that are supported by CLDR.
Definition: unounclass.h:24
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
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:467
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-compatible API for 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