ICU 69.1  69.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"
18 #include "unicode/formattedvalue.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"
27 #include "unicode/uobject.h"
28 
84 U_NAMESPACE_BEGIN
85 
86 // Forward declarations:
87 class IFixedDecimal;
88 class FieldPositionIteratorHandler;
89 class FormattedStringBuilder;
90 
91 namespace numparse {
92 namespace impl {
93 
94 // Forward declarations:
95 class NumberParserImpl;
96 class MultiplierParseHandler;
97 
98 }
99 }
100 
101 namespace units {
102 
103 // Forward declarations:
104 class UnitsRouter;
105 
106 } // namespace units
107 
108 namespace number { // icu::number
109 
110 // Forward declarations:
111 class UnlocalizedNumberFormatter;
112 class LocalizedNumberFormatter;
113 class FormattedNumber;
114 class Notation;
115 class ScientificNotation;
116 class Precision;
117 class FractionPrecision;
118 class CurrencyPrecision;
119 class IncrementPrecision;
120 class IntegerWidth;
121 
122 namespace impl {
123 
124 // can't be #ifndef U_HIDE_INTERNAL_API; referenced throughout this file in public classes
130 typedef int16_t digits_t;
131 
132 // can't be #ifndef U_HIDE_INTERNAL_API; needed for struct initialization
139 static constexpr int32_t kInternalDefaultThreshold = 3;
140 
141 // Forward declarations:
142 class Padder;
143 struct MacroProps;
144 struct MicroProps;
145 class DecimalQuantity;
146 class UFormattedNumberData;
147 class NumberFormatterImpl;
148 struct ParsedPatternInfo;
149 class ScientificModifier;
150 class MultiplierProducer;
151 class RoundingImpl;
152 class ScientificHandler;
153 class Modifier;
154 class AffixPatternProvider;
155 class NumberPropertyMapper;
156 struct DecimalFormatProperties;
157 class MultiplierFormatHandler;
158 class CurrencySymbols;
159 class GeneratorHelpers;
160 class DecNum;
161 class NumberRangeFormatterImpl;
162 struct RangeMacroProps;
163 struct UFormattedNumberImpl;
164 class MutablePatternModifier;
165 class ImmutablePatternModifier;
166 struct DecimalFormatWarehouse;
167 
175 
176 } // namespace impl
177 
184 
191 
197 class U_I18N_API Notation : public UMemory {
198  public:
224 
248 
291 
315 
341 
342  private:
343  enum NotationType {
344  NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
345  } fType;
346 
347  union NotationUnion {
348  // For NTN_SCIENTIFIC
359  } scientific;
360 
361  // For NTN_COMPACT
362  UNumberCompactStyle compactStyle;
363 
364  // For NTN_ERROR
365  UErrorCode errorCode;
366  } fUnion;
367 
369 
370  Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
371 
372  Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
373  fUnion.errorCode = errorCode;
374  }
375 
376  Notation() : fType(NTN_SIMPLE), fUnion() {}
377 
378  UBool copyErrorTo(UErrorCode &status) const {
379  if (fType == NTN_ERROR) {
380  status = fUnion.errorCode;
381  return true;
382  }
383  return false;
384  }
385 
386  // To allow MacroProps to initialize empty instances:
387  friend struct impl::MacroProps;
388  friend class ScientificNotation;
389 
390  // To allow implementation to access internal types:
391  friend class impl::NumberFormatterImpl;
392  friend class impl::ScientificModifier;
393  friend class impl::ScientificHandler;
394 
395  // To allow access to the skeleton generation code:
396  friend class impl::GeneratorHelpers;
397 };
398 
408  public:
422  ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
423 
438 
439  private:
440  // Inherit constructor
441  using Notation::Notation;
442 
443  // Raw constructor for NumberPropertyMapper
444  ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
445  UNumberSignDisplay fExponentSignDisplay);
446 
447  friend class Notation;
448 
449  // So that NumberPropertyMapper can create instances
450  friend class impl::NumberPropertyMapper;
451 };
452 
459 
468 class U_I18N_API Precision : public UMemory {
469 
470  public:
489 
497 
525  static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
526 
540  static FractionPrecision minFraction(int32_t minFractionPlaces);
541 
552  static FractionPrecision maxFraction(int32_t maxFractionPlaces);
553 
567  static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
568 
582  static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
583 
596  static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
597 
606  static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
607 
619  static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
620  int32_t maxSignificantDigits);
621 
641  static IncrementPrecision increment(double roundingIncrement);
642 
661 
662 #ifndef U_HIDE_DRAFT_API
671 #endif // U_HIDE_DRAFT_API
672 
673  private:
674  enum PrecisionType {
675  RND_BOGUS,
676  RND_NONE,
677  RND_FRACTION,
678  RND_SIGNIFICANT,
679  RND_FRACTION_SIGNIFICANT,
680 
681  // Used for strange increments like 3.14.
682  RND_INCREMENT,
683 
684  // Used for increments with 1 as the only digit. This is different than fraction
685  // rounding because it supports having additional trailing zeros. For example, this
686  // class is used to round with the increment 0.010.
687  RND_INCREMENT_ONE,
688 
689  // Used for increments with 5 as the only digit (nickel rounding).
690  RND_INCREMENT_FIVE,
691 
692  RND_CURRENCY,
693  RND_ERROR
694  } fType;
695 
696  union PrecisionUnion {
699  // For RND_FRACTION, RND_SIGNIFICANT, and RND_FRACTION_SIGNIFICANT
710  } fracSig;
713  // For RND_INCREMENT, RND_INCREMENT_ONE, and RND_INCREMENT_FIVE
715  double fIncrement;
720  } increment;
721  UCurrencyUsage currencyUsage; // For RND_CURRENCY
722  UErrorCode errorCode; // For RND_ERROR
723  } fUnion;
724 
726 
729 
730  Precision(const PrecisionType& type, const PrecisionUnion& union_)
731  : fType(type), fUnion(union_) {}
732 
733  Precision(UErrorCode errorCode) : fType(RND_ERROR) {
734  fUnion.errorCode = errorCode;
735  }
736 
737  Precision() : fType(RND_BOGUS) {}
738 
739  bool isBogus() const {
740  return fType == RND_BOGUS;
741  }
742 
743  UBool copyErrorTo(UErrorCode &status) const {
744  if (fType == RND_ERROR) {
745  status = fUnion.errorCode;
746  return true;
747  }
748  return false;
749  }
750 
751  // On the parent type so that this method can be called internally on Precision instances.
752  Precision withCurrency(const CurrencyUnit &currency, UErrorCode &status) const;
753 
754  static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
755 
756  static Precision constructSignificant(int32_t minSig, int32_t maxSig);
757 
758  static Precision constructFractionSignificant(
759  const FractionPrecision &base,
760  int32_t minSig,
761  int32_t maxSig,
762  UNumberRoundingPriority priority);
763 
764  static IncrementPrecision constructIncrement(double increment, int32_t minFrac);
765 
766  static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
767 
768  // To allow MacroProps/MicroProps to initialize bogus instances:
769  friend struct impl::MacroProps;
770  friend struct impl::MicroProps;
771 
772  // To allow NumberFormatterImpl to access isBogus() and other internal methods:
773  friend class impl::NumberFormatterImpl;
774 
775  // To allow NumberPropertyMapper to create instances from DecimalFormatProperties:
776  friend class impl::NumberPropertyMapper;
777 
778  // To allow access to the main implementation class:
779  friend class impl::RoundingImpl;
780 
781  // To allow child classes to call private methods:
782  friend class FractionPrecision;
783  friend class CurrencyPrecision;
784  friend class IncrementPrecision;
785 
786  // To allow access to the skeleton generation code:
787  friend class impl::GeneratorHelpers;
788 
789  // To allow access to isBogus and the default (bogus) constructor:
790  friend class units::UnitsRouter;
791 };
792 
803  public:
804 #ifndef U_HIDE_DRAFT_API
820  int32_t minSignificantDigits,
821  int32_t maxSignificantDigits,
822  UNumberRoundingPriority priority) const;
823 #endif // U_HIDE_DRAFT_API
824 
842  Precision withMinDigits(int32_t minSignificantDigits) const;
843 
861  Precision withMaxDigits(int32_t maxSignificantDigits) const;
862 
863  private:
864  // Inherit constructor
865  using Precision::Precision;
866 
867  // To allow parent class to call this class's constructor:
868  friend class Precision;
869 };
870 
881  public:
899  Precision withCurrency(const CurrencyUnit &currency) const;
900 
901  private:
902  // Inherit constructor
903  using Precision::Precision;
904 
905  // To allow parent class to call this class's constructor:
906  friend class Precision;
907 };
908 
919  public:
935  Precision withMinFraction(int32_t minFrac) const;
936 
937  private:
938  // Inherit constructor
939  using Precision::Precision;
940 
941  // To allow parent class to call this class's constructor:
942  friend class Precision;
943 };
944 
955  public:
967  static IntegerWidth zeroFillTo(int32_t minInt);
968 
980  IntegerWidth truncateAt(int32_t maxInt);
981 
982  private:
983  union {
984  struct {
985  impl::digits_t fMinInt;
986  impl::digits_t fMaxInt;
987  bool fFormatFailIfMoreThanMaxDigits;
988  } minMaxInt;
989  UErrorCode errorCode;
990  } fUnion;
991  bool fHasError = false;
992 
993  IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
994 
995  IntegerWidth(UErrorCode errorCode) { // NOLINT
996  fUnion.errorCode = errorCode;
997  fHasError = true;
998  }
999 
1000  IntegerWidth() { // NOLINT
1001  fUnion.minMaxInt.fMinInt = -1;
1002  }
1003 
1005  static IntegerWidth standard() {
1006  return IntegerWidth::zeroFillTo(1);
1007  }
1008 
1009  bool isBogus() const {
1010  return !fHasError && fUnion.minMaxInt.fMinInt == -1;
1011  }
1012 
1013  UBool copyErrorTo(UErrorCode &status) const {
1014  if (fHasError) {
1015  status = fUnion.errorCode;
1016  return true;
1017  }
1018  return false;
1019  }
1020 
1021  void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
1022 
1023  bool operator==(const IntegerWidth& other) const;
1024 
1025  // To allow MacroProps/MicroProps to initialize empty instances:
1026  friend struct impl::MacroProps;
1027  friend struct impl::MicroProps;
1028 
1029  // To allow NumberFormatterImpl to access isBogus():
1030  friend class impl::NumberFormatterImpl;
1031 
1032  // To allow the use of this class when formatting:
1033  friend class impl::MutablePatternModifier;
1034  friend class impl::ImmutablePatternModifier;
1035 
1036  // So that NumberPropertyMapper can create instances
1037  friend class impl::NumberPropertyMapper;
1038 
1039  // To allow access to the skeleton generation code:
1040  friend class impl::GeneratorHelpers;
1041 };
1042 
1051 class U_I18N_API Scale : public UMemory {
1052  public:
1059  static Scale none();
1060 
1071  static Scale powerOfTen(int32_t power);
1072 
1085  static Scale byDecimal(StringPiece multiplicand);
1086 
1095  static Scale byDouble(double multiplicand);
1096 
1103  static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
1104 
1105  // We need a custom destructor for the DecNum, which means we need to declare
1106  // the copy/move constructor/assignment quartet.
1107 
1109  Scale(const Scale& other);
1110 
1112  Scale& operator=(const Scale& other);
1113 
1116 
1119 
1122 
1123 #ifndef U_HIDE_INTERNAL_API
1125  Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1126 #endif /* U_HIDE_INTERNAL_API */
1127 
1128  private:
1129  int32_t fMagnitude;
1130  impl::DecNum* fArbitrary;
1131  UErrorCode fError;
1132 
1133  Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
1134 
1135  Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
1136 
1137  bool isValid() const {
1138  return fMagnitude != 0 || fArbitrary != nullptr;
1139  }
1140 
1141  UBool copyErrorTo(UErrorCode &status) const {
1142  if (U_FAILURE(fError)) {
1143  status = fError;
1144  return true;
1145  }
1146  return false;
1147  }
1148 
1149  void applyTo(impl::DecimalQuantity& quantity) const;
1150 
1151  void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
1152 
1153  // To allow MacroProps/MicroProps to initialize empty instances:
1154  friend struct impl::MacroProps;
1155  friend struct impl::MicroProps;
1156 
1157  // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1158  friend class impl::NumberFormatterImpl;
1159 
1160  // To allow the helper class MultiplierFormatHandler access to private fields:
1161  friend class impl::MultiplierFormatHandler;
1162 
1163  // To allow access to the skeleton generation code:
1164  friend class impl::GeneratorHelpers;
1165 
1166  // To allow access to parsing code:
1167  friend class ::icu::numparse::impl::NumberParserImpl;
1168  friend class ::icu::numparse::impl::MultiplierParseHandler;
1169 };
1170 
1171 namespace impl {
1172 
1173 // Do not enclose entire StringProp with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1179 
1180 #ifndef U_HIDE_INTERNAL_API
1181 
1182  public:
1184  StringProp(const StringProp &other);
1185 
1188 
1191 
1194 
1197 
1199  int16_t length() const {
1200  return fLength;
1201  }
1202 
1206  void set(StringPiece value);
1207 
1209  bool isSet() const {
1210  return fLength > 0;
1211  }
1212 
1213 #endif // U_HIDE_INTERNAL_API
1214 
1215  private:
1216  char *fValue;
1217  int16_t fLength;
1218  UErrorCode fError;
1219 
1220  StringProp() : fValue(nullptr), fLength(0), fError(U_ZERO_ERROR) {
1221  }
1222 
1224  UBool copyErrorTo(UErrorCode &status) const {
1225  if (U_FAILURE(fError)) {
1226  status = fError;
1227  return true;
1228  }
1229  return false;
1230  }
1231 
1232  // Allow NumberFormatterImpl to access fValue.
1233  friend class impl::NumberFormatterImpl;
1234 
1235  // Allow skeleton generation code to access private members.
1236  friend class impl::GeneratorHelpers;
1237 
1238  // Allow MacroProps/MicroProps to initialize empty instances and to call
1239  // copyErrorTo().
1240  friend struct impl::MacroProps;
1241 };
1242 
1243 // Do not enclose entire SymbolsWrapper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1246  public:
1248  SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
1249 
1252 
1255 
1258 
1261 
1264 
1265 #ifndef U_HIDE_INTERNAL_API
1266 
1271  void setTo(const DecimalFormatSymbols &dfs);
1272 
1277  void setTo(const NumberingSystem *ns);
1278 
1284 
1289  bool isNumberingSystem() const;
1290 
1296 
1302 
1303 #endif // U_HIDE_INTERNAL_API
1304 
1306  UBool copyErrorTo(UErrorCode &status) const {
1307  if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
1308  status = U_MEMORY_ALLOCATION_ERROR;
1309  return true;
1310  } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
1311  status = U_MEMORY_ALLOCATION_ERROR;
1312  return true;
1313  }
1314  return false;
1315  }
1316 
1317  private:
1318  enum SymbolsPointerType {
1319  SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1320  } fType;
1321 
1322  union {
1323  const DecimalFormatSymbols *dfs;
1324  const NumberingSystem *ns;
1325  } fPtr;
1326 
1327  void doCopyFrom(const SymbolsWrapper &other);
1328 
1329  void doMoveFrom(SymbolsWrapper&& src);
1330 
1331  void doCleanup();
1332 };
1333 
1334 // Do not enclose entire Grouper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1336 class U_I18N_API Grouper : public UMemory {
1337  public:
1338 #ifndef U_HIDE_INTERNAL_API
1341 
1346  static Grouper forProperties(const DecimalFormatProperties& properties);
1347 
1348  // Future: static Grouper forProperties(DecimalFormatProperties& properties);
1349 
1351  Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
1352  : fGrouping1(grouping1),
1353  fGrouping2(grouping2),
1354  fMinGrouping(minGrouping),
1355  fStrategy(strategy) {}
1356 
1358  int16_t getPrimary() const;
1359 
1361  int16_t getSecondary() const;
1362 #endif // U_HIDE_INTERNAL_API
1363 
1364  private:
1373  int16_t fGrouping1;
1374  int16_t fGrouping2;
1375 
1383  int16_t fMinGrouping;
1384 
1389  UNumberGroupingStrategy fStrategy;
1390 
1391  Grouper() : fGrouping1(-3) {}
1392 
1393  bool isBogus() const {
1394  return fGrouping1 == -3;
1395  }
1396 
1398  void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
1399 
1400  bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
1401 
1402  // To allow MacroProps/MicroProps to initialize empty instances:
1403  friend struct MacroProps;
1404  friend struct MicroProps;
1405 
1406  // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1407  friend class NumberFormatterImpl;
1408 
1409  // To allow NumberParserImpl to perform setLocaleData():
1410  friend class ::icu::numparse::impl::NumberParserImpl;
1411 
1412  // To allow access to the skeleton generation code:
1413  friend class impl::GeneratorHelpers;
1414 };
1415 
1416 // Do not enclose entire Padder with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1418 class U_I18N_API Padder : public UMemory {
1419  public:
1420 #ifndef U_HIDE_INTERNAL_API
1422  static Padder none();
1423 
1425  static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
1426 
1428  static Padder forProperties(const DecimalFormatProperties& properties);
1429 #endif // U_HIDE_INTERNAL_API
1430 
1431  private:
1432  UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding
1433  union {
1434  struct {
1435  int32_t fCp;
1436  UNumberFormatPadPosition fPosition;
1437  } padding;
1438  UErrorCode errorCode;
1439  } fUnion;
1440 
1441  Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
1442 
1443  Padder(int32_t width);
1444 
1445  Padder(UErrorCode errorCode) : fWidth(-3) { // NOLINT
1446  fUnion.errorCode = errorCode;
1447  }
1448 
1449  Padder() : fWidth(-2) {} // NOLINT
1450 
1451  bool isBogus() const {
1452  return fWidth == -2;
1453  }
1454 
1455  UBool copyErrorTo(UErrorCode &status) const {
1456  if (fWidth == -3) {
1457  status = fUnion.errorCode;
1458  return true;
1459  }
1460  return false;
1461  }
1462 
1463  bool isValid() const {
1464  return fWidth > 0;
1465  }
1466 
1467  int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
1468  FormattedStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
1469  UErrorCode &status) const;
1470 
1471  // To allow MacroProps/MicroProps to initialize empty instances:
1472  friend struct MacroProps;
1473  friend struct MicroProps;
1474 
1475  // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1476  friend class impl::NumberFormatterImpl;
1477 
1478  // To allow access to the skeleton generation code:
1479  friend class impl::GeneratorHelpers;
1480 };
1481 
1482 // Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1484 struct U_I18N_API MacroProps : public UMemory {
1487 
1489  MeasureUnit unit; // = MeasureUnit(); (the base dimensionless unit)
1490 
1492  MeasureUnit perUnit; // = MeasureUnit(); (the base dimensionless unit)
1493 
1495  Precision precision; // = Precision(); (bogus)
1496 
1499 
1501  Grouper grouper; // = Grouper(); (bogus)
1502 
1504  Padder padder; // = Padder(); (bogus)
1505 
1507  IntegerWidth integerWidth; // = IntegerWidth(); (bogus)
1508 
1511 
1512  // UNUM_XYZ_COUNT denotes null (bogus) values.
1513 
1516 
1519 
1522 
1524  Scale scale; // = Scale(); (benign value)
1525 
1527  StringProp usage; // = StringProp(); (no usage)
1528 
1530  StringProp unitDisplayCase; // = StringProp(); (nominative)
1531 
1533  const AffixPatternProvider* affixProvider = nullptr; // no ownership
1534 
1536  const PluralRules* rules = nullptr; // no ownership
1537 
1539  int32_t threshold = kInternalDefaultThreshold;
1540 
1543 
1544  // NOTE: Uses default copy and move constructors.
1545 
1550  bool copyErrorTo(UErrorCode &status) const {
1551  return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1552  padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1553  symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status) ||
1554  unitDisplayCase.copyErrorTo(status);
1555  }
1556 };
1557 
1558 } // namespace impl
1559 
1560 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1561 // Ignore MSVC warning 4661. This is generated for NumberFormatterSettings<>::toSkeleton() as this method
1562 // is defined elsewhere (in number_skeletons.cpp). The compiler is warning that the explicit template instantiation
1563 // inside this single translation unit (CPP file) is incomplete, and thus it isn't sure if the template class is
1564 // fully defined. However, since each translation unit explicitly instantiates all the necessary template classes,
1565 // they will all be passed to the linker, and the linker will still find and export all the class members.
1566 #pragma warning(push)
1567 #pragma warning(disable: 4661)
1568 #endif
1569 
1575 template<typename Derived>
1577  public:
1606  Derived notation(const Notation &notation) const &;
1607 
1617  Derived notation(const Notation &notation) &&;
1618 
1667  Derived unit(const icu::MeasureUnit &unit) const &;
1668 
1678  Derived unit(const icu::MeasureUnit &unit) &&;
1679 
1693  Derived adoptUnit(icu::MeasureUnit *unit) const &;
1694 
1704  Derived adoptUnit(icu::MeasureUnit *unit) &&;
1705 
1728  Derived perUnit(const icu::MeasureUnit &perUnit) const &;
1729 
1739  Derived perUnit(const icu::MeasureUnit &perUnit) &&;
1740 
1754  Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
1755 
1765  Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
1766 
1797  Derived precision(const Precision& precision) const &;
1798 
1808  Derived precision(const Precision& precision) &&;
1809 
1828  Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
1829 
1838  Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
1839 
1867  Derived grouping(UNumberGroupingStrategy strategy) const &;
1868 
1878  Derived grouping(UNumberGroupingStrategy strategy) &&;
1879 
1904  Derived integerWidth(const IntegerWidth &style) const &;
1905 
1915  Derived integerWidth(const IntegerWidth &style) &&;
1916 
1957  Derived symbols(const DecimalFormatSymbols &symbols) const &;
1958 
1968  Derived symbols(const DecimalFormatSymbols &symbols) &&;
1969 
2003  Derived adoptSymbols(NumberingSystem *symbols) const &;
2004 
2014  Derived adoptSymbols(NumberingSystem *symbols) &&;
2015 
2041  Derived unitWidth(UNumberUnitWidth width) const &;
2042 
2052  Derived unitWidth(UNumberUnitWidth width) &&;
2053 
2079  Derived sign(UNumberSignDisplay style) const &;
2080 
2090  Derived sign(UNumberSignDisplay style) &&;
2091 
2117  Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
2118 
2129 
2154  Derived scale(const Scale &scale) const &;
2155 
2165  Derived scale(const Scale &scale) &&;
2166 
2167 #ifndef U_HIDE_DRAFT_API
2210  Derived usage(StringPiece usage) const &;
2211 
2219  Derived usage(StringPiece usage) &&;
2220 #endif // U_HIDE_DRAFT_API
2221 
2222 #ifndef U_HIDE_DRAFT_API
2223 #ifndef U_HIDE_INTERNAL_API
2230  Derived unitDisplayCase(StringPiece unitDisplayCase) const &;
2231 
2237  Derived unitDisplayCase(StringPiece unitDisplayCase) &&;
2238 #endif // U_HIDE_INTERNAL_API
2239 #endif // U_HIDE_DRAFT_API
2240 
2241 #ifndef U_HIDE_INTERNAL_API
2242 
2248  Derived padding(const impl::Padder &padder) const &;
2249 
2251  Derived padding(const impl::Padder &padder) &&;
2252 
2259  Derived threshold(int32_t threshold) const &;
2260 
2262  Derived threshold(int32_t threshold) &&;
2263 
2269  Derived macros(const impl::MacroProps& macros) const &;
2270 
2272  Derived macros(const impl::MacroProps& macros) &&;
2273 
2275  Derived macros(impl::MacroProps&& macros) const &;
2276 
2278  Derived macros(impl::MacroProps&& macros) &&;
2279 
2280 #endif /* U_HIDE_INTERNAL_API */
2281 
2300 
2313 
2321  LocalPointer<Derived> clone() &&;
2322 
2329  UBool copyErrorTo(UErrorCode &outErrorCode) const {
2330  if (U_FAILURE(outErrorCode)) {
2331  // Do not overwrite the older error code
2332  return true;
2333  }
2334  fMacros.copyErrorTo(outErrorCode);
2335  return U_FAILURE(outErrorCode);
2336  }
2337 
2338  // NOTE: Uses default copy and move constructors.
2339 
2340  private:
2341  impl::MacroProps fMacros;
2342 
2343  // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
2344  NumberFormatterSettings() = default;
2345 
2346  friend class LocalizedNumberFormatter;
2347  friend class UnlocalizedNumberFormatter;
2348 
2349  // Give NumberRangeFormatter access to the MacroProps
2350  friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
2351  friend class impl::NumberRangeFormatterImpl;
2352 };
2353 
2363  : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
2364 
2365  public:
2376 
2387 
2394 
2400 
2407 
2413 
2420 
2421  private:
2423 
2424  explicit UnlocalizedNumberFormatter(
2426 
2427  // To give the fluent setters access to this class's constructor:
2429 
2430  // To give NumberFormatter::with() access to this class's constructor:
2431  friend class NumberFormatter;
2432 };
2433 
2443  : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
2444  public:
2456  FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
2457 
2469  FormattedNumber formatDouble(double value, UErrorCode &status) const;
2470 
2486 
2487 #ifndef U_HIDE_INTERNAL_API
2488 
2492  FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
2493 
2497  void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
2498 
2503  const impl::NumberFormatterImpl* getCompiled() const;
2504 
2509  int32_t getCallCount() const;
2510 
2511 #endif /* U_HIDE_INTERNAL_API */
2512 
2526  Format* toFormat(UErrorCode& status) const;
2527 
2534 
2540 
2547 
2553 
2560 
2561 #ifndef U_HIDE_INTERNAL_API
2562 
2575  void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
2576 
2577 #endif /* U_HIDE_INTERNAL_API */
2578 
2584 
2585  private:
2586  // Note: fCompiled can't be a LocalPointer because impl::NumberFormatterImpl is defined in an internal
2587  // header, and LocalPointer needs the full class definition in order to delete the instance.
2588  const impl::NumberFormatterImpl* fCompiled {nullptr};
2589  char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t
2590 
2591  // Owned pointer to a DecimalFormatWarehouse, used when copying a LocalizedNumberFormatter
2592  // from a DecimalFormat.
2593  const impl::DecimalFormatWarehouse* fWarehouse {nullptr};
2594 
2595  explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
2596 
2597  explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
2598 
2599  LocalizedNumberFormatter(const impl::MacroProps &macros, const Locale &locale);
2600 
2601  LocalizedNumberFormatter(impl::MacroProps &&macros, const Locale &locale);
2602 
2603  void resetCompiled();
2604 
2605  void lnfMoveHelper(LocalizedNumberFormatter&& src);
2606 
2607  void lnfCopyHelper(const LocalizedNumberFormatter& src, UErrorCode& status);
2608 
2612  bool computeCompiled(UErrorCode& status) const;
2613 
2614  // To give the fluent setters access to this class's constructor:
2615  friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2616  friend class NumberFormatterSettings<LocalizedNumberFormatter>;
2617 
2618  // To give UnlocalizedNumberFormatter::locale() access to this class's constructor:
2619  friend class UnlocalizedNumberFormatter;
2620 };
2621 
2622 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2623 // Warning 4661.
2624 #pragma warning(pop)
2625 #endif
2626 
2636  public:
2637 
2643  : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
2644 
2650 
2656 
2659 
2661  FormattedNumber& operator=(const FormattedNumber&) = delete;
2662 
2668 
2669  // Copybrief: this method is older than the parent method
2677  UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
2678 
2679  // Copydoc: this method is new in ICU 64
2681  UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
2682 
2683  // Copybrief: this method is older than the parent method
2691  Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
2692 
2693  // Copydoc: this method is new in ICU 64
2695  UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
2696 
2715  template<typename StringClass>
2716  inline StringClass toDecimalNumber(UErrorCode& status) const;
2717 
2718 #ifndef U_HIDE_DRAFT_API
2731 
2738  const char *getGender(UErrorCode& status) const;
2739 #endif // U_HIDE_DRAFT_API
2740 
2741 #ifndef U_HIDE_INTERNAL_API
2742 
2747  void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
2748 
2753  void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
2754 
2755 #endif /* U_HIDE_INTERNAL_API */
2756 
2757  private:
2758  // Can't use LocalPointer because UFormattedNumberData is forward-declared
2759  const impl::UFormattedNumberData *fData;
2760 
2761  // Error code for the terminal methods
2762  UErrorCode fErrorCode;
2763 
2768  explicit FormattedNumber(impl::UFormattedNumberData *results)
2769  : fData(results), fErrorCode(U_ZERO_ERROR) {}
2770 
2771  explicit FormattedNumber(UErrorCode errorCode)
2772  : fData(nullptr), fErrorCode(errorCode) {}
2773 
2774  void toDecimalNumber(ByteSink& sink, UErrorCode& status) const;
2775 
2776  // To give LocalizedNumberFormatter format methods access to this class's constructor:
2777  friend class LocalizedNumberFormatter;
2778 
2779  // To give C API access to internals
2780  friend struct impl::UFormattedNumberImpl;
2781 };
2782 
2783 template<typename StringClass>
2784 StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const {
2785  StringClass result;
2786  StringByteSink<StringClass> sink(&result);
2787  toDecimalNumber(sink, status);
2788  return result;
2789 }
2790 
2797  public:
2806 
2817 
2836 
2858  UParseError& perror, UErrorCode& status);
2859 
2863  NumberFormatter() = delete;
2864 };
2865 
2866 } // namespace number
2867 U_NAMESPACE_END
2868 
2869 #endif /* #if !UCONFIG_NO_FORMATTING */
2870 
2871 #endif /* U_SHOW_CPLUSPLUS_API */
2872 
2873 #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:369
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.
MeasureUnit getOutputUnit(UErrorCode &status) const
Gets the resolved output unit.
FormattedNumber()
Default constructor; makes an empty FormattedNumber.
void getAllFieldPositionsImpl(FieldPositionIteratorHandler &fpih, UErrorCode &status) const
Populates the mutable builder type FieldPositionIteratorHandler.
const char * getGender(UErrorCode &status) const
Gets the gender of the formatted output.
virtual ~FormattedNumber() U_OVERRIDE
Destruct an instance of FormattedNumber.
FormattedNumber(FormattedNumber &&src) U_NOEXCEPT
Move constructor: Leaves the source FormattedNumber in an undefined state.
A class that defines a rounding precision based on a number of fraction places and optionally signifi...
Precision withMinDigits(int32_t minSignificantDigits) const
Ensure that no less than this number of significant digits are retained when rounding according to fr...
Precision withSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits, UNumberRoundingPriority priority) const
Override maximum fraction digits with maximum significant digits depending on the magnitude of the nu...
Precision withMaxDigits(int32_t maxSignificantDigits) const
Ensure that no more than this number of significant digits are retained when rounding according to fr...
A class that defines a rounding precision parameterized by a rounding increment to be used when forma...
Precision withMinFraction(int32_t minFrac) const
Specifies the minimum number of fraction digits to render after the decimal separator,...
A class that defines the strategy for padding and truncating integers before the decimal separator.
static IntegerWidth zeroFillTo(int32_t minInt)
Pad numbers at the beginning with zeros to guarantee a certain number of numerals before the decimal ...
IntegerWidth truncateAt(int32_t maxInt)
Truncate numbers exceeding a certain number of numerals before the decimal separator.
A NumberFormatter that has a locale associated with it; this means .format() methods are available.
const impl::NumberFormatterImpl * getCompiled() const
Internal method for testing.
LocalizedNumberFormatter & operator=(const LocalizedNumberFormatter &other)
Copy assignment operator.
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.
int32_t getCallCount() const
Internal method for testing.
~LocalizedNumberFormatter()
Destruct this LocalizedNumberFormatter, cleaning up any memory it might own.
Format * toFormat(UErrorCode &status) const
Creates a representation of this LocalizedNumberFormat as an icu::Format, enabling the use of this nu...
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.
LocalizedNumberFormatter & operator=(LocalizedNumberFormatter &&src) U_NOEXCEPT
Move assignment operator: The source LocalizedNumberFormatter will be left in a valid but undefined s...
FormattedNumber formatDecimal(StringPiece value, UErrorCode &status) const
Format the given decimal number to a string using the settings specified in the NumberFormatter fluen...
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...
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.
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) &&
LocalPointer< Derived > clone() const &
Returns the current (Un)LocalizedNumberFormatter as a LocalPointer wrapping a heap-allocated copy of ...
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 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
Scale & operator=(const Scale &other)
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=(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 & operator=(const UnlocalizedNumberFormatter &other)
Copy assignment operator.
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.
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 & operator=(StringProp &&src) U_NOEXCEPT
StringProp(const StringProp &other)
StringProp & operator=(const StringProp &other)
void set(StringPiece value)
StringProp(StringProp &&src) U_NOEXCEPT
SymbolsWrapper & operator=(SymbolsWrapper &&src) U_NOEXCEPT
SymbolsWrapper & operator=(const SymbolsWrapper &other)
const NumberingSystem * getNumberingSystem() const
Get the NumberingSystem pointer.
bool isNumberingSystem() const
Whether the object is currently holding a NumberingSystem.
const DecimalFormatSymbols * getDecimalFormatSymbols() const
Get the DecimalFormatSymbols pointer.
SymbolsWrapper(SymbolsWrapper &&src) U_NOEXCEPT
SymbolsWrapper(const SymbolsWrapper &other)
void setTo(const DecimalFormatSymbols &dfs)
The provided object is copied, but we do not adopt it.
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.
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 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:339
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:328
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:719
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301