ICU 74.2 74.2

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/displayoptions.h"
18 #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/unum.h"
26 #include "unicode/unumberformatter.h"
27 #include "unicode/uobject.h"
28 #include "unicode/unumberoptions.h"
29 #include "unicode/formattednumber.h"
30
89 U_NAMESPACE_BEGIN
90
91 // Forward declarations:
92 class IFixedDecimal;
93 class FieldPositionIteratorHandler;
94 class FormattedStringBuilder;
95
96 namespace numparse {
97 namespace impl {
98
99 // Forward declarations:
100 class NumberParserImpl;
101 class MultiplierParseHandler;
102
103 }
104 }
105
106 namespace units {
107
108 // Forward declarations:
109 class UnitsRouter;
110
111 } // namespace units
112
113 namespace number { // icu::number
114
115 // Forward declarations:
116 class UnlocalizedNumberFormatter;
117 class LocalizedNumberFormatter;
118 class SimpleNumberFormatter;
119 class FormattedNumber;
120 class Notation;
121 class ScientificNotation;
122 class Precision;
123 class FractionPrecision;
124 class CurrencyPrecision;
125 class IncrementPrecision;
126 class IntegerWidth;
127
128 namespace impl {
129
130 // can't be #ifndef U_HIDE_INTERNAL_API; referenced throughout this file in public classes
136 typedef int16_t digits_t;
137
138 // can't be #ifndef U_HIDE_INTERNAL_API; needed for struct initialization
145 static constexpr int32_t kInternalDefaultThreshold = 3;
146
147 // Forward declarations:
148 class Padder;
149 struct MacroProps;
150 struct MicroProps;
151 class DecimalQuantity;
152 class UFormattedNumberData;
153 class NumberFormatterImpl;
154 struct ParsedPatternInfo;
155 class ScientificModifier;
156 class MultiplierProducer;
157 class RoundingImpl;
158 class ScientificHandler;
159 class Modifier;
160 class AffixPatternProvider;
161 class NumberPropertyMapper;
162 struct DecimalFormatProperties;
163 class MultiplierFormatHandler;
164 class CurrencySymbols;
165 class GeneratorHelpers;
166 class DecNum;
167 class NumberRangeFormatterImpl;
168 struct RangeMacroProps;
169 struct UFormattedNumberImpl;
170 class MutablePatternModifier;
171 class ImmutablePatternModifier;
172 struct DecimalFormatWarehouse;
173 struct SimpleMicroProps;
174 class AdoptingSignumModifierStore;
175
182 void touchRangeLocales(impl::RangeMacroProps& macros);
183
184 } // namespace impl
185
191 typedef Notation CompactNotation;
192
198 typedef Notation SimpleNotation;
199
205 class U_I18N_API Notation : public UMemory {
206 public:
231 static ScientificNotation scientific();
232
255 static ScientificNotation engineering();
256
298 static CompactNotation compactShort();
299
322 static CompactNotation compactLong();
323
348 static SimpleNotation simple();
349
350 private:
351 enum NotationType {
352 NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
353 } fType;
354
355 union NotationUnion {
356 // For NTN_SCIENTIFIC
358 struct ScientificSettings {
360 int8_t fEngineeringInterval;
362 bool fRequireMinInt;
364 impl::digits_t fMinExponentDigits;
366 UNumberSignDisplay fExponentSignDisplay;
367 } scientific;
368
369 // For NTN_COMPACT
370 UNumberCompactStyle compactStyle;
371
372 // For NTN_ERROR
373 UErrorCode errorCode;
374 } fUnion;
375
376 typedef NotationUnion::ScientificSettings ScientificSettings;
377
378 Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
379
380 Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
381 fUnion.errorCode = errorCode;
382 }
383
384 Notation() : fType(NTN_SIMPLE), fUnion() {}
385
386 UBool copyErrorTo(UErrorCode &status) const {
387 if (fType == NTN_ERROR) {
388 status = fUnion.errorCode;
389 return true;
390 }
391 return false;
392 }
393
394 // To allow MacroProps to initialize empty instances:
395 friend struct impl::MacroProps;
396 friend class ScientificNotation;
397
398 // To allow implementation to access internal types:
399 friend class impl::NumberFormatterImpl;
400 friend class impl::ScientificModifier;
401 friend class impl::ScientificHandler;
402
403 // To allow access to the skeleton generation code:
404 friend class impl::GeneratorHelpers;
405 };
406
415 class U_I18N_API ScientificNotation : public Notation {
416 public:
430 ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
431
445 ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const;
446
447 private:
448 // Inherit constructor
449 using Notation::Notation;
450
451 // Raw constructor for NumberPropertyMapper
452 ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
453 UNumberSignDisplay fExponentSignDisplay);
454
455 friend class Notation;
456
457 // So that NumberPropertyMapper can create instances
458 friend class impl::NumberPropertyMapper;
459 };
460
466 typedef Precision SignificantDigitsPrecision;
467
476 class U_I18N_API Precision : public UMemory {
477
478 public:
496 static Precision unlimited();
497
504 static FractionPrecision integer();
505
533 static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
534
548 static FractionPrecision minFraction(int32_t minFractionPlaces);
549
560 static FractionPrecision maxFraction(int32_t maxFractionPlaces);
561
575 static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
576
590 static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
591
604 static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
605
614 static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
615
627 static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
628 int32_t maxSignificantDigits);
629
649 static IncrementPrecision increment(double roundingIncrement);
650
674 static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude);
675
693 static CurrencyPrecision currency(UCurrencyUsage currencyUsage);
694
702 Precision trailingZeroDisplay(UNumberTrailingZeroDisplay trailingZeroDisplay) const;
703
704 private:
705 enum PrecisionType {
706 RND_BOGUS,
707 RND_NONE,
708 RND_FRACTION,
709 RND_SIGNIFICANT,
710 RND_FRACTION_SIGNIFICANT,
711
712 // Used for strange increments like 3.14.
713 RND_INCREMENT,
714
715 // Used for increments with 1 as the only digit. This is different than fraction
716 // rounding because it supports having additional trailing zeros. For example, this
717 // class is used to round with the increment 0.010.
718 RND_INCREMENT_ONE,
719
720 // Used for increments with 5 as the only digit (nickel rounding).
721 RND_INCREMENT_FIVE,
722
723 RND_CURRENCY,
724 RND_ERROR
725 } fType;
726
727 union PrecisionUnion {
729 struct FractionSignificantSettings {
730 // For RND_FRACTION, RND_SIGNIFICANT, and RND_FRACTION_SIGNIFICANT
732 impl::digits_t fMinFrac;
734 impl::digits_t fMaxFrac;
736 impl::digits_t fMinSig;
738 impl::digits_t fMaxSig;
740 UNumberRoundingPriority fPriority;
745 bool fRetain;
746 } fracSig;
748 struct IncrementSettings {
749 // For RND_INCREMENT, RND_INCREMENT_ONE, and RND_INCREMENT_FIVE
750 // Note: This is a union, so we shouldn't own memory, since
751 // the default destructor would leak it.
753 uint64_t fIncrement;
755 impl::digits_t fIncrementMagnitude;
757 impl::digits_t fMinFrac;
758 } increment;
759 UCurrencyUsage currencyUsage; // For RND_CURRENCY
760 UErrorCode errorCode; // For RND_ERROR
761 } fUnion;
762
763 UNumberTrailingZeroDisplay fTrailingZeroDisplay = UNUM_TRAILING_ZERO_AUTO;
764
765 typedef PrecisionUnion::FractionSignificantSettings FractionSignificantSettings;
766 typedef PrecisionUnion::IncrementSettings IncrementSettings;
767
768 Precision(const PrecisionType& type, const PrecisionUnion& union_)
769 : fType(type), fUnion(union_) {}
770
771 Precision(UErrorCode errorCode) : fType(RND_ERROR) {
772 fUnion.errorCode = errorCode;
773 }
774
775 Precision() : fType(RND_BOGUS) {}
776
777 bool isBogus() const {
778 return fType == RND_BOGUS;
779 }
780
781 UBool copyErrorTo(UErrorCode &status) const {
782 if (fType == RND_ERROR) {
783 status = fUnion.errorCode;
784 return true;
785 }
786 return false;
787 }
788
789 // On the parent type so that this method can be called internally on Precision instances.
790 Precision withCurrency(const CurrencyUnit &currency, UErrorCode &status) const;
791
792 static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
793
794 static Precision constructSignificant(int32_t minSig, int32_t maxSig);
795
796 static Precision constructFractionSignificant(
797 const FractionPrecision &base,
798 int32_t minSig,
799 int32_t maxSig,
800 UNumberRoundingPriority priority,
801 bool retain);
802
803 static IncrementPrecision constructIncrement(uint64_t increment, impl::digits_t magnitude);
804
805 static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
806
807 // To allow MacroProps/MicroProps to initialize bogus instances:
808 friend struct impl::MacroProps;
809 friend struct impl::MicroProps;
810
811 // To allow NumberFormatterImpl to access isBogus() and other internal methods:
812 friend class impl::NumberFormatterImpl;
813
814 // To allow NumberPropertyMapper to create instances from DecimalFormatProperties:
815 friend class impl::NumberPropertyMapper;
816
817 // To allow access to the main implementation class:
818 friend class impl::RoundingImpl;
819
820 // To allow child classes to call private methods:
821 friend class FractionPrecision;
822 friend class CurrencyPrecision;
823 friend class IncrementPrecision;
824
825 // To allow access to the skeleton generation code:
826 friend class impl::GeneratorHelpers;
827
828 // To allow access to isBogus and the default (bogus) constructor:
829 friend class units::UnitsRouter;
830 };
831
841 class U_I18N_API FractionPrecision : public Precision {
842 public:
857 Precision withSignificantDigits(
858 int32_t minSignificantDigits,
859 int32_t maxSignificantDigits,
860 UNumberRoundingPriority priority) const;
861
879 Precision withMinDigits(int32_t minSignificantDigits) const;
880
898 Precision withMaxDigits(int32_t maxSignificantDigits) const;
899
900 private:
901 // Inherit constructor
902 using Precision::Precision;
903
904 // To allow parent class to call this class's constructor:
905 friend class Precision;
906 };
907
917 class U_I18N_API CurrencyPrecision : public Precision {
918 public:
936 Precision withCurrency(const CurrencyUnit &currency) const;
937
938 private:
939 // Inherit constructor
940 using Precision::Precision;
941
942 // To allow parent class to call this class's constructor:
943 friend class Precision;
944 };
945
955 class U_I18N_API IncrementPrecision : public Precision {
956 public:
972 Precision withMinFraction(int32_t minFrac) const;
973
974 private:
975 // Inherit constructor
976 using Precision::Precision;
977
978 // To allow parent class to call this class's constructor:
979 friend class Precision;
980 };
981
991 class U_I18N_API IntegerWidth : public UMemory {
992 public:
1004 static IntegerWidth zeroFillTo(int32_t minInt);
1005
1017 IntegerWidth truncateAt(int32_t maxInt);
1018
1019 private:
1020 union {
1021 struct {
1022 impl::digits_t fMinInt;
1023 impl::digits_t fMaxInt;
1024 bool fFormatFailIfMoreThanMaxDigits;
1025 } minMaxInt;
1026 UErrorCode errorCode;
1027 } fUnion;
1028 bool fHasError = false;
1029
1030 IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
1031
1032 IntegerWidth(UErrorCode errorCode) { // NOLINT
1033 fUnion.errorCode = errorCode;
1034 fHasError = true;
1035 }
1036
1037 IntegerWidth() { // NOLINT
1038 fUnion.minMaxInt.fMinInt = -1;
1039 }
1040
1042 static IntegerWidth standard() {
1043 return IntegerWidth::zeroFillTo(1);
1044 }
1045
1046 bool isBogus() const {
1047 return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1048 }
1049
1050 UBool copyErrorTo(UErrorCode &status) const {
1051 if (fHasError) {
1052 status = fUnion.errorCode;
1053 return true;
1054 }
1055 return false;
1056 }
1057
1058 void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
1059
1060 bool operator==(const IntegerWidth& other) const;
1061
1062 // To allow MacroProps/MicroProps to initialize empty instances:
1063 friend struct impl::MacroProps;
1064 friend struct impl::MicroProps;
1065
1066 // To allow NumberFormatterImpl to access isBogus():
1067 friend class impl::NumberFormatterImpl;
1068
1069 // To allow the use of this class when formatting:
1070 friend class impl::MutablePatternModifier;
1071 friend class impl::ImmutablePatternModifier;
1072
1073 // So that NumberPropertyMapper can create instances
1074 friend class impl::NumberPropertyMapper;
1075
1076 // To allow access to the skeleton generation code:
1077 friend class impl::GeneratorHelpers;
1078 };
1079
1088 class U_I18N_API Scale : public UMemory {
1089 public:
1096 static Scale none();
1097
1108 static Scale powerOfTen(int32_t power);
1109
1122 static Scale byDecimal(StringPiece multiplicand);
1123
1132 static Scale byDouble(double multiplicand);
1133
1140 static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
1141
1142 // We need a custom destructor for the DecNum, which means we need to declare
1143 // the copy/move constructor/assignment quartet.
1144
1146 Scale(const Scale& other);
1147
1149 Scale& operator=(const Scale& other);
1150
1152 Scale(Scale&& src) noexcept;
1153
1155 Scale& operator=(Scale&& src) noexcept;
1156
1158 ~Scale();
1159
1160 #ifndef U_HIDE_INTERNAL_API
1162 Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1163 #endif /* U_HIDE_INTERNAL_API */
1164
1165 private:
1166 int32_t fMagnitude;
1167 impl::DecNum* fArbitrary;
1168 UErrorCode fError;
1169
1170 Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
1171
1172 Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
1173
1174 bool isValid() const {
1175 return fMagnitude != 0 || fArbitrary != nullptr;
1176 }
1177
1178 UBool copyErrorTo(UErrorCode &status) const {
1179 if (U_FAILURE(fError)) {
1180 status = fError;
1181 return true;
1182 }
1183 return false;
1184 }
1185
1186 void applyTo(impl::DecimalQuantity& quantity) const;
1187
1188 void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
1189
1190 // To allow MacroProps/MicroProps to initialize empty instances:
1191 friend struct impl::MacroProps;
1192 friend struct impl::MicroProps;
1193
1194 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1195 friend class impl::NumberFormatterImpl;
1196
1197 // To allow the helper class MultiplierFormatHandler access to private fields:
1198 friend class impl::MultiplierFormatHandler;
1199
1200 // To allow access to the skeleton generation code:
1201 friend class impl::GeneratorHelpers;
1202
1203 // To allow access to parsing code:
1204 friend class ::icu::numparse::impl::NumberParserImpl;
1205 friend class ::icu::numparse::impl::MultiplierParseHandler;
1206 };
1207
1208 namespace impl {
1209
1210 // Do not enclose entire StringProp with #ifndef U_HIDE_INTERNAL_API, needed for a protected field.
1211 // And do not enclose its class boilerplate within #ifndef U_HIDE_INTERNAL_API.
1216 class U_I18N_API StringProp : public UMemory {
1217
1218 public:
1220 ~StringProp();
1221
1223 StringProp(const StringProp &other);
1224
1226 StringProp &operator=(const StringProp &other);
1227
1228 #ifndef U_HIDE_INTERNAL_API
1229
1231 StringProp(StringProp &&src) noexcept;
1232
1234 StringProp &operator=(StringProp &&src) noexcept;
1235
1237 int16_t length() const {
1238 return fLength;
1239 }
1240
1244 void set(StringPiece value);
1245
1247 bool isSet() const {
1248 return fLength > 0;
1249 }
1250
1251 #endif // U_HIDE_INTERNAL_API
1252
1253 private:
1254 char *fValue;
1255 int16_t fLength;
1256 UErrorCode fError;
1257
1258 StringProp() : fValue(nullptr), fLength(0), fError(U_ZERO_ERROR) {
1259 }
1260
1262 UBool copyErrorTo(UErrorCode &status) const {
1263 if (U_FAILURE(fError)) {
1264 status = fError;
1265 return true;
1266 }
1267 return false;
1268 }
1269
1270 // Allow NumberFormatterImpl to access fValue.
1271 friend class impl::NumberFormatterImpl;
1272
1273 // Allow skeleton generation code to access private members.
1274 friend class impl::GeneratorHelpers;
1275
1276 // Allow MacroProps/MicroProps to initialize empty instances and to call
1277 // copyErrorTo().
1278 friend struct impl::MacroProps;
1279 };
1280
1281 // Do not enclose entire SymbolsWrapper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1283 class U_I18N_API SymbolsWrapper : public UMemory {
1284 public:
1286 SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
1287
1289 SymbolsWrapper(const SymbolsWrapper &other);
1290
1292 SymbolsWrapper &operator=(const SymbolsWrapper &other);
1293
1295 SymbolsWrapper(SymbolsWrapper&& src) noexcept;
1296
1298 SymbolsWrapper &operator=(SymbolsWrapper&& src) noexcept;
1299
1301 ~SymbolsWrapper();
1302
1303 #ifndef U_HIDE_INTERNAL_API
1304
1309 void setTo(const DecimalFormatSymbols &dfs);
1310
1315 void setTo(const NumberingSystem *ns);
1316
1321 bool isDecimalFormatSymbols() const;
1322
1327 bool isNumberingSystem() const;
1328
1333 const DecimalFormatSymbols *getDecimalFormatSymbols() const;
1334
1339 const NumberingSystem *getNumberingSystem() const;
1340
1341 #endif // U_HIDE_INTERNAL_API
1342
1344 UBool copyErrorTo(UErrorCode &status) const {
1345 if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
1346 status = U_MEMORY_ALLOCATION_ERROR;
1347 return true;
1348 } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
1349 status = U_MEMORY_ALLOCATION_ERROR;
1350 return true;
1351 }
1352 return false;
1353 }
1354
1355 private:
1356 enum SymbolsPointerType {
1357 SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1358 } fType;
1359
1360 union {
1361 const DecimalFormatSymbols *dfs;
1362 const NumberingSystem *ns;
1363 } fPtr;
1364
1365 void doCopyFrom(const SymbolsWrapper &other);
1366
1367 void doMoveFrom(SymbolsWrapper&& src);
1368
1369 void doCleanup();
1370 };
1371
1372 // Do not enclose entire Grouper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1374 class U_I18N_API Grouper : public UMemory {
1375 public:
1376 #ifndef U_HIDE_INTERNAL_API
1378 static Grouper forStrategy(UNumberGroupingStrategy grouping);
1379
1384 static Grouper forProperties(const DecimalFormatProperties& properties);
1385
1386 // Future: static Grouper forProperties(DecimalFormatProperties& properties);
1387
1389 Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
1390 : fGrouping1(grouping1),
1391 fGrouping2(grouping2),
1392 fMinGrouping(minGrouping),
1393 fStrategy(strategy) {}
1394
1396 int16_t getPrimary() const;
1397
1399 int16_t getSecondary() const;
1400 #endif // U_HIDE_INTERNAL_API
1401
1402 private:
1411 int16_t fGrouping1;
1412 int16_t fGrouping2;
1413
1421 int16_t fMinGrouping;
1422
1427 UNumberGroupingStrategy fStrategy;
1428
1429 Grouper() : fGrouping1(-3) {}
1430
1431 bool isBogus() const {
1432 return fGrouping1 == -3;
1433 }
1434
1436 void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
1437
1438 bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
1439
1440 // To allow MacroProps/MicroProps to initialize empty instances:
1441 friend struct MacroProps;
1442 friend struct MicroProps;
1443 friend struct SimpleMicroProps;
1444
1445 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1446 friend class NumberFormatterImpl;
1447 friend class ::icu::number::SimpleNumberFormatter;
1448
1449 // To allow NumberParserImpl to perform setLocaleData():
1450 friend class ::icu::numparse::impl::NumberParserImpl;
1451
1452 // To allow access to the skeleton generation code:
1453 friend class impl::GeneratorHelpers;
1454 };
1455
1456 // Do not enclose entire Padder with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1458 class U_I18N_API Padder : public UMemory {
1459 public:
1460 #ifndef U_HIDE_INTERNAL_API
1462 static Padder none();
1463
1465 static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
1466
1468 static Padder forProperties(const DecimalFormatProperties& properties);
1469 #endif // U_HIDE_INTERNAL_API
1470
1471 private:
1472 UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding
1473 union {
1474 struct {
1475 int32_t fCp;
1476 UNumberFormatPadPosition fPosition;
1477 } padding;
1478 UErrorCode errorCode;
1479 } fUnion;
1480
1481 Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
1482
1483 Padder(int32_t width);
1484
1485 Padder(UErrorCode errorCode) : fWidth(-3) { // NOLINT
1486 fUnion.errorCode = errorCode;
1487 }
1488
1489 Padder() : fWidth(-2) {} // NOLINT
1490
1491 bool isBogus() const {
1492 return fWidth == -2;
1493 }
1494
1495 UBool copyErrorTo(UErrorCode &status) const {
1496 if (fWidth == -3) {
1497 status = fUnion.errorCode;
1498 return true;
1499 }
1500 return false;
1501 }
1502
1503 bool isValid() const {
1504 return fWidth > 0;
1505 }
1506
1507 int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
1508 FormattedStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
1509 UErrorCode &status) const;
1510
1511 // To allow MacroProps/MicroProps to initialize empty instances:
1512 friend struct MacroProps;
1513 friend struct MicroProps;
1514
1515 // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1516 friend class impl::NumberFormatterImpl;
1517
1518 // To allow access to the skeleton generation code:
1519 friend class impl::GeneratorHelpers;
1520 };
1521
1522 // Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1524 struct U_I18N_API MacroProps : public UMemory {
1526 Notation notation;
1527
1529 MeasureUnit unit; // = MeasureUnit(); (the base dimensionless unit)
1530
1532 MeasureUnit perUnit; // = MeasureUnit(); (the base dimensionless unit)
1533
1535 Precision precision; // = Precision(); (bogus)
1536
1538 UNumberFormatRoundingMode roundingMode = UNUM_ROUND_HALFEVEN;
1539
1541 Grouper grouper; // = Grouper(); (bogus)
1542
1544 Padder padder; // = Padder(); (bogus)
1545
1547 IntegerWidth integerWidth; // = IntegerWidth(); (bogus)
1548
1550 SymbolsWrapper symbols;
1551
1552 // UNUM_XYZ_COUNT denotes null (bogus) values.
1553
1555 UNumberUnitWidth unitWidth = UNUM_UNIT_WIDTH_COUNT;
1556
1558 UNumberSignDisplay sign = UNUM_SIGN_COUNT;
1559
1561 bool approximately = false;
1562
1564 UNumberDecimalSeparatorDisplay decimal = UNUM_DECIMAL_SEPARATOR_COUNT;
1565
1567 Scale scale; // = Scale(); (benign value)
1568
1570 StringProp usage; // = StringProp(); (no usage)
1571
1573 StringProp unitDisplayCase; // = StringProp(); (nominative)
1574
1576 const AffixPatternProvider* affixProvider = nullptr; // no ownership
1577
1579 const PluralRules* rules = nullptr; // no ownership
1580
1582 int32_t threshold = kInternalDefaultThreshold;
1583
1585 Locale locale;
1586
1587 // NOTE: Uses default copy and move constructors.
1588
1593 bool copyErrorTo(UErrorCode &status) const {
1594 return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1595 padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1596 symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1597 unitDisplayCase.copyErrorTo(status);
1598 }
1599 };
1600
1601 } // namespace impl
1602
1603 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1604 // Ignore MSVC warning 4661. This is generated for NumberFormatterSettings<>::toSkeleton() as this method
1605 // is defined elsewhere (in number_skeletons.cpp). The compiler is warning that the explicit template instantiation
1606 // inside this single translation unit (CPP file) is incomplete, and thus it isn't sure if the template class is
1607 // fully defined. However, since each translation unit explicitly instantiates all the necessary template classes,
1608 // they will all be passed to the linker, and the linker will still find and export all the class members.
1609 #pragma warning(push)
1610 #pragma warning(disable: 4661)
1611 #endif
1612
1618 template<typename Derived>
1619 class U_I18N_API NumberFormatterSettings {
1620 public:
1649 Derived notation(const Notation &notation) const &;
1650
1660 Derived notation(const Notation &notation) &&;
1661
1710 Derived unit(const icu::MeasureUnit &unit) const &;
1711
1721 Derived unit(const icu::MeasureUnit &unit) &&;
1722
1736 Derived adoptUnit(icu::MeasureUnit *unit) const &;
1737
1747 Derived adoptUnit(icu::MeasureUnit *unit) &&;
1748
1771 Derived perUnit(const icu::MeasureUnit &perUnit) const &;
1772
1782 Derived perUnit(const icu::MeasureUnit &perUnit) &&;
1783
1797 Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
1798
1808 Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
1809
1840 Derived precision(const Precision& precision) const &;
1841
1851 Derived precision(const Precision& precision) &&;
1852
1871 Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
1872
1881 Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
1882
1910 Derived grouping(UNumberGroupingStrategy strategy) const &;
1911
1921 Derived grouping(UNumberGroupingStrategy strategy) &&;
1922
1947 Derived integerWidth(const IntegerWidth &style) const &;
1948
1958 Derived integerWidth(const IntegerWidth &style) &&;
1959
2000 Derived symbols(const DecimalFormatSymbols &symbols) const &;
2001
2011 Derived symbols(const DecimalFormatSymbols &symbols) &&;
2012
2046 Derived adoptSymbols(NumberingSystem *symbols) const &;
2047
2057 Derived adoptSymbols(NumberingSystem *symbols) &&;
2058
2084 Derived unitWidth(UNumberUnitWidth width) const &;
2085
2095 Derived unitWidth(UNumberUnitWidth width) &&;
2096
2122 Derived sign(UNumberSignDisplay style) const &;
2123
2133 Derived sign(UNumberSignDisplay style) &&;
2134
2160 Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
2161
2171 Derived decimal(UNumberDecimalSeparatorDisplay style) &&;
2172
2197 Derived scale(const Scale &scale) const &;
2198
2208 Derived scale(const Scale &scale) &&;
2209
2252 Derived usage(StringPiece usage) const &;
2253
2261 Derived usage(StringPiece usage) &&;
2262
2271 Derived displayOptions(const DisplayOptions &displayOptions) const &;
2272
2280 Derived displayOptions(const DisplayOptions &displayOptions) &&;
2281
2282 #ifndef U_HIDE_INTERNAL_API
2293 Derived unitDisplayCase(StringPiece unitDisplayCase) const &;
2294
2304 Derived unitDisplayCase(StringPiece unitDisplayCase) &&;
2305 #endif // U_HIDE_INTERNAL_API
2306
2307 #ifndef U_HIDE_INTERNAL_API
2308
2314 Derived padding(const impl::Padder &padder) const &;
2315
2317 Derived padding(const impl::Padder &padder) &&;
2318
2325 Derived threshold(int32_t threshold) const &;
2326
2328 Derived threshold(int32_t threshold) &&;
2329
2335 Derived macros(const impl::MacroProps& macros) const &;
2336
2338 Derived macros(const impl::MacroProps& macros) &&;
2339
2341 Derived macros(impl::MacroProps&& macros) const &;
2342
2344 Derived macros(impl::MacroProps&& macros) &&;
2345
2346 #endif /* U_HIDE_INTERNAL_API */
2347
2365 UnicodeString toSkeleton(UErrorCode& status) const;
2366
2378 LocalPointer<Derived> clone() const &;
2379
2387 LocalPointer<Derived> clone() &&;
2388
2395 UBool copyErrorTo(UErrorCode &outErrorCode) const {
2396 if (U_FAILURE(outErrorCode)) {
2397 // Do not overwrite the older error code
2398 return true;
2399 }
2400 fMacros.copyErrorTo(outErrorCode);
2401 return U_FAILURE(outErrorCode);
2402 }
2403
2404 // NOTE: Uses default copy and move constructors.
2405
2406 private:
2407 impl::MacroProps fMacros;
2408
2409 // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
2410 NumberFormatterSettings() = default;
2411
2412 friend class LocalizedNumberFormatter;
2413 friend class UnlocalizedNumberFormatter;
2414
2415 // Give NumberRangeFormatter access to the MacroProps
2416 friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
2417 friend class impl::NumberRangeFormatterImpl;
2418 };
2419
2420 // Explicit instantiations in source/i18n/number_fluent.cpp.
2421 // (MSVC treats imports/exports of explicit instantiations differently.)
2422 #ifndef _MSC_VER
2423 extern template class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2424 extern template class NumberFormatterSettings<LocalizedNumberFormatter>;
2425 #endif
2426
2435 class U_I18N_API UnlocalizedNumberFormatter
2436 : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
2437
2438 public:
2448 LocalizedNumberFormatter locale(const icu::Locale &locale) const &;
2449
2459 LocalizedNumberFormatter locale(const icu::Locale &locale) &&;
2460
2466 UnlocalizedNumberFormatter() = default;
2467
2472 UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other);
2473
2479 UnlocalizedNumberFormatter(UnlocalizedNumberFormatter&& src) noexcept;
2480
2485 UnlocalizedNumberFormatter& operator=(const UnlocalizedNumberFormatter& other);
2486
2492 UnlocalizedNumberFormatter& operator=(UnlocalizedNumberFormatter&& src) noexcept;
2493
2494 private:
2495 explicit UnlocalizedNumberFormatter(const NumberFormatterSettings<UnlocalizedNumberFormatter>& other);
2496
2497 explicit UnlocalizedNumberFormatter(
2498 NumberFormatterSettings<UnlocalizedNumberFormatter>&& src) noexcept;
2499
2500 // To give the fluent setters access to this class's constructor:
2501 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2502
2503 // To give NumberFormatter::with() access to this class's constructor:
2504 friend class NumberFormatter;
2505 };
2506
2515 class U_I18N_API LocalizedNumberFormatter
2516 : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
2517 public:
2529 FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
2530
2542 FormattedNumber formatDouble(double value, UErrorCode &status) const;
2543
2558 FormattedNumber formatDecimal(StringPiece value, UErrorCode& status) const;
2559
2560 #ifndef U_HIDE_INTERNAL_API
2561
2562
2566 const DecimalFormatSymbols* getDecimalFormatSymbols() const;
2567
2571 FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
2572
2576 void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
2577
2582 const impl::NumberFormatterImpl* getCompiled() const;
2583
2588 int32_t getCallCount() const;
2589
2590 #endif /* U_HIDE_INTERNAL_API */
2591
2605 Format* toFormat(UErrorCode& status) const;
2606
2612 LocalizedNumberFormatter() = default;
2613
2618 LocalizedNumberFormatter(const LocalizedNumberFormatter &other);
2619
2625 LocalizedNumberFormatter(LocalizedNumberFormatter&& src) noexcept;
2626
2631 LocalizedNumberFormatter& operator=(const LocalizedNumberFormatter& other);
2632
2638 LocalizedNumberFormatter& operator=(LocalizedNumberFormatter&& src) noexcept;
2639
2640 #ifndef U_HIDE_INTERNAL_API
2641
2654 void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
2655
2656 #endif /* U_HIDE_INTERNAL_API */
2657
2662 ~LocalizedNumberFormatter();
2663
2664 private:
2665 // Note: fCompiled can't be a LocalPointer because impl::NumberFormatterImpl is defined in an internal
2666 // header, and LocalPointer needs the full class definition in order to delete the instance.
2667 const impl::NumberFormatterImpl* fCompiled {nullptr};
2668 char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t
2669
2670 // Owned pointer to a DecimalFormatWarehouse, used when copying a LocalizedNumberFormatter
2671 // from a DecimalFormat.
2672 const impl::DecimalFormatWarehouse* fWarehouse {nullptr};
2673
2674 explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
2675
2676 explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) noexcept;
2677
2678 LocalizedNumberFormatter(const impl::MacroProps &macros, const Locale &locale);
2679
2680 LocalizedNumberFormatter(impl::MacroProps &&macros, const Locale &locale);
2681
2682 void resetCompiled();
2683
2684 void lnfMoveHelper(LocalizedNumberFormatter&& src);
2685
2686 void lnfCopyHelper(const LocalizedNumberFormatter& src, UErrorCode& status);
2687
2691 bool computeCompiled(UErrorCode& status) const;
2692
2693 // To give the fluent setters access to this class's constructor:
2694 friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2695 friend class NumberFormatterSettings<LocalizedNumberFormatter>;
2696
2697 // To give UnlocalizedNumberFormatter::locale() access to this class's constructor:
2698 friend class UnlocalizedNumberFormatter;
2699 };
2700
2701 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2702 // Warning 4661.
2703 #pragma warning(pop)
2704 #endif
2705
2711 class U_I18N_API NumberFormatter final {
2712 public:
2720 static UnlocalizedNumberFormatter with();
2721
2731 static LocalizedNumberFormatter withLocale(const Locale &locale);
2732
2750 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton, UErrorCode& status);
2751
2772 static UnlocalizedNumberFormatter forSkeleton(const UnicodeString& skeleton,
2773 UParseError& perror, UErrorCode& status);
2774
2778 NumberFormatter() = delete;
2779 };
2780
2781 } // namespace number
2782 U_NAMESPACE_END
2783
2784 #endif /* #if !UCONFIG_NO_FORMATTING */
2785
2786 #endif /* U_SHOW_CPLUSPLUS_API */
2787
2788 #endif // __NUMBERFORMATTER_H__
appendable.h
C++ API: Appendable class: Sink for Unicode code points and 16-bit code units (char16_ts).
bytestream.h
C++ API: Interface for writing bytes, and implementation classes.
icu::CurrencyUnit
A unit of currency, such as USD (U.S.
Definition: currunit.h:39
icu::DecimalFormatSymbols
This class represents the set of symbols needed by DecimalFormat to format numbers.
Definition: dcfmtsym.h:86
icu::DisplayOptions
Represents all the display options that are supported by CLDR such as grammatical case,...
Definition: displayoptions.h:43
icu::Format
Base class for all formats.
Definition: format.h:98
icu::LocalPointer
"Smart pointer" class, deletes objects via the standard C++ delete operator.
Definition: localpointer.h:191
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::MeasureUnit
A unit such as length, mass, volume, currency, etc.
Definition: measunit.h:369
icu::NumberingSystem
Defines numbering systems.
Definition: numsys.h:60
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:212
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::number::CurrencyPrecision
A class that defines a rounding precision parameterized by a currency to be used when formatting numb...
Definition: numberformatter.h:917
icu::number::CurrencyPrecision::withCurrency
Precision withCurrency(const CurrencyUnit &currency) const
Associates a currency with this rounding precision.
icu::number::FormattedNumber
The result of a number formatting operation.
Definition: formattednumber.h:47
icu::number::FractionPrecision
A class that defines a rounding precision based on a number of fraction places and optionally signifi...
Definition: numberformatter.h:841
icu::number::FractionPrecision::withMinDigits
Precision withMinDigits(int32_t minSignificantDigits) const
Ensure that no less than this number of significant digits are retained when rounding according to fr...
icu::number::FractionPrecision::withSignificantDigits
Precision withSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits, UNumberRoundingPriority priority) const
Override maximum fraction digits with maximum significant digits depending on the magnitude of the nu...
icu::number::FractionPrecision::withMaxDigits
Precision withMaxDigits(int32_t maxSignificantDigits) const
Ensure that no more than this number of significant digits are retained when rounding according to fr...
icu::number::IncrementPrecision
A class that defines a rounding precision parameterized by a rounding increment to be used when forma...
Definition: numberformatter.h:955
icu::number::IncrementPrecision::withMinFraction
Precision withMinFraction(int32_t minFrac) const
Specifies the minimum number of fraction digits to render after the decimal separator,...
icu::number::IntegerWidth
A class that defines the strategy for padding and truncating integers before the decimal separator.
Definition: numberformatter.h:991
icu::number::IntegerWidth::zeroFillTo
static IntegerWidth zeroFillTo(int32_t minInt)
Pad numbers at the beginning with zeros to guarantee a certain number of numerals before the decimal ...
icu::number::IntegerWidth::truncateAt
IntegerWidth truncateAt(int32_t maxInt)
Truncate numbers exceeding a certain number of numerals before the decimal separator.
icu::number::LocalizedNumberFormatter
A NumberFormatter that has a locale associated with it; this means .format() methods are available.
Definition: numberformatter.h:2516
icu::number::LocalizedNumberFormatter::getDecimalFormatSymbols
const DecimalFormatSymbols * getDecimalFormatSymbols() const
icu::number::LocalizedNumberFormatter::getCompiled
const impl::NumberFormatterImpl * getCompiled() const
Internal method for testing.
icu::number::LocalizedNumberFormatter::operator=
LocalizedNumberFormatter & operator=(const LocalizedNumberFormatter &other)
Copy assignment operator.
icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter
LocalizedNumberFormatter(LocalizedNumberFormatter &&src) noexcept
Move constructor: The source LocalizedNumberFormatter will be left in a valid but undefined state.
icu::number::LocalizedNumberFormatter::operator=
LocalizedNumberFormatter & operator=(LocalizedNumberFormatter &&src) noexcept
Move assignment operator: The source LocalizedNumberFormatter will be left in a valid but undefined s...
icu::number::LocalizedNumberFormatter::formatInt
FormattedNumber formatInt(int64_t value, UErrorCode &status) const
Format the given integer number to a string using the settings specified in the NumberFormatter fluen...
icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter
LocalizedNumberFormatter()=default
Default constructor: puts the formatter into a valid but undefined state.
icu::number::LocalizedNumberFormatter::LocalizedNumberFormatter
LocalizedNumberFormatter(const LocalizedNumberFormatter &other)
Returns a copy of this LocalizedNumberFormatter.
icu::number::LocalizedNumberFormatter::getCallCount
int32_t getCallCount() const
Internal method for testing.
icu::number::LocalizedNumberFormatter::~LocalizedNumberFormatter
~LocalizedNumberFormatter()
Destruct this LocalizedNumberFormatter, cleaning up any memory it might own.
icu::number::LocalizedNumberFormatter::toFormat
Format * toFormat(UErrorCode &status) const
Creates a representation of this LocalizedNumberFormat as an icu::Format, enabling the use of this nu...
icu::number::LocalizedNumberFormatter::formatImpl
void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const
This is the core entrypoint to the number formatting pipeline.
icu::number::LocalizedNumberFormatter::formatDecimal
FormattedNumber formatDecimal(StringPiece value, UErrorCode &status) const
Format the given decimal number to a string using the settings specified in the NumberFormatter fluen...
icu::number::LocalizedNumberFormatter::getAffixImpl
void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString &result, UErrorCode &status) const
Internal method for DecimalFormat compatibility.
icu::number::LocalizedNumberFormatter::formatDecimalQuantity
FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity &dq, UErrorCode &status) const
Internal method.
icu::number::LocalizedNumberFormatter::formatDouble
FormattedNumber formatDouble(double value, UErrorCode &status) const
Format the given float or double to a string using the settings specified in the NumberFormatter flue...
icu::number::Notation
A class that defines the notation style to be used when formatting numbers in NumberFormatter.
Definition: numberformatter.h:205
icu::number::Notation::compactShort
static CompactNotation compactShort()
Print the number using short-form compact notation.
icu::number::Notation::engineering
static ScientificNotation engineering()
Print the number using engineering notation, a variant of scientific notation in which the exponent m...
icu::number::Notation::compactLong
static CompactNotation compactLong()
Print the number using long-form compact notation.
icu::number::Notation::simple
static SimpleNotation simple()
Print the number using simple notation without any scaling by powers of ten.
icu::number::Notation::scientific
static ScientificNotation scientific()
Print the number using scientific notation (also known as scientific form, standard index form,...
icu::number::NumberFormatterSettings
An abstract base class for specifying settings related to number formatting.
Definition: numberformatter.h:1619
icu::number::NumberFormatterSettings::unitDisplayCase
Derived unitDisplayCase(StringPiece unitDisplayCase) &&
NOTE: Use displayOptions instead.
icu::number::NumberFormatterSettings::adoptSymbols
Derived adoptSymbols(NumberingSystem *symbols) const &
Specifies that the given numbering system should be used when fetching symbols.
icu::number::NumberFormatterSettings::precision
Derived precision(const Precision &precision) const &
Specifies the rounding precision to use when formatting numbers.
icu::number::NumberFormatterSettings::decimal
Derived decimal(UNumberDecimalSeparatorDisplay style) &&
Overload of decimal() for use on an rvalue reference.
icu::number::NumberFormatterSettings::unitWidth
Derived unitWidth(UNumberUnitWidth width) const &
Sets the width of the unit (measure unit or currency).
icu::number::NumberFormatterSettings::adoptUnit
Derived adoptUnit(icu::MeasureUnit *unit) const &
Like unit(), but takes ownership of a pointer.
icu::number::NumberFormatterSettings::perUnit
Derived perUnit(const icu::MeasureUnit &perUnit) &&
Overload of perUnit() for use on an rvalue reference.
icu::number::NumberFormatterSettings::padding
Derived padding(const impl::Padder &padder) &&
icu::number::NumberFormatterSettings::adoptSymbols
Derived adoptSymbols(NumberingSystem *symbols) &&
Overload of adoptSymbols() for use on an rvalue reference.
icu::number::NumberFormatterSettings::macros
Derived macros(const impl::MacroProps &macros) &&
icu::number::NumberFormatterSettings::roundingMode
Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&
Overload of roundingMode() for use on an rvalue reference.
icu::number::NumberFormatterSettings::integerWidth
Derived integerWidth(const IntegerWidth &style) const &
Specifies the minimum and maximum number of digits to render before the decimal mark.
icu::number::NumberFormatterSettings::macros
Derived macros(const impl::MacroProps &macros) const &
Internal fluent setter to overwrite the entire macros object.
icu::number::NumberFormatterSettings::threshold
Derived threshold(int32_t threshold) const &
Internal fluent setter to support a custom regulation threshold.
icu::number::NumberFormatterSettings::perUnit
Derived perUnit(const icu::MeasureUnit &perUnit) const &
Sets a unit to be used in the denominator.
icu::number::NumberFormatterSettings::integerWidth
Derived integerWidth(const IntegerWidth &style) &&
Overload of integerWidth() for use on an rvalue reference.
icu::number::NumberFormatterSettings::unitDisplayCase
Derived unitDisplayCase(StringPiece unitDisplayCase) const &
NOTE: Use displayOptions instead.
icu::number::NumberFormatterSettings::grouping
Derived grouping(UNumberGroupingStrategy strategy) const &
Specifies the grouping strategy to use when formatting numbers.
icu::number::NumberFormatterSettings::unit
Derived unit(const icu::MeasureUnit &unit) const &
Specifies the unit (unit of measure, currency, or percent) to associate with rendered numbers.
icu::number::NumberFormatterSettings::displayOptions
Derived displayOptions(const DisplayOptions &displayOptions) const &
Specifies the DisplayOptions.
icu::number::NumberFormatterSettings::usage
Derived usage(StringPiece usage) &&
Overload of usage() for use on an rvalue reference.
icu::number::NumberFormatterSettings::displayOptions
Derived displayOptions(const DisplayOptions &displayOptions) &&
Overload of displayOptions() for use on an rvalue reference.
icu::number::NumberFormatterSettings::adoptPerUnit
Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &
Like perUnit(), but takes ownership of a pointer.
icu::number::NumberFormatterSettings::adoptUnit
Derived adoptUnit(icu::MeasureUnit *unit) &&
Overload of adoptUnit() for use on an rvalue reference.
icu::number::NumberFormatterSettings::scale
Derived scale(const Scale &scale) &&
Overload of scale() for use on an rvalue reference.
icu::number::NumberFormatterSettings::precision
Derived precision(const Precision &precision) &&
Overload of precision() for use on an rvalue reference.
icu::number::NumberFormatterSettings::symbols
Derived symbols(const DecimalFormatSymbols &symbols) &&
Overload of symbols() for use on an rvalue reference.
icu::number::NumberFormatterSettings::padding
Derived padding(const impl::Padder &padder) const &
Set the padding strategy.
icu::number::NumberFormatterSettings::notation
Derived notation(const Notation &notation) const &
Specifies the notation style (simple, scientific, or compact) for rendering numbers.
icu::number::NumberFormatterSettings::sign
Derived sign(UNumberSignDisplay style) const &
Sets the plus/minus sign display strategy.
icu::number::NumberFormatterSettings::threshold
Derived threshold(int32_t threshold) &&
icu::number::NumberFormatterSettings::roundingMode
Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &
Specifies how to determine the direction to round a number when it has more digits than fit in the de...
icu::number::NumberFormatterSettings::symbols
Derived symbols(const DecimalFormatSymbols &symbols) const &
Specifies the symbols (decimal separator, grouping separator, percent sign, numerals,...
icu::number::NumberFormatterSettings::macros
Derived macros(impl::MacroProps &&macros) &&
icu::number::NumberFormatterSettings::clone
LocalPointer< Derived > clone() const &
Returns the current (Un)LocalizedNumberFormatter as a LocalPointer wrapping a heap-allocated copy of ...
icu::number::NumberFormatterSettings::sign
Derived sign(UNumberSignDisplay style) &&
Overload of sign() for use on an rvalue reference.
icu::number::NumberFormatterSettings::toSkeleton
UnicodeString toSkeleton(UErrorCode &status) const
Creates a skeleton string representation of this number formatter.
icu::number::NumberFormatterSettings::grouping
Derived grouping(UNumberGroupingStrategy strategy) &&
Overload of grouping() for use on an rvalue reference.
icu::number::NumberFormatterSettings::usage
Derived usage(StringPiece usage) const &
Specifies the usage for which numbers will be formatted ("person-height", "road", "rainfall",...
icu::number::NumberFormatterSettings::adoptPerUnit
Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&
Overload of adoptPerUnit() for use on an rvalue reference.
icu::number::NumberFormatterSettings::unitWidth
Derived unitWidth(UNumberUnitWidth width) &&
Overload of unitWidth() for use on an rvalue reference.
icu::number::NumberFormatterSettings::decimal
Derived decimal(UNumberDecimalSeparatorDisplay style) const &
Sets the decimal separator display strategy.
icu::number::NumberFormatterSettings::unit
Derived unit(const icu::MeasureUnit &unit) &&
Overload of unit() for use on an rvalue reference.
icu::number::NumberFormatterSettings::macros
Derived macros(impl::MacroProps &&macros) const &
icu::number::NumberFormatterSettings::scale
Derived scale(const Scale &scale) const &
Sets a scale (multiplier) to be used to scale the number by an arbitrary amount before formatting.
icu::number::NumberFormatterSettings::notation
Derived notation(const Notation &notation) &&
Overload of notation() for use on an rvalue reference.
icu::number::NumberFormatter
See the main description in numberformatter.h for documentation and examples.
Definition: numberformatter.h:2711
icu::number::NumberFormatter::forSkeleton
static UnlocalizedNumberFormatter forSkeleton(const UnicodeString &skeleton, UParseError &perror, UErrorCode &status)
Call this method at the beginning of a NumberFormatter fluent chain to create an instance based on a ...
icu::number::NumberFormatter::forSkeleton
static UnlocalizedNumberFormatter forSkeleton(const UnicodeString &skeleton, UErrorCode &status)
Call this method at the beginning of a NumberFormatter fluent chain to create an instance based on a ...
icu::number::NumberFormatter::with
static UnlocalizedNumberFormatter with()
Call this method at the beginning of a NumberFormatter fluent chain in which the locale is not curren...
icu::number::NumberFormatter::NumberFormatter
NumberFormatter()=delete
Use factory methods instead of the constructor to create a NumberFormatter.
icu::number::NumberFormatter::withLocale
static LocalizedNumberFormatter withLocale(const Locale &locale)
Call this method at the beginning of a NumberFormatter fluent chain in which the locale is known at t...
icu::number::Precision
A class that defines the rounding precision to be used when formatting numbers in NumberFormatter.
Definition: numberformatter.h:476
icu::number::Precision::maxSignificantDigits
static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures.
icu::number::Precision::fixedFraction
static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
icu::number::Precision::minSignificantDigits
static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits)
Always show at least a certain number of significant digits/figures, padding with zeros if necessary.
icu::number::Precision::maxFraction
static FractionPrecision maxFraction(int32_t maxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
icu::number::Precision::increment
static IncrementPrecision increment(double roundingIncrement)
Show numbers rounded if necessary to the closest multiple of a certain rounding increment.
icu::number::Precision::currency
static CurrencyPrecision currency(UCurrencyUsage currencyUsage)
Show numbers rounded and padded according to the rules for the currency unit.
icu::number::Precision::minFraction
static FractionPrecision minFraction(int32_t minFractionPlaces)
Always show at least a certain number of fraction places after the decimal separator,...
icu::number::Precision::trailingZeroDisplay
Precision trailingZeroDisplay(UNumberTrailingZeroDisplay trailingZeroDisplay) const
Configure how trailing zeros are displayed on numbers.
icu::number::Precision::unlimited
static Precision unlimited()
Show all available digits to full precision.
icu::number::Precision::integer
static FractionPrecision integer()
Show numbers rounded if necessary to the nearest integer.
icu::number::Precision::fixedSignificantDigits
static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits or significant figures.
icu::number::Precision::incrementExact
static IncrementPrecision incrementExact(uint64_t mantissa, int16_t magnitude)
Version of Precision::increment() that takes an integer at a particular power of 10.
icu::number::Precision::minMaxFraction
static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces)
Show numbers rounded if necessary to a certain number of fraction places (numerals after the decimal ...
icu::number::Precision::minMaxSignificantDigits
static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits)
Show numbers rounded if necessary to a certain number of significant digits/figures; in addition,...
icu::number::Scale
A class that defines a quantity by which a number should be multiplied when formatting.
Definition: numberformatter.h:1088
icu::number::Scale::none
static Scale none()
Do not change the value of numbers when formatting or parsing.
icu::number::Scale::operator=
Scale & operator=(const Scale &other)
icu::number::Scale::powerOfTen
static Scale powerOfTen(int32_t power)
Multiply numbers by a power of ten before formatting.
icu::number::Scale::Scale
Scale(const Scale &other)
icu::number::Scale::byDoubleAndPowerOfTen
static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power)
Multiply a number by both a power of ten and by an arbitrary double value.
icu::number::Scale::byDecimal
static Scale byDecimal(StringPiece multiplicand)
Multiply numbers by an arbitrary value before formatting.
icu::number::Scale::Scale
Scale(int32_t magnitude, impl::DecNum *arbitraryToAdopt)
icu::number::Scale::Scale
Scale(Scale &&src) noexcept
icu::number::Scale::~Scale
~Scale()
icu::number::Scale::byDouble
static Scale byDouble(double multiplicand)
Multiply numbers by an arbitrary value before formatting.
icu::number::Scale::operator=
Scale & operator=(Scale &&src) noexcept
icu::number::ScientificNotation
A class that defines the scientific notation style to be used when formatting numbers in NumberFormat...
Definition: numberformatter.h:415
icu::number::ScientificNotation::withExponentSignDisplay
ScientificNotation withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const
Sets whether to show the sign on positive and negative exponents in scientific notation.
icu::number::ScientificNotation::withMinExponentDigits
ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const
Sets the minimum number of digits to show in the exponent of scientific notation, padding with zeros ...
icu::number::UnlocalizedNumberFormatter
A NumberFormatter that does not yet have a locale.
Definition: numberformatter.h:2436
icu::number::UnlocalizedNumberFormatter::UnlocalizedNumberFormatter
UnlocalizedNumberFormatter()=default
Default constructor: puts the formatter into a valid but undefined state.
icu::number::UnlocalizedNumberFormatter::operator=
UnlocalizedNumberFormatter & operator=(const UnlocalizedNumberFormatter &other)
Copy assignment operator.
icu::number::UnlocalizedNumberFormatter::UnlocalizedNumberFormatter
UnlocalizedNumberFormatter(const UnlocalizedNumberFormatter &other)
Returns a copy of this UnlocalizedNumberFormatter.
icu::number::UnlocalizedNumberFormatter::locale
LocalizedNumberFormatter locale(const icu::Locale &locale) &&
Overload of locale() for use on an rvalue reference.
icu::number::UnlocalizedNumberFormatter::UnlocalizedNumberFormatter
UnlocalizedNumberFormatter(UnlocalizedNumberFormatter &&src) noexcept
Move constructor: The source UnlocalizedNumberFormatter will be left in a valid but undefined state.
icu::number::UnlocalizedNumberFormatter::operator=
UnlocalizedNumberFormatter & operator=(UnlocalizedNumberFormatter &&src) noexcept
Move assignment operator: The source UnlocalizedNumberFormatter will be left in a valid but undefined...
icu::number::UnlocalizedNumberFormatter::locale
LocalizedNumberFormatter locale(const icu::Locale &locale) const &
Associate the given locale with the number formatter.
icu::number::impl::Grouper
Definition: numberformatter.h:1374
icu::number::impl::Grouper::forStrategy
static Grouper forStrategy(UNumberGroupingStrategy grouping)
icu::number::impl::Grouper::Grouper
Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
Definition: numberformatter.h:1389
icu::number::impl::Grouper::getSecondary
int16_t getSecondary() const
icu::number::impl::Grouper::forProperties
static Grouper forProperties(const DecimalFormatProperties &properties)
Resolve the values in Properties to a Grouper object.
icu::number::impl::Grouper::getPrimary
int16_t getPrimary() const
icu::number::impl::Padder
Definition: numberformatter.h:1458
icu::number::impl::Padder::forProperties
static Padder forProperties(const DecimalFormatProperties &properties)
icu::number::impl::Padder::codePoints
static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position)
icu::number::impl::Padder::none
static Padder none()
icu::number::impl::StringProp
Manages NumberFormatterSettings::usage()'s char* instance on the heap.
Definition: numberformatter.h:1216
icu::number::impl::StringProp::StringProp
StringProp(StringProp &&src) noexcept
icu::number::impl::StringProp::StringProp
StringProp(const StringProp &other)
icu::number::impl::StringProp::length
int16_t length() const
Definition: numberformatter.h:1237
icu::number::impl::StringProp::isSet
bool isSet() const
Definition: numberformatter.h:1247
icu::number::impl::StringProp::~StringProp
~StringProp()
icu::number::impl::StringProp::operator=
StringProp & operator=(StringProp &&src) noexcept
icu::number::impl::StringProp::operator=
StringProp & operator=(const StringProp &other)
icu::number::impl::StringProp::set
void set(StringPiece value)
icu::number::impl::SymbolsWrapper
Definition: numberformatter.h:1283
icu::number::impl::SymbolsWrapper::SymbolsWrapper
SymbolsWrapper()
Definition: numberformatter.h:1286
icu::number::impl::SymbolsWrapper::operator=
SymbolsWrapper & operator=(const SymbolsWrapper &other)
icu::number::impl::SymbolsWrapper::getNumberingSystem
const NumberingSystem * getNumberingSystem() const
Get the NumberingSystem pointer.
icu::number::impl::SymbolsWrapper::isNumberingSystem
bool isNumberingSystem() const
Whether the object is currently holding a NumberingSystem.
icu::number::impl::SymbolsWrapper::getDecimalFormatSymbols
const DecimalFormatSymbols * getDecimalFormatSymbols() const
Get the DecimalFormatSymbols pointer.
icu::number::impl::SymbolsWrapper::~SymbolsWrapper
~SymbolsWrapper()
icu::number::impl::SymbolsWrapper::SymbolsWrapper
SymbolsWrapper(const SymbolsWrapper &other)
icu::number::impl::SymbolsWrapper::SymbolsWrapper
SymbolsWrapper(SymbolsWrapper &&src) noexcept
icu::number::impl::SymbolsWrapper::setTo
void setTo(const DecimalFormatSymbols &dfs)
The provided object is copied, but we do not adopt it.
icu::number::impl::SymbolsWrapper::operator=
SymbolsWrapper & operator=(SymbolsWrapper &&src) noexcept
icu::number::impl::SymbolsWrapper::setTo
void setTo(const NumberingSystem *ns)
Adopt the provided object.
icu::number::impl::SymbolsWrapper::copyErrorTo
UBool copyErrorTo(UErrorCode &status) const
Definition: numberformatter.h:1344
icu::number::impl::SymbolsWrapper::isDecimalFormatSymbols
bool isDecimalFormatSymbols() const
Whether the object is currently holding a DecimalFormatSymbols.
currunit.h
C++ API: Currency Unit Information.
dcfmtsym.h
C++ API: Symbols for formatting numbers.
displayoptions.h
C++ API: Display options class.
fieldpos.h
C++ API: FieldPosition identifies the fields in a formatted output.
formattednumber.h
C API: Formatted number result from various number formatting functions.
fpositer.h
C++ API: FieldPosition Iterator.
measunit.h
C++ API: A unit for measuring a quantity.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
nounit.h
C++ API: units for percent and permille.
icu::number::impl::digits_t
int16_t digits_t
Datatype for minimum/maximum fraction digits.
Definition: numberformatter.h:136
icu::number::impl::touchRangeLocales
void touchRangeLocales(impl::RangeMacroProps &macros)
Used for NumberRangeFormatter and implemented in numrange_fluent.cpp.
parseerr.h
C API: Parse Error Information.
plurrule.h
C++ API: PluralRules object.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
icu::number::Notation::NotationUnion::ScientificSettings
Definition: numberformatter.h:358
icu::number::Notation::NotationUnion::ScientificSettings::fRequireMinInt
bool fRequireMinInt
Definition: numberformatter.h:362
icu::number::Notation::NotationUnion::ScientificSettings::fMinExponentDigits
impl::digits_t fMinExponentDigits
Definition: numberformatter.h:364
icu::number::Notation::NotationUnion::ScientificSettings::fExponentSignDisplay
UNumberSignDisplay fExponentSignDisplay
Definition: numberformatter.h:366
icu::number::Notation::NotationUnion::ScientificSettings::fEngineeringInterval
int8_t fEngineeringInterval
Definition: numberformatter.h:360
icu::number::Precision::PrecisionUnion::FractionSignificantSettings
Definition: numberformatter.h:729
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fMinFrac
impl::digits_t fMinFrac
Definition: numberformatter.h:732
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fRetain
bool fRetain
Whether to retain trailing zeros based on the looser strategy.
Definition: numberformatter.h:745
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fMaxSig
impl::digits_t fMaxSig
Definition: numberformatter.h:738
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fPriority
UNumberRoundingPriority fPriority
Definition: numberformatter.h:740
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fMaxFrac
impl::digits_t fMaxFrac
Definition: numberformatter.h:734
icu::number::Precision::PrecisionUnion::FractionSignificantSettings::fMinSig
impl::digits_t fMinSig
Definition: numberformatter.h:736
icu::number::Precision::PrecisionUnion::IncrementSettings
Definition: numberformatter.h:748
icu::number::Precision::PrecisionUnion::IncrementSettings::fIncrementMagnitude
impl::digits_t fIncrementMagnitude
Definition: numberformatter.h:755
icu::number::Precision::PrecisionUnion::IncrementSettings::fIncrement
uint64_t fIncrement
Definition: numberformatter.h:753
icu::number::Precision::PrecisionUnion::IncrementSettings::fMinFrac
impl::digits_t fMinFrac
Definition: numberformatter.h:757
icu::number::impl::MacroProps
Definition: numberformatter.h:1524
icu::number::impl::MacroProps::perUnit
MeasureUnit perUnit
Definition: numberformatter.h:1532
icu::number::impl::MacroProps::scale
Scale scale
Definition: numberformatter.h:1567
icu::number::impl::MacroProps::copyErrorTo
bool copyErrorTo(UErrorCode &status) const
Check all members for errors.
Definition: numberformatter.h:1593
icu::number::impl::MacroProps::usage
StringProp usage
Definition: numberformatter.h:1570
icu::number::impl::MacroProps::unitDisplayCase
StringProp unitDisplayCase
Definition: numberformatter.h:1573
icu::number::impl::MacroProps::locale
Locale locale
Definition: numberformatter.h:1585
icu::number::impl::MacroProps::precision
Precision precision
Definition: numberformatter.h:1535
icu::number::impl::MacroProps::integerWidth
IntegerWidth integerWidth
Definition: numberformatter.h:1547
icu::number::impl::MacroProps::padder
Padder padder
Definition: numberformatter.h:1544
icu::number::impl::MacroProps::grouper
Grouper grouper
Definition: numberformatter.h:1541
icu::number::impl::MacroProps::unit
MeasureUnit unit
Definition: numberformatter.h:1529
icu::number::impl::MacroProps::notation
Notation notation
Definition: numberformatter.h:1526
icu::number::impl::MacroProps::symbols
SymbolsWrapper symbols
Definition: numberformatter.h:1550
icu::number::impl::RangeMacroProps
Definition: numberrangeformatter.h:93
ucurr.h
C API: Encapsulates information about a currency.
UCurrencyUsage
UCurrencyUsage
Currency Usage used for Decimal Format.
Definition: ucurr.h:41
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:435
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
unum.h
C API: Compatibility APIs for number formatting.
UNumberCompactStyle
UNumberCompactStyle
Constants for specifying short or long format.
Definition: unum.h:289
UNumberFormatPadPosition
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:278
unumberformatter.h
C API: Localized number formatting; not recommended for C++.
UNumberRoundingPriority
UNumberRoundingPriority
An enum declaring how to resolve conflicts between maximum fraction digits and maximum significant di...
Definition: unumberformatter.h:118
UNumberSignDisplay
UNumberSignDisplay
An enum declaring how to denote positive and negative numbers.
Definition: unumberformatter.h:264
UNUM_SIGN_COUNT
@ UNUM_SIGN_COUNT
One more than the highest UNumberSignDisplay value.
Definition: unumberformatter.h:355
UNumberDecimalSeparatorDisplay
UNumberDecimalSeparatorDisplay
An enum declaring how to render the decimal separator.
Definition: unumberformatter.h:369
UNUM_DECIMAL_SEPARATOR_COUNT
@ UNUM_DECIMAL_SEPARATOR_COUNT
One more than the highest UNumberDecimalSeparatorDisplay value.
Definition: unumberformatter.h:392
UNumberTrailingZeroDisplay
UNumberTrailingZeroDisplay
An enum declaring how to render trailing zeros.
Definition: unumberformatter.h:403
UNUM_TRAILING_ZERO_AUTO
@ UNUM_TRAILING_ZERO_AUTO
Display trailing zeros according to the settings for minimum fraction and significant digits.
Definition: unumberformatter.h:409
UNumberUnitWidth
UNumberUnitWidth
An enum declaring how to render units, including currencies.
Definition: unumberformatter.h:152
UNUM_UNIT_WIDTH_COUNT
@ UNUM_UNIT_WIDTH_COUNT
One more than the highest UNumberUnitWidth value.
Definition: unumberformatter.h:242
unumberoptions.h
C API: Header-only input options for various number formatting APIs.
UNumberFormatRoundingMode
UNumberFormatRoundingMode
The possible number format rounding modes.
Definition: unumberoptions.h:28
UNUM_ROUND_HALFEVEN
@ UNUM_ROUND_HALFEVEN
Half-even rounding.
Definition: unumberoptions.h:37
UNumberGroupingStrategy
UNumberGroupingStrategy
An enum declaring the strategy for when and how to display grouping separators (i....
Definition: unumberoptions.h:96
uobject.h
C++ API: Common ICU base class UObject.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_MEMORY_ALLOCATION_ERROR
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition: utypes.h:457
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:449
U_FAILURE
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition: utypes.h:717
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301