ICU 68.2  68.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/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 
85 U_NAMESPACE_BEGIN
86 
87 // Forward declarations:
88 class IFixedDecimal;
89 class FieldPositionIteratorHandler;
90 class FormattedStringBuilder;
91 
92 namespace numparse {
93 namespace impl {
94 
95 // Forward declarations:
96 class NumberParserImpl;
97 class MultiplierParseHandler;
98 
99 }
100 }
101 
102 namespace units {
103 
104 // Forward declarations:
105 class UnitsRouter;
106 
107 } // namespace units
108 
109 namespace number { // icu::number
110 
111 // Forward declarations:
112 class UnlocalizedNumberFormatter;
113 class LocalizedNumberFormatter;
114 class FormattedNumber;
115 class Notation;
116 class ScientificNotation;
117 class Precision;
118 class FractionPrecision;
119 class CurrencyPrecision;
120 class IncrementPrecision;
121 class IntegerWidth;
122 
123 namespace impl {
124 
125 // can't be #ifndef U_HIDE_INTERNAL_API; referenced throughout this file in public classes
131 typedef int16_t digits_t;
132 
133 // can't be #ifndef U_HIDE_INTERNAL_API; needed for struct initialization
140 static constexpr int32_t kInternalDefaultThreshold = 3;
141 
142 // Forward declarations:
143 class Padder;
144 struct MacroProps;
145 struct MicroProps;
146 class DecimalQuantity;
147 class UFormattedNumberData;
148 class NumberFormatterImpl;
149 struct ParsedPatternInfo;
150 class ScientificModifier;
151 class MultiplierProducer;
152 class RoundingImpl;
153 class ScientificHandler;
154 class Modifier;
155 class AffixPatternProvider;
156 class NumberPropertyMapper;
157 struct DecimalFormatProperties;
158 class MultiplierFormatHandler;
159 class CurrencySymbols;
160 class GeneratorHelpers;
161 class DecNum;
162 class NumberRangeFormatterImpl;
163 struct RangeMacroProps;
164 struct UFormattedNumberImpl;
165 class MutablePatternModifier;
166 class ImmutablePatternModifier;
167 struct DecimalFormatWarehouse;
168 
176 
177 } // namespace impl
178 
185 
192 
198 class U_I18N_API Notation : public UMemory {
199  public:
225 
249 
292 
316 
342 
343  private:
344  enum NotationType {
345  NTN_SCIENTIFIC, NTN_COMPACT, NTN_SIMPLE, NTN_ERROR
346  } fType;
347 
348  union NotationUnion {
349  // For NTN_SCIENTIFIC
360  } scientific;
361 
362  // For NTN_COMPACT
363  UNumberCompactStyle compactStyle;
364 
365  // For NTN_ERROR
366  UErrorCode errorCode;
367  } fUnion;
368 
370 
371  Notation(const NotationType &type, const NotationUnion &union_) : fType(type), fUnion(union_) {}
372 
373  Notation(UErrorCode errorCode) : fType(NTN_ERROR) {
374  fUnion.errorCode = errorCode;
375  }
376 
377  Notation() : fType(NTN_SIMPLE), fUnion() {}
378 
379  UBool copyErrorTo(UErrorCode &status) const {
380  if (fType == NTN_ERROR) {
381  status = fUnion.errorCode;
382  return true;
383  }
384  return false;
385  }
386 
387  // To allow MacroProps to initialize empty instances:
388  friend struct impl::MacroProps;
389  friend class ScientificNotation;
390 
391  // To allow implementation to access internal types:
392  friend class impl::NumberFormatterImpl;
393  friend class impl::ScientificModifier;
394  friend class impl::ScientificHandler;
395 
396  // To allow access to the skeleton generation code:
397  friend class impl::GeneratorHelpers;
398 };
399 
409  public:
423  ScientificNotation withMinExponentDigits(int32_t minExponentDigits) const;
424 
439 
440  private:
441  // Inherit constructor
442  using Notation::Notation;
443 
444  // Raw constructor for NumberPropertyMapper
445  ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, impl::digits_t fMinExponentDigits,
446  UNumberSignDisplay fExponentSignDisplay);
447 
448  friend class Notation;
449 
450  // So that NumberPropertyMapper can create instances
451  friend class impl::NumberPropertyMapper;
452 };
453 
460 
469 class U_I18N_API Precision : public UMemory {
470 
471  public:
490 
498 
526  static FractionPrecision fixedFraction(int32_t minMaxFractionPlaces);
527 
541  static FractionPrecision minFraction(int32_t minFractionPlaces);
542 
553  static FractionPrecision maxFraction(int32_t maxFractionPlaces);
554 
568  static FractionPrecision minMaxFraction(int32_t minFractionPlaces, int32_t maxFractionPlaces);
569 
583  static SignificantDigitsPrecision fixedSignificantDigits(int32_t minMaxSignificantDigits);
584 
597  static SignificantDigitsPrecision minSignificantDigits(int32_t minSignificantDigits);
598 
607  static SignificantDigitsPrecision maxSignificantDigits(int32_t maxSignificantDigits);
608 
620  static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits,
621  int32_t maxSignificantDigits);
622 
642  static IncrementPrecision increment(double roundingIncrement);
643 
662 
663  private:
664  enum PrecisionType {
665  RND_BOGUS,
666  RND_NONE,
667  RND_FRACTION,
668  RND_SIGNIFICANT,
669  RND_FRACTION_SIGNIFICANT,
670 
671  // Used for strange increments like 3.14.
672  RND_INCREMENT,
673 
674  // Used for increments with 1 as the only digit. This is different than fraction
675  // rounding because it supports having additional trailing zeros. For example, this
676  // class is used to round with the increment 0.010.
677  RND_INCREMENT_ONE,
678 
679  // Used for increments with 5 as the only digit (nickel rounding).
680  RND_INCREMENT_FIVE,
681 
682  RND_CURRENCY,
683  RND_ERROR
684  } fType;
685 
686  union PrecisionUnion {
689  // For RND_FRACTION, RND_SIGNIFICANT, and RND_FRACTION_SIGNIFICANT
698  } fracSig;
701  // For RND_INCREMENT, RND_INCREMENT_ONE, and RND_INCREMENT_FIVE
703  double fIncrement;
708  } increment;
709  UCurrencyUsage currencyUsage; // For RND_CURRENCY
710  UErrorCode errorCode; // For RND_ERROR
711  } fUnion;
712 
715 
716  Precision(const PrecisionType& type, const PrecisionUnion& union_)
717  : fType(type), fUnion(union_) {}
718 
719  Precision(UErrorCode errorCode) : fType(RND_ERROR) {
720  fUnion.errorCode = errorCode;
721  }
722 
723  Precision() : fType(RND_BOGUS) {}
724 
725  bool isBogus() const {
726  return fType == RND_BOGUS;
727  }
728 
729  UBool copyErrorTo(UErrorCode &status) const {
730  if (fType == RND_ERROR) {
731  status = fUnion.errorCode;
732  return true;
733  }
734  return false;
735  }
736 
737  // On the parent type so that this method can be called internally on Precision instances.
738  Precision withCurrency(const CurrencyUnit &currency, UErrorCode &status) const;
739 
740  static FractionPrecision constructFraction(int32_t minFrac, int32_t maxFrac);
741 
742  static Precision constructSignificant(int32_t minSig, int32_t maxSig);
743 
744  static Precision
745  constructFractionSignificant(const FractionPrecision &base, int32_t minSig, int32_t maxSig);
746 
747  static IncrementPrecision constructIncrement(double increment, int32_t minFrac);
748 
749  static CurrencyPrecision constructCurrency(UCurrencyUsage usage);
750 
751  // To allow MacroProps/MicroProps to initialize bogus instances:
752  friend struct impl::MacroProps;
753  friend struct impl::MicroProps;
754 
755  // To allow NumberFormatterImpl to access isBogus() and other internal methods:
756  friend class impl::NumberFormatterImpl;
757 
758  // To allow NumberPropertyMapper to create instances from DecimalFormatProperties:
759  friend class impl::NumberPropertyMapper;
760 
761  // To allow access to the main implementation class:
762  friend class impl::RoundingImpl;
763 
764  // To allow child classes to call private methods:
765  friend class FractionPrecision;
766  friend class CurrencyPrecision;
767  friend class IncrementPrecision;
768 
769  // To allow access to the skeleton generation code:
770  friend class impl::GeneratorHelpers;
771 
772  // To allow access to isBogus and the default (bogus) constructor:
773  friend class units::UnitsRouter;
774 };
775 
786  public:
803  Precision withMinDigits(int32_t minSignificantDigits) const;
804 
822  Precision withMaxDigits(int32_t maxSignificantDigits) const;
823 
824  private:
825  // Inherit constructor
826  using Precision::Precision;
827 
828  // To allow parent class to call this class's constructor:
829  friend class Precision;
830 };
831 
842  public:
860  Precision withCurrency(const CurrencyUnit &currency) const;
861 
862  private:
863  // Inherit constructor
864  using Precision::Precision;
865 
866  // To allow parent class to call this class's constructor:
867  friend class Precision;
868 };
869 
880  public:
896  Precision withMinFraction(int32_t minFrac) const;
897 
898  private:
899  // Inherit constructor
900  using Precision::Precision;
901 
902  // To allow parent class to call this class's constructor:
903  friend class Precision;
904 };
905 
916  public:
928  static IntegerWidth zeroFillTo(int32_t minInt);
929 
941  IntegerWidth truncateAt(int32_t maxInt);
942 
943  private:
944  union {
945  struct {
946  impl::digits_t fMinInt;
947  impl::digits_t fMaxInt;
948  bool fFormatFailIfMoreThanMaxDigits;
949  } minMaxInt;
950  UErrorCode errorCode;
951  } fUnion;
952  bool fHasError = false;
953 
954  IntegerWidth(impl::digits_t minInt, impl::digits_t maxInt, bool formatFailIfMoreThanMaxDigits);
955 
956  IntegerWidth(UErrorCode errorCode) { // NOLINT
957  fUnion.errorCode = errorCode;
958  fHasError = true;
959  }
960 
961  IntegerWidth() { // NOLINT
962  fUnion.minMaxInt.fMinInt = -1;
963  }
964 
966  static IntegerWidth standard() {
967  return IntegerWidth::zeroFillTo(1);
968  }
969 
970  bool isBogus() const {
971  return !fHasError && fUnion.minMaxInt.fMinInt == -1;
972  }
973 
974  UBool copyErrorTo(UErrorCode &status) const {
975  if (fHasError) {
976  status = fUnion.errorCode;
977  return true;
978  }
979  return false;
980  }
981 
982  void apply(impl::DecimalQuantity &quantity, UErrorCode &status) const;
983 
984  bool operator==(const IntegerWidth& other) const;
985 
986  // To allow MacroProps/MicroProps to initialize empty instances:
987  friend struct impl::MacroProps;
988  friend struct impl::MicroProps;
989 
990  // To allow NumberFormatterImpl to access isBogus():
991  friend class impl::NumberFormatterImpl;
992 
993  // To allow the use of this class when formatting:
994  friend class impl::MutablePatternModifier;
995  friend class impl::ImmutablePatternModifier;
996 
997  // So that NumberPropertyMapper can create instances
998  friend class impl::NumberPropertyMapper;
999 
1000  // To allow access to the skeleton generation code:
1001  friend class impl::GeneratorHelpers;
1002 };
1003 
1012 class U_I18N_API Scale : public UMemory {
1013  public:
1020  static Scale none();
1021 
1032  static Scale powerOfTen(int32_t power);
1033 
1046  static Scale byDecimal(StringPiece multiplicand);
1047 
1056  static Scale byDouble(double multiplicand);
1057 
1064  static Scale byDoubleAndPowerOfTen(double multiplicand, int32_t power);
1065 
1066  // We need a custom destructor for the DecNum, which means we need to declare
1067  // the copy/move constructor/assignment quartet.
1068 
1070  Scale(const Scale& other);
1071 
1073  Scale& operator=(const Scale& other);
1074 
1077 
1080 
1083 
1084 #ifndef U_HIDE_INTERNAL_API
1086  Scale(int32_t magnitude, impl::DecNum* arbitraryToAdopt);
1087 #endif /* U_HIDE_INTERNAL_API */
1088 
1089  private:
1090  int32_t fMagnitude;
1091  impl::DecNum* fArbitrary;
1092  UErrorCode fError;
1093 
1094  Scale(UErrorCode error) : fMagnitude(0), fArbitrary(nullptr), fError(error) {}
1095 
1096  Scale() : fMagnitude(0), fArbitrary(nullptr), fError(U_ZERO_ERROR) {}
1097 
1098  bool isValid() const {
1099  return fMagnitude != 0 || fArbitrary != nullptr;
1100  }
1101 
1102  UBool copyErrorTo(UErrorCode &status) const {
1103  if (U_FAILURE(fError)) {
1104  status = fError;
1105  return true;
1106  }
1107  return false;
1108  }
1109 
1110  void applyTo(impl::DecimalQuantity& quantity) const;
1111 
1112  void applyReciprocalTo(impl::DecimalQuantity& quantity) const;
1113 
1114  // To allow MacroProps/MicroProps to initialize empty instances:
1115  friend struct impl::MacroProps;
1116  friend struct impl::MicroProps;
1117 
1118  // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1119  friend class impl::NumberFormatterImpl;
1120 
1121  // To allow the helper class MultiplierFormatHandler access to private fields:
1122  friend class impl::MultiplierFormatHandler;
1123 
1124  // To allow access to the skeleton generation code:
1125  friend class impl::GeneratorHelpers;
1126 
1127  // To allow access to parsing code:
1128  friend class ::icu::numparse::impl::NumberParserImpl;
1129  friend class ::icu::numparse::impl::MultiplierParseHandler;
1130 };
1131 
1132 namespace impl {
1133 
1134 // Do not enclose entire Usage with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1139 class U_I18N_API Usage : public UMemory {
1140 
1141 #ifndef U_HIDE_INTERNAL_API
1142 
1143  public:
1145  Usage(const Usage& other);
1146 
1148  Usage& operator=(const Usage& other);
1149 
1152 
1155 
1158 
1160  int16_t length() const { return fLength; }
1161 
1165  void set(StringPiece value);
1166 
1168  bool isSet() const { return fLength > 0; }
1169 
1170 #endif // U_HIDE_INTERNAL_API
1171 
1172  private:
1173  char *fUsage;
1174  int16_t fLength;
1175  UErrorCode fError;
1176 
1177  Usage() : fUsage(nullptr), fLength(0), fError(U_ZERO_ERROR) {}
1178 
1180  UBool copyErrorTo(UErrorCode &status) const {
1181  if (U_FAILURE(fError)) {
1182  status = fError;
1183  return true;
1184  }
1185  return false;
1186  }
1187 
1188  // Allow NumberFormatterImpl to access fUsage.
1189  friend class impl::NumberFormatterImpl;
1190 
1191  // Allow skeleton generation code to access private members.
1192  friend class impl::GeneratorHelpers;
1193 
1194  // Allow MacroProps/MicroProps to initialize empty instances and to call
1195  // copyErrorTo().
1196  friend struct impl::MacroProps;
1197 };
1198 
1199 // Do not enclose entire SymbolsWrapper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1202  public:
1204  SymbolsWrapper() : fType(SYMPTR_NONE), fPtr{nullptr} {}
1205 
1208 
1211 
1214 
1217 
1220 
1221 #ifndef U_HIDE_INTERNAL_API
1222 
1227  void setTo(const DecimalFormatSymbols &dfs);
1228 
1233  void setTo(const NumberingSystem *ns);
1234 
1240 
1245  bool isNumberingSystem() const;
1246 
1252 
1258 
1259 #endif // U_HIDE_INTERNAL_API
1260 
1262  UBool copyErrorTo(UErrorCode &status) const {
1263  if (fType == SYMPTR_DFS && fPtr.dfs == nullptr) {
1264  status = U_MEMORY_ALLOCATION_ERROR;
1265  return true;
1266  } else if (fType == SYMPTR_NS && fPtr.ns == nullptr) {
1267  status = U_MEMORY_ALLOCATION_ERROR;
1268  return true;
1269  }
1270  return false;
1271  }
1272 
1273  private:
1274  enum SymbolsPointerType {
1275  SYMPTR_NONE, SYMPTR_DFS, SYMPTR_NS
1276  } fType;
1277 
1278  union {
1279  const DecimalFormatSymbols *dfs;
1280  const NumberingSystem *ns;
1281  } fPtr;
1282 
1283  void doCopyFrom(const SymbolsWrapper &other);
1284 
1285  void doMoveFrom(SymbolsWrapper&& src);
1286 
1287  void doCleanup();
1288 };
1289 
1290 // Do not enclose entire Grouper with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1292 class U_I18N_API Grouper : public UMemory {
1293  public:
1294 #ifndef U_HIDE_INTERNAL_API
1297 
1302  static Grouper forProperties(const DecimalFormatProperties& properties);
1303 
1304  // Future: static Grouper forProperties(DecimalFormatProperties& properties);
1305 
1307  Grouper(int16_t grouping1, int16_t grouping2, int16_t minGrouping, UNumberGroupingStrategy strategy)
1308  : fGrouping1(grouping1),
1309  fGrouping2(grouping2),
1310  fMinGrouping(minGrouping),
1311  fStrategy(strategy) {}
1312 
1314  int16_t getPrimary() const;
1315 
1317  int16_t getSecondary() const;
1318 #endif // U_HIDE_INTERNAL_API
1319 
1320  private:
1329  int16_t fGrouping1;
1330  int16_t fGrouping2;
1331 
1339  int16_t fMinGrouping;
1340 
1345  UNumberGroupingStrategy fStrategy;
1346 
1347  Grouper() : fGrouping1(-3) {}
1348 
1349  bool isBogus() const {
1350  return fGrouping1 == -3;
1351  }
1352 
1354  void setLocaleData(const impl::ParsedPatternInfo &patternInfo, const Locale& locale);
1355 
1356  bool groupAtPosition(int32_t position, const impl::DecimalQuantity &value) const;
1357 
1358  // To allow MacroProps/MicroProps to initialize empty instances:
1359  friend struct MacroProps;
1360  friend struct MicroProps;
1361 
1362  // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1363  friend class NumberFormatterImpl;
1364 
1365  // To allow NumberParserImpl to perform setLocaleData():
1366  friend class ::icu::numparse::impl::NumberParserImpl;
1367 
1368  // To allow access to the skeleton generation code:
1369  friend class impl::GeneratorHelpers;
1370 };
1371 
1372 // Do not enclose entire Padder with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1374 class U_I18N_API Padder : public UMemory {
1375  public:
1376 #ifndef U_HIDE_INTERNAL_API
1378  static Padder none();
1379 
1381  static Padder codePoints(UChar32 cp, int32_t targetWidth, UNumberFormatPadPosition position);
1382 
1384  static Padder forProperties(const DecimalFormatProperties& properties);
1385 #endif // U_HIDE_INTERNAL_API
1386 
1387  private:
1388  UChar32 fWidth; // -3 = error; -2 = bogus; -1 = no padding
1389  union {
1390  struct {
1391  int32_t fCp;
1392  UNumberFormatPadPosition fPosition;
1393  } padding;
1394  UErrorCode errorCode;
1395  } fUnion;
1396 
1397  Padder(UChar32 cp, int32_t width, UNumberFormatPadPosition position);
1398 
1399  Padder(int32_t width);
1400 
1401  Padder(UErrorCode errorCode) : fWidth(-3) { // NOLINT
1402  fUnion.errorCode = errorCode;
1403  }
1404 
1405  Padder() : fWidth(-2) {} // NOLINT
1406 
1407  bool isBogus() const {
1408  return fWidth == -2;
1409  }
1410 
1411  UBool copyErrorTo(UErrorCode &status) const {
1412  if (fWidth == -3) {
1413  status = fUnion.errorCode;
1414  return true;
1415  }
1416  return false;
1417  }
1418 
1419  bool isValid() const {
1420  return fWidth > 0;
1421  }
1422 
1423  int32_t padAndApply(const impl::Modifier &mod1, const impl::Modifier &mod2,
1424  FormattedStringBuilder &string, int32_t leftIndex, int32_t rightIndex,
1425  UErrorCode &status) const;
1426 
1427  // To allow MacroProps/MicroProps to initialize empty instances:
1428  friend struct MacroProps;
1429  friend struct MicroProps;
1430 
1431  // To allow NumberFormatterImpl to access isBogus() and perform other operations:
1432  friend class impl::NumberFormatterImpl;
1433 
1434  // To allow access to the skeleton generation code:
1435  friend class impl::GeneratorHelpers;
1436 };
1437 
1438 // Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
1440 struct U_I18N_API MacroProps : public UMemory {
1443 
1445  MeasureUnit unit; // = MeasureUnit(); (the base dimensionless unit)
1446 
1448  MeasureUnit perUnit; // = MeasureUnit(); (the base dimensionless unit)
1449 
1451  Precision precision; // = Precision(); (bogus)
1452 
1455 
1457  Grouper grouper; // = Grouper(); (bogus)
1458 
1460  Padder padder; // = Padder(); (bogus)
1461 
1463  IntegerWidth integerWidth; // = IntegerWidth(); (bogus)
1464 
1467 
1468  // UNUM_XYZ_COUNT denotes null (bogus) values.
1469 
1472 
1475 
1478 
1480  Scale scale; // = Scale(); (benign value)
1481 
1483  Usage usage; // = Usage(); (no usage)
1484 
1486  const AffixPatternProvider* affixProvider = nullptr; // no ownership
1487 
1489  const PluralRules* rules = nullptr; // no ownership
1490 
1492  int32_t threshold = kInternalDefaultThreshold;
1493 
1496 
1497  // NOTE: Uses default copy and move constructors.
1498 
1503  bool copyErrorTo(UErrorCode &status) const {
1504  return notation.copyErrorTo(status) || precision.copyErrorTo(status) ||
1505  padder.copyErrorTo(status) || integerWidth.copyErrorTo(status) ||
1506  symbols.copyErrorTo(status) || scale.copyErrorTo(status) || usage.copyErrorTo(status);
1507  }
1508 };
1509 
1510 } // namespace impl
1511 
1512 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
1513 // Ignore MSVC warning 4661. This is generated for NumberFormatterSettings<>::toSkeleton() as this method
1514 // is defined elsewhere (in number_skeletons.cpp). The compiler is warning that the explicit template instantiation
1515 // inside this single translation unit (CPP file) is incomplete, and thus it isn't sure if the template class is
1516 // fully defined. However, since each translation unit explicitly instantiates all the necessary template classes,
1517 // they will all be passed to the linker, and the linker will still find and export all the class members.
1518 #pragma warning(push)
1519 #pragma warning(disable: 4661)
1520 #endif
1521 
1527 template<typename Derived>
1529  public:
1558  Derived notation(const Notation &notation) const &;
1559 
1569  Derived notation(const Notation &notation) &&;
1570 
1619  Derived unit(const icu::MeasureUnit &unit) const &;
1620 
1630  Derived unit(const icu::MeasureUnit &unit) &&;
1631 
1645  Derived adoptUnit(icu::MeasureUnit *unit) const &;
1646 
1656  Derived adoptUnit(icu::MeasureUnit *unit) &&;
1657 
1680  Derived perUnit(const icu::MeasureUnit &perUnit) const &;
1681 
1691  Derived perUnit(const icu::MeasureUnit &perUnit) &&;
1692 
1706  Derived adoptPerUnit(icu::MeasureUnit *perUnit) const &;
1707 
1717  Derived adoptPerUnit(icu::MeasureUnit *perUnit) &&;
1718 
1749  Derived precision(const Precision& precision) const &;
1750 
1760  Derived precision(const Precision& precision) &&;
1761 
1780  Derived roundingMode(UNumberFormatRoundingMode roundingMode) const &;
1781 
1790  Derived roundingMode(UNumberFormatRoundingMode roundingMode) &&;
1791 
1819  Derived grouping(UNumberGroupingStrategy strategy) const &;
1820 
1830  Derived grouping(UNumberGroupingStrategy strategy) &&;
1831 
1856  Derived integerWidth(const IntegerWidth &style) const &;
1857 
1867  Derived integerWidth(const IntegerWidth &style) &&;
1868 
1909  Derived symbols(const DecimalFormatSymbols &symbols) const &;
1910 
1920  Derived symbols(const DecimalFormatSymbols &symbols) &&;
1921 
1955  Derived adoptSymbols(NumberingSystem *symbols) const &;
1956 
1966  Derived adoptSymbols(NumberingSystem *symbols) &&;
1967 
1993  Derived unitWidth(UNumberUnitWidth width) const &;
1994 
2004  Derived unitWidth(UNumberUnitWidth width) &&;
2005 
2031  Derived sign(UNumberSignDisplay style) const &;
2032 
2042  Derived sign(UNumberSignDisplay style) &&;
2043 
2069  Derived decimal(UNumberDecimalSeparatorDisplay style) const &;
2070 
2081 
2106  Derived scale(const Scale &scale) const &;
2107 
2117  Derived scale(const Scale &scale) &&;
2118 
2119 #ifndef U_HIDE_DRAFT_API
2162  Derived usage(StringPiece usage) const &;
2163 
2171  Derived usage(StringPiece usage) &&;
2172 #endif // U_HIDE_DRAFT_API
2173 
2174 #ifndef U_HIDE_INTERNAL_API
2175 
2181  Derived padding(const impl::Padder &padder) const &;
2182 
2184  Derived padding(const impl::Padder &padder) &&;
2185 
2192  Derived threshold(int32_t threshold) const &;
2193 
2195  Derived threshold(int32_t threshold) &&;
2196 
2202  Derived macros(const impl::MacroProps& macros) const &;
2203 
2205  Derived macros(const impl::MacroProps& macros) &&;
2206 
2208  Derived macros(impl::MacroProps&& macros) const &;
2209 
2211  Derived macros(impl::MacroProps&& macros) &&;
2212 
2213 #endif /* U_HIDE_INTERNAL_API */
2214 
2230 
2243 
2251  LocalPointer<Derived> clone() &&;
2252 
2259  UBool copyErrorTo(UErrorCode &outErrorCode) const {
2260  if (U_FAILURE(outErrorCode)) {
2261  // Do not overwrite the older error code
2262  return true;
2263  }
2264  fMacros.copyErrorTo(outErrorCode);
2265  return U_FAILURE(outErrorCode);
2266  }
2267 
2268  // NOTE: Uses default copy and move constructors.
2269 
2270  private:
2271  impl::MacroProps fMacros;
2272 
2273  // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
2274  NumberFormatterSettings() = default;
2275 
2276  friend class LocalizedNumberFormatter;
2277  friend class UnlocalizedNumberFormatter;
2278 
2279  // Give NumberRangeFormatter access to the MacroProps
2280  friend void impl::touchRangeLocales(impl::RangeMacroProps& macros);
2281  friend class impl::NumberRangeFormatterImpl;
2282 };
2283 
2293  : public NumberFormatterSettings<UnlocalizedNumberFormatter>, public UMemory {
2294 
2295  public:
2306 
2317 
2324 
2330 
2337 
2343 
2350 
2351  private:
2353 
2354  explicit UnlocalizedNumberFormatter(
2356 
2357  // To give the fluent setters access to this class's constructor:
2359 
2360  // To give NumberFormatter::with() access to this class's constructor:
2361  friend class NumberFormatter;
2362 };
2363 
2373  : public NumberFormatterSettings<LocalizedNumberFormatter>, public UMemory {
2374  public:
2386  FormattedNumber formatInt(int64_t value, UErrorCode &status) const;
2387 
2399  FormattedNumber formatDouble(double value, UErrorCode &status) const;
2400 
2416 
2417 #ifndef U_HIDE_INTERNAL_API
2418 
2422  FormattedNumber formatDecimalQuantity(const impl::DecimalQuantity& dq, UErrorCode& status) const;
2423 
2427  void getAffixImpl(bool isPrefix, bool isNegative, UnicodeString& result, UErrorCode& status) const;
2428 
2433  const impl::NumberFormatterImpl* getCompiled() const;
2434 
2439  int32_t getCallCount() const;
2440 
2441 #endif /* U_HIDE_INTERNAL_API */
2442 
2456  Format* toFormat(UErrorCode& status) const;
2457 
2464 
2470 
2477 
2483 
2490 
2491 #ifndef U_HIDE_INTERNAL_API
2492 
2505  void formatImpl(impl::UFormattedNumberData *results, UErrorCode &status) const;
2506 
2507 #endif /* U_HIDE_INTERNAL_API */
2508 
2514 
2515  private:
2516  // Note: fCompiled can't be a LocalPointer because impl::NumberFormatterImpl is defined in an internal
2517  // header, and LocalPointer needs the full class definition in order to delete the instance.
2518  const impl::NumberFormatterImpl* fCompiled {nullptr};
2519  char fUnsafeCallCount[8] {}; // internally cast to u_atomic_int32_t
2520 
2521  // Owned pointer to a DecimalFormatWarehouse, used when copying a LocalizedNumberFormatter
2522  // from a DecimalFormat.
2523  const impl::DecimalFormatWarehouse* fWarehouse {nullptr};
2524 
2525  explicit LocalizedNumberFormatter(const NumberFormatterSettings<LocalizedNumberFormatter>& other);
2526 
2527  explicit LocalizedNumberFormatter(NumberFormatterSettings<LocalizedNumberFormatter>&& src) U_NOEXCEPT;
2528 
2529  LocalizedNumberFormatter(const impl::MacroProps &macros, const Locale &locale);
2530 
2531  LocalizedNumberFormatter(impl::MacroProps &&macros, const Locale &locale);
2532 
2533  void resetCompiled();
2534 
2535  void lnfMoveHelper(LocalizedNumberFormatter&& src);
2536 
2537  void lnfCopyHelper(const LocalizedNumberFormatter& src, UErrorCode& status);
2538 
2542  bool computeCompiled(UErrorCode& status) const;
2543 
2544  // To give the fluent setters access to this class's constructor:
2545  friend class NumberFormatterSettings<UnlocalizedNumberFormatter>;
2546  friend class NumberFormatterSettings<LocalizedNumberFormatter>;
2547 
2548  // To give UnlocalizedNumberFormatter::locale() access to this class's constructor:
2549  friend class UnlocalizedNumberFormatter;
2550 };
2551 
2552 #if (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN) && defined(_MSC_VER)
2553 // Warning 4661.
2554 #pragma warning(pop)
2555 #endif
2556 
2566  public:
2567 
2573  : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
2574 
2580 
2586 
2589 
2591  FormattedNumber& operator=(const FormattedNumber&) = delete;
2592 
2598 
2599  // Copybrief: this method is older than the parent method
2607  UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
2608 
2609  // Copydoc: this method is new in ICU 64
2611  UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
2612 
2613  // Copybrief: this method is older than the parent method
2621  Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
2622 
2623  // Copydoc: this method is new in ICU 64
2625  UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
2626 
2645  template<typename StringClass>
2646  inline StringClass toDecimalNumber(UErrorCode& status) const;
2647 
2648 #ifndef U_HIDE_DRAFT_API
2661 #endif // U_HIDE_DRAFT_API
2662 
2663 #ifndef U_HIDE_INTERNAL_API
2664 
2669  void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const;
2670 
2675  void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const;
2676 
2677 #endif /* U_HIDE_INTERNAL_API */
2678 
2679  private:
2680  // Can't use LocalPointer because UFormattedNumberData is forward-declared
2681  const impl::UFormattedNumberData *fData;
2682 
2683  // Error code for the terminal methods
2684  UErrorCode fErrorCode;
2685 
2690  explicit FormattedNumber(impl::UFormattedNumberData *results)
2691  : fData(results), fErrorCode(U_ZERO_ERROR) {}
2692 
2693  explicit FormattedNumber(UErrorCode errorCode)
2694  : fData(nullptr), fErrorCode(errorCode) {}
2695 
2696  void toDecimalNumber(ByteSink& sink, UErrorCode& status) const;
2697 
2698  // To give LocalizedNumberFormatter format methods access to this class's constructor:
2699  friend class LocalizedNumberFormatter;
2700 
2701  // To give C API access to internals
2702  friend struct impl::UFormattedNumberImpl;
2703 };
2704 
2705 #ifndef U_HIDE_DRAFT_API
2706 // Note: This is draft ICU 65
2707 template<typename StringClass>
2708 StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const {
2709  StringClass result;
2710  StringByteSink<StringClass> sink(&result);
2711  toDecimalNumber(sink, status);
2712  return result;
2713 }
2714 #endif // U_HIDE_DRAFT_API
2715 
2722  public:
2731 
2742 
2758 
2777  UParseError& perror, UErrorCode& status);
2778 
2782  NumberFormatter() = delete;
2783 };
2784 
2785 } // namespace number
2786 U_NAMESPACE_END
2787 
2788 #endif /* #if !UCONFIG_NO_FORMATTING */
2789 
2790 #endif /* U_SHOW_CPLUSPLUS_API */
2791 
2792 #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:237
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:269
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:295
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.
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 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 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 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,...
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)
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.
Manages NumberFormatterSettings::usage()'s char* instance on the heap.
void set(StringPiece value)
Usage(const Usage &other)
Usage & operator=(Usage &&src) U_NOEXCEPT
Usage & operator=(const Usage &other)
Usage(Usage &&src) U_NOEXCEPT
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:322
UNumberFormatPadPosition
The possible number format pad positions.
Definition: unum.h:311
C-compatible API for localized number formatting; not recommended for C++.
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.
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