| 1 | // © 2018 and later: Unicode, Inc. and others. |
| 2 | // License & terms of use: http://www.unicode.org/copyright.html |
| 3 | |
| 4 | #include "unicode/utypes.h" |
| 5 | |
| 6 | #if !UCONFIG_NO_FORMATTING |
| 7 | |
| 8 | // Allow implicit conversion from char16_t* to UnicodeString for this file: |
| 9 | // Helpful in toString methods and elsewhere. |
| 10 | #define UNISTR_FROM_STRING_EXPLICIT |
| 11 | |
| 12 | #include "unicode/compactdecimalformat.h" |
| 13 | #include "number_mapper.h" |
| 14 | #include "number_decimfmtprops.h" |
| 15 | |
| 16 | using namespace icu; |
| 17 | |
| 18 | |
| 19 | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CompactDecimalFormat) |
| 20 | |
| 21 | |
| 22 | CompactDecimalFormat* |
| 23 | CompactDecimalFormat::createInstance(const Locale& inLocale, UNumberCompactStyle style, |
| 24 | UErrorCode& status) { |
| 25 | return new CompactDecimalFormat(inLocale, style, status); |
| 26 | } |
| 27 | |
| 28 | CompactDecimalFormat::CompactDecimalFormat(const Locale& inLocale, UNumberCompactStyle style, |
| 29 | UErrorCode& status) |
| 30 | : DecimalFormat(new DecimalFormatSymbols(inLocale, status), status) { |
| 31 | if (U_FAILURE(status)) return; |
| 32 | // Minimal properties: let the non-shim code path do most of the logic for us. |
| 33 | fields->properties.compactStyle = style; |
| 34 | fields->properties.groupingSize = -2; // do not forward grouping information |
| 35 | fields->properties.minimumGroupingDigits = 2; |
| 36 | touch(status); |
| 37 | } |
| 38 | |
| 39 | CompactDecimalFormat::CompactDecimalFormat(const CompactDecimalFormat& source) = default; |
| 40 | |
| 41 | CompactDecimalFormat::~CompactDecimalFormat() = default; |
| 42 | |
| 43 | CompactDecimalFormat& CompactDecimalFormat::operator=(const CompactDecimalFormat& rhs) { |
| 44 | DecimalFormat::operator=(rhs); |
| 45 | return *this; |
| 46 | } |
| 47 | |
| 48 | CompactDecimalFormat* CompactDecimalFormat::clone() const { |
| 49 | return new CompactDecimalFormat(*this); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | CompactDecimalFormat::parse( |
| 54 | const UnicodeString& /* text */, |
| 55 | Formattable& /* result */, |
| 56 | ParsePosition& /* parsePosition */) const { |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | CompactDecimalFormat::parse( |
| 61 | const UnicodeString& /* text */, |
| 62 | Formattable& /* result */, |
| 63 | UErrorCode& status) const { |
| 64 | status = U_UNSUPPORTED_ERROR; |
| 65 | } |
| 66 | |
| 67 | CurrencyAmount* |
| 68 | CompactDecimalFormat::parseCurrency( |
| 69 | const UnicodeString& /* text */, |
| 70 | ParsePosition& /* pos */) const { |
| 71 | return nullptr; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
| 76 | |