LEFT | RIGHT |
(no file at all) | |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html | 2 // License & terms of use: http://www.unicode.org/copyright.html |
3 | 3 |
4 #include "unicode/utypes.h" | 4 #include "unicode/utypes.h" |
5 | 5 |
6 #if !UCONFIG_NO_FORMATTING | 6 #if !UCONFIG_NO_FORMATTING |
7 #ifndef __NUMBERFORMATTER_H__ | 7 #ifndef __NUMBERFORMATTER_H__ |
8 #define __NUMBERFORMATTER_H__ | 8 #define __NUMBERFORMATTER_H__ |
9 | 9 |
10 #include "unicode/appendable.h" | 10 #include "unicode/appendable.h" |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 Rounder withCurrency(const CurrencyUnit ¤cy, UErrorCode &status) const
; | 829 Rounder withCurrency(const CurrencyUnit ¤cy, UErrorCode &status) const
; |
830 | 830 |
831 /** NON-CONST: mutates the current instance. */ | 831 /** NON-CONST: mutates the current instance. */ |
832 void setLocaleData(const CurrencyUnit ¤cy, UErrorCode &status); | 832 void setLocaleData(const CurrencyUnit ¤cy, UErrorCode &status); |
833 | 833 |
834 void apply(impl::DecimalQuantity &value, UErrorCode &status) const; | 834 void apply(impl::DecimalQuantity &value, UErrorCode &status) const; |
835 | 835 |
836 /** Version of {@link #apply} that obeys minInt constraints. Used for scient
ific notation compatibility mode. */ | 836 /** Version of {@link #apply} that obeys minInt constraints. Used for scient
ific notation compatibility mode. */ |
837 void apply(impl::DecimalQuantity &value, int32_t minInt, UErrorCode status); | 837 void apply(impl::DecimalQuantity &value, int32_t minInt, UErrorCode status); |
838 | 838 |
| 839 /** |
| 840 * Rounding endpoint used by Engineering and Compact notation. Chooses the m
ost appropriate multiplier (magnitude |
| 841 * adjustment), applies the adjustment, rounds, and returns the chosen multi
plier. |
| 842 * |
| 843 * <p> |
| 844 * In most cases, this is simple. However, when rounding the number causes i
t to cross a multiplier boundary, we |
| 845 * need to re-do the rounding. For example, to display 999,999 in Engineerin
g notation with 2 sigfigs, first you |
| 846 * guess the multiplier to be -3. However, then you end up getting 1000E3, w
hich is not the correct output. You then |
| 847 * change your multiplier to be -6, and you get 1.0E6, which is correct. |
| 848 * |
| 849 * @param input The quantity to process. |
| 850 * @param producer Function to call to return a multiplier based on a magnit
ude. |
| 851 * @return The number of orders of magnitude the input was adjusted by this
method. |
| 852 */ |
839 int32_t | 853 int32_t |
840 chooseMultiplierAndApply(impl::DecimalQuantity &input, const impl::Multiplie
rProducer &producer, | 854 chooseMultiplierAndApply(impl::DecimalQuantity &input, const impl::Multiplie
rProducer &producer, |
841 UErrorCode &status); | 855 UErrorCode &status); |
842 | 856 |
843 static FractionRounder constructFraction(int32_t minFrac, int32_t maxFrac); | 857 static FractionRounder constructFraction(int32_t minFrac, int32_t maxFrac); |
844 | 858 |
845 static Rounder constructSignificant(int32_t minSig, int32_t maxSig); | 859 static Rounder constructSignificant(int32_t minSig, int32_t maxSig); |
846 | 860 |
847 static Rounder | 861 static Rounder |
848 constructFractionSignificant(const FractionRounder &base, int32_t minSig, in
t32_t maxSig); | 862 constructFractionSignificant(const FractionRounder &base, int32_t minSig, in
t32_t maxSig); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 | 1291 |
1278 /** @internal */ | 1292 /** @internal */ |
1279 struct U_I18N_API MacroProps : public UMemory { | 1293 struct U_I18N_API MacroProps : public UMemory { |
1280 /** @internal */ | 1294 /** @internal */ |
1281 Notation notation; | 1295 Notation notation; |
1282 | 1296 |
1283 /** @internal */ | 1297 /** @internal */ |
1284 MeasureUnit unit; // = NoUnit::base(); | 1298 MeasureUnit unit; // = NoUnit::base(); |
1285 | 1299 |
1286 /** @internal */ | 1300 /** @internal */ |
| 1301 MeasureUnit perUnit; // = NoUnit::base(); |
| 1302 |
| 1303 /** @internal */ |
1287 Rounder rounder; // = Rounder(); (bogus) | 1304 Rounder rounder; // = Rounder(); (bogus) |
1288 | 1305 |
1289 /** @internal */ | 1306 /** @internal */ |
1290 Grouper grouper; // = Grouper(); (bogus) | 1307 Grouper grouper; // = Grouper(); (bogus) |
1291 | 1308 |
1292 /** @internal */ | 1309 /** @internal */ |
1293 Padder padder; // = Padder(); (bogus) | 1310 Padder padder; // = Padder(); (bogus) |
1294 | 1311 |
1295 /** @internal */ | 1312 /** @internal */ |
1296 IntegerWidth integerWidth; // = IntegerWidth(); (bogus) | 1313 IntegerWidth integerWidth; // = IntegerWidth(); (bogus) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 | 1385 |
1369 /** | 1386 /** |
1370 * Specifies the unit (unit of measure, currency, or percent) to associate w
ith rendered numbers. | 1387 * Specifies the unit (unit of measure, currency, or percent) to associate w
ith rendered numbers. |
1371 * | 1388 * |
1372 * <ul> | 1389 * <ul> |
1373 * <li>Unit of measure: "12.3 meters" | 1390 * <li>Unit of measure: "12.3 meters" |
1374 * <li>Currency: "$12.30" | 1391 * <li>Currency: "$12.30" |
1375 * <li>Percent: "12.3%" | 1392 * <li>Percent: "12.3%" |
1376 * </ul> | 1393 * </ul> |
1377 * | 1394 * |
1378 * <p> | |
1379 * All units will be properly localized with locale data, and all units are
compatible with notation styles, | 1395 * All units will be properly localized with locale data, and all units are
compatible with notation styles, |
1380 * rounding strategies, and other number formatter settings. | 1396 * rounding strategies, and other number formatter settings. |
1381 * | 1397 * |
1382 * <p> | |
1383 * Pass this method any instance of {@link MeasureUnit}. For units of measur
e: | 1398 * Pass this method any instance of {@link MeasureUnit}. For units of measur
e: |
1384 * | 1399 * |
1385 * <pre> | 1400 * <pre> |
1386 * NumberFormatter.with().adoptUnit(MeasureUnit::createMeter(status)) | 1401 * NumberFormatter::with().adoptUnit(MeasureUnit::createMeter(status)) |
1387 * </pre> | 1402 * </pre> |
1388 * | 1403 * |
1389 * Currency: | 1404 * Currency: |
1390 * | 1405 * |
1391 * <pre> | 1406 * <pre> |
1392 * NumberFormatter.with()::unit(CurrencyUnit(u"USD", status)) | 1407 * NumberFormatter::with().unit(CurrencyUnit(u"USD", status)) |
1393 * </pre> | 1408 * </pre> |
1394 * | 1409 * |
1395 * Percent: | 1410 * Percent: |
1396 * | 1411 * |
1397 * <pre> | 1412 * <pre> |
1398 * NumberFormatter.with()::unit(NoUnit.percent()) | 1413 * NumberFormatter::with().unit(NoUnit.percent()) |
1399 * </pre> | 1414 * </pre> |
| 1415 * |
| 1416 * See {@link #perUnit} for information on how to format strings like "5 met
ers per second". |
1400 * | 1417 * |
1401 * The default is to render without units (equivalent to NoUnit.base()). | 1418 * The default is to render without units (equivalent to NoUnit.base()). |
1402 * | 1419 * |
1403 * @param unit | 1420 * @param unit |
1404 * The unit to render. | 1421 * The unit to render. |
1405 * @return The fluent chain. | 1422 * @return The fluent chain. |
1406 * @see MeasureUnit | 1423 * @see MeasureUnit |
1407 * @see Currency | 1424 * @see Currency |
1408 * @see NoUnit | 1425 * @see NoUnit |
| 1426 * @see #perUnit |
1409 * @draft ICU 60 | 1427 * @draft ICU 60 |
1410 */ | 1428 */ |
1411 Derived unit(const icu::MeasureUnit &unit) const; | 1429 Derived unit(const icu::MeasureUnit &unit) const; |
1412 | 1430 |
1413 /** | 1431 /** |
1414 * Like unit(), but takes ownership of a pointer. Convenient for use with t
he MeasureFormat factory | 1432 * Like unit(), but takes ownership of a pointer. Convenient for use with t
he MeasureFormat factory |
1415 * methods, which return pointers that need ownership. | 1433 * methods, which return pointers that need ownership. |
1416 * | 1434 * |
1417 * @param unit | 1435 * @param unit |
1418 * The unit to render. | 1436 * The unit to render. |
1419 * @return The fluent chain. | 1437 * @return The fluent chain. |
1420 * @see #unit | 1438 * @see #unit |
1421 * @see MeasureUnit | 1439 * @see MeasureUnit |
1422 * @draft ICU 60 | 1440 * @draft ICU 60 |
1423 */ | 1441 */ |
1424 Derived adoptUnit(const icu::MeasureUnit *unit) const; | 1442 Derived adoptUnit(const icu::MeasureUnit *unit) const; |
| 1443 |
| 1444 /** |
| 1445 * Sets a unit to be used in the denominator. For example, to format "3 m/s"
, pass METER to the unit and SECOND to |
| 1446 * the perUnit. |
| 1447 * |
| 1448 * Pass this method any instance of {@link MeasureUnit}. For example: |
| 1449 * |
| 1450 * <pre> |
| 1451 * NumberFormatter::with() |
| 1452 * .adoptUnit(MeasureUnit::createMeter(status)) |
| 1453 * .adoptPerUnit(MeasureUnit::createSecond(status)) |
| 1454 * </pre> |
| 1455 * |
| 1456 * The default is not to display any unit in the denominator. |
| 1457 * |
| 1458 * If a per-unit is specified without a primary unit via {@link #unit}, the
behavior is undefined. |
| 1459 * |
| 1460 * @param perUnit |
| 1461 * The unit to render in the denominator. |
| 1462 * @return The fluent chain |
| 1463 * @see #unit |
| 1464 * @draft ICU 61 |
| 1465 */ |
| 1466 Derived perUnit(const icu::MeasureUnit &perUnit) const; |
| 1467 |
| 1468 /** |
| 1469 * Like perUnit(), but takes ownership of a pointer. Convenient for use wit
h the MeasureFormat factory |
| 1470 * methods, which return pointers that need ownership. |
| 1471 * |
| 1472 * @param perUnit |
| 1473 * The unit to render in the denominator. |
| 1474 * @return The fluent chain. |
| 1475 * @see #perUnit |
| 1476 * @see MeasureUnit |
| 1477 * @draft ICU 61 |
| 1478 */ |
| 1479 Derived adoptPerUnit(const icu::MeasureUnit *perUnit) const; |
1425 | 1480 |
1426 /** | 1481 /** |
1427 * Specifies the rounding strategy to use when formatting numbers. | 1482 * Specifies the rounding strategy to use when formatting numbers. |
1428 * | 1483 * |
1429 * <ul> | 1484 * <ul> |
1430 * <li>Round to 3 decimal places: "3.142" | 1485 * <li>Round to 3 decimal places: "3.142" |
1431 * <li>Round to 3 significant figures: "3.14" | 1486 * <li>Round to 3 significant figures: "3.14" |
1432 * <li>Round to the closest nickel: "3.15" | 1487 * <li>Round to the closest nickel: "3.15" |
1433 * <li>Do not perform rounding: "3.1415926..." | 1488 * <li>Do not perform rounding: "3.1415926..." |
1434 * </ul> | 1489 * </ul> |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 explicit FormattedNumber(impl::NumberFormatterResults *results) | 2002 explicit FormattedNumber(impl::NumberFormatterResults *results) |
1948 : fResults(results), fErrorCode(U_ZERO_ERROR) {}; | 2003 : fResults(results), fErrorCode(U_ZERO_ERROR) {}; |
1949 | 2004 |
1950 explicit FormattedNumber(UErrorCode errorCode) | 2005 explicit FormattedNumber(UErrorCode errorCode) |
1951 : fResults(nullptr), fErrorCode(errorCode) {}; | 2006 : fResults(nullptr), fErrorCode(errorCode) {}; |
1952 | 2007 |
1953 // To give LocalizedNumberFormatter format methods access to this class's co
nstructor: | 2008 // To give LocalizedNumberFormatter format methods access to this class's co
nstructor: |
1954 friend class LocalizedNumberFormatter; | 2009 friend class LocalizedNumberFormatter; |
1955 }; | 2010 }; |
1956 | 2011 |
| 2012 // // TODO: Propose this. |
| 2013 // std::ostream& operator<<(std::ostream& os, |
| 2014 // const FormattedNumber& fn)·· |
| 2015 // {· |
| 2016 // os << fn.toString(); |
| 2017 // return os;·· |
| 2018 // } |
| 2019 |
1957 /** | 2020 /** |
1958 * See the main description in numberformatter.h for documentation and examples. | 2021 * See the main description in numberformatter.h for documentation and examples. |
1959 * | 2022 * |
1960 * @draft ICU 60 | 2023 * @draft ICU 60 |
1961 */ | 2024 */ |
1962 class U_I18N_API NumberFormatter final { | 2025 class U_I18N_API NumberFormatter final { |
1963 public: | 2026 public: |
1964 /** | 2027 /** |
1965 * Call this method at the beginning of a NumberFormatter fluent chain in wh
ich the locale is not currently known at | 2028 * Call this method at the beginning of a NumberFormatter fluent chain in wh
ich the locale is not currently known at |
1966 * the call site. | 2029 * the call site. |
(...skipping 22 matching lines...) Expand all Loading... |
1989 }; | 2052 }; |
1990 | 2053 |
1991 } // namespace number | 2054 } // namespace number |
1992 U_NAMESPACE_END | 2055 U_NAMESPACE_END |
1993 | 2056 |
1994 #endif // U_HIDE_DRAFT_API | 2057 #endif // U_HIDE_DRAFT_API |
1995 | 2058 |
1996 #endif // __NUMBERFORMATTER_H__ | 2059 #endif // __NUMBERFORMATTER_H__ |
1997 | 2060 |
1998 #endif /* #if !UCONFIG_NO_FORMATTING */ | 2061 #endif /* #if !UCONFIG_NO_FORMATTING */ |
LEFT | RIGHT |