1*0e209d39SAndroid Build Coastguard Worker // © 2017 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker 4*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 5*0e209d39SAndroid Build Coastguard Worker 6*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING 7*0e209d39SAndroid Build Coastguard Worker #ifndef __NUMBER_DECIMFMTPROPS_H__ 8*0e209d39SAndroid Build Coastguard Worker #define __NUMBER_DECIMFMTPROPS_H__ 9*0e209d39SAndroid Build Coastguard Worker 10*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h" 11*0e209d39SAndroid Build Coastguard Worker #include <cstdint> 12*0e209d39SAndroid Build Coastguard Worker #include "unicode/plurrule.h" 13*0e209d39SAndroid Build Coastguard Worker #include "unicode/currpinf.h" 14*0e209d39SAndroid Build Coastguard Worker #include "unicode/unum.h" 15*0e209d39SAndroid Build Coastguard Worker #include "unicode/localpointer.h" 16*0e209d39SAndroid Build Coastguard Worker #include "number_types.h" 17*0e209d39SAndroid Build Coastguard Worker 18*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 19*0e209d39SAndroid Build Coastguard Worker 20*0e209d39SAndroid Build Coastguard Worker // Export an explicit template instantiation of the LocalPointer that is used as a 21*0e209d39SAndroid Build Coastguard Worker // data member of CurrencyPluralInfoWrapper. 22*0e209d39SAndroid Build Coastguard Worker // (When building DLLs for Windows this is required.) 23*0e209d39SAndroid Build Coastguard Worker #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN 24*0e209d39SAndroid Build Coastguard Worker #if defined(_MSC_VER) 25*0e209d39SAndroid Build Coastguard Worker // Ignore warning 4661 as LocalPointerBase does not use operator== or operator!= 26*0e209d39SAndroid Build Coastguard Worker #pragma warning(push) 27*0e209d39SAndroid Build Coastguard Worker #pragma warning(disable: 4661) 28*0e209d39SAndroid Build Coastguard Worker #endif 29*0e209d39SAndroid Build Coastguard Worker template class U_I18N_API LocalPointerBase<CurrencyPluralInfo>; 30*0e209d39SAndroid Build Coastguard Worker template class U_I18N_API LocalPointer<CurrencyPluralInfo>; 31*0e209d39SAndroid Build Coastguard Worker #if defined(_MSC_VER) 32*0e209d39SAndroid Build Coastguard Worker #pragma warning(pop) 33*0e209d39SAndroid Build Coastguard Worker #endif 34*0e209d39SAndroid Build Coastguard Worker #endif 35*0e209d39SAndroid Build Coastguard Worker 36*0e209d39SAndroid Build Coastguard Worker namespace number::impl { 37*0e209d39SAndroid Build Coastguard Worker 38*0e209d39SAndroid Build Coastguard Worker // Exported as U_I18N_API because it is a public member field of exported DecimalFormatProperties 39*0e209d39SAndroid Build Coastguard Worker // Using this wrapper is rather unfortunate, but is needed on Windows platforms in order to allow 40*0e209d39SAndroid Build Coastguard Worker // for DLL-exporting a fully specified template instantiation. 41*0e209d39SAndroid Build Coastguard Worker class U_I18N_API CurrencyPluralInfoWrapper { 42*0e209d39SAndroid Build Coastguard Worker public: 43*0e209d39SAndroid Build Coastguard Worker LocalPointer<CurrencyPluralInfo> fPtr; 44*0e209d39SAndroid Build Coastguard Worker 45*0e209d39SAndroid Build Coastguard Worker CurrencyPluralInfoWrapper() = default; 46*0e209d39SAndroid Build Coastguard Worker CurrencyPluralInfoWrapper(const CurrencyPluralInfoWrapper & other)47*0e209d39SAndroid Build Coastguard Worker CurrencyPluralInfoWrapper(const CurrencyPluralInfoWrapper& other) { 48*0e209d39SAndroid Build Coastguard Worker if (!other.fPtr.isNull()) { 49*0e209d39SAndroid Build Coastguard Worker fPtr.adoptInstead(new CurrencyPluralInfo(*other.fPtr)); 50*0e209d39SAndroid Build Coastguard Worker } 51*0e209d39SAndroid Build Coastguard Worker } 52*0e209d39SAndroid Build Coastguard Worker 53*0e209d39SAndroid Build Coastguard Worker CurrencyPluralInfoWrapper& operator=(const CurrencyPluralInfoWrapper& other) { 54*0e209d39SAndroid Build Coastguard Worker if (this != &other && // self-assignment: no-op 55*0e209d39SAndroid Build Coastguard Worker !other.fPtr.isNull()) { 56*0e209d39SAndroid Build Coastguard Worker fPtr.adoptInstead(new CurrencyPluralInfo(*other.fPtr)); 57*0e209d39SAndroid Build Coastguard Worker } 58*0e209d39SAndroid Build Coastguard Worker return *this; 59*0e209d39SAndroid Build Coastguard Worker } 60*0e209d39SAndroid Build Coastguard Worker }; 61*0e209d39SAndroid Build Coastguard Worker 62*0e209d39SAndroid Build Coastguard Worker /** Controls the set of rules for parsing a string from the old DecimalFormat API. */ 63*0e209d39SAndroid Build Coastguard Worker enum ParseMode { 64*0e209d39SAndroid Build Coastguard Worker /** 65*0e209d39SAndroid Build Coastguard Worker * Lenient mode should be used if you want to accept malformed user input. It will use heuristics 66*0e209d39SAndroid Build Coastguard Worker * to attempt to parse through typographical errors in the string. 67*0e209d39SAndroid Build Coastguard Worker */ 68*0e209d39SAndroid Build Coastguard Worker PARSE_MODE_LENIENT, 69*0e209d39SAndroid Build Coastguard Worker 70*0e209d39SAndroid Build Coastguard Worker /** 71*0e209d39SAndroid Build Coastguard Worker * Strict mode should be used if you want to require that the input is well-formed. More 72*0e209d39SAndroid Build Coastguard Worker * specifically, it differs from lenient mode in the following ways: 73*0e209d39SAndroid Build Coastguard Worker * 74*0e209d39SAndroid Build Coastguard Worker * <ul> 75*0e209d39SAndroid Build Coastguard Worker * <li>Grouping widths must match the grouping settings. For example, "12,3,45" will fail if the 76*0e209d39SAndroid Build Coastguard Worker * grouping width is 3, as in the pattern "#,##0". 77*0e209d39SAndroid Build Coastguard Worker * <li>The string must contain a complete prefix and suffix. For example, if the pattern is 78*0e209d39SAndroid Build Coastguard Worker * "{#};(#)", then "{123}" or "(123)" would match, but "{123", "123}", and "123" would all fail. 79*0e209d39SAndroid Build Coastguard Worker * (The latter strings would be accepted in lenient mode.) 80*0e209d39SAndroid Build Coastguard Worker * <li>Whitespace may not appear at arbitrary places in the string. In lenient mode, whitespace 81*0e209d39SAndroid Build Coastguard Worker * is allowed to occur arbitrarily before and after prefixes and exponent separators. 82*0e209d39SAndroid Build Coastguard Worker * <li>Leading grouping separators are not allowed, as in ",123". 83*0e209d39SAndroid Build Coastguard Worker * <li>Minus and plus signs can only appear if specified in the pattern. In lenient mode, a plus 84*0e209d39SAndroid Build Coastguard Worker * or minus sign can always precede a number. 85*0e209d39SAndroid Build Coastguard Worker * <li>The set of characters that can be interpreted as a decimal or grouping separator is 86*0e209d39SAndroid Build Coastguard Worker * smaller. 87*0e209d39SAndroid Build Coastguard Worker * <li><strong>If currency parsing is enabled,</strong> currencies must only appear where 88*0e209d39SAndroid Build Coastguard Worker * specified in either the current pattern string or in a valid pattern string for the current 89*0e209d39SAndroid Build Coastguard Worker * locale. For example, if the pattern is "¤0.00", then "$1.23" would match, but "1.23$" would 90*0e209d39SAndroid Build Coastguard Worker * fail to match. 91*0e209d39SAndroid Build Coastguard Worker * </ul> 92*0e209d39SAndroid Build Coastguard Worker */ 93*0e209d39SAndroid Build Coastguard Worker PARSE_MODE_STRICT, 94*0e209d39SAndroid Build Coastguard Worker }; 95*0e209d39SAndroid Build Coastguard Worker 96*0e209d39SAndroid Build Coastguard Worker // Exported as U_I18N_API because it is needed for the unit test PatternStringTest 97*0e209d39SAndroid Build Coastguard Worker struct U_I18N_API DecimalFormatProperties : public UMemory { 98*0e209d39SAndroid Build Coastguard Worker 99*0e209d39SAndroid Build Coastguard Worker public: 100*0e209d39SAndroid Build Coastguard Worker NullableValue<UNumberCompactStyle> compactStyle; 101*0e209d39SAndroid Build Coastguard Worker NullableValue<CurrencyUnit> currency; 102*0e209d39SAndroid Build Coastguard Worker CurrencyPluralInfoWrapper currencyPluralInfo; 103*0e209d39SAndroid Build Coastguard Worker NullableValue<UCurrencyUsage> currencyUsage; 104*0e209d39SAndroid Build Coastguard Worker bool decimalPatternMatchRequired; 105*0e209d39SAndroid Build Coastguard Worker bool decimalSeparatorAlwaysShown; 106*0e209d39SAndroid Build Coastguard Worker bool exponentSignAlwaysShown; 107*0e209d39SAndroid Build Coastguard Worker bool currencyAsDecimal; 108*0e209d39SAndroid Build Coastguard Worker bool formatFailIfMoreThanMaxDigits; // ICU4C-only 109*0e209d39SAndroid Build Coastguard Worker int32_t formatWidth; 110*0e209d39SAndroid Build Coastguard Worker int32_t groupingSize; 111*0e209d39SAndroid Build Coastguard Worker bool groupingUsed; 112*0e209d39SAndroid Build Coastguard Worker int32_t magnitudeMultiplier; // internal field like multiplierScale but separate to avoid conflict 113*0e209d39SAndroid Build Coastguard Worker int32_t maximumFractionDigits; 114*0e209d39SAndroid Build Coastguard Worker int32_t maximumIntegerDigits; 115*0e209d39SAndroid Build Coastguard Worker int32_t maximumSignificantDigits; 116*0e209d39SAndroid Build Coastguard Worker int32_t minimumExponentDigits; 117*0e209d39SAndroid Build Coastguard Worker int32_t minimumFractionDigits; 118*0e209d39SAndroid Build Coastguard Worker int32_t minimumGroupingDigits; 119*0e209d39SAndroid Build Coastguard Worker int32_t minimumIntegerDigits; 120*0e209d39SAndroid Build Coastguard Worker int32_t minimumSignificantDigits; 121*0e209d39SAndroid Build Coastguard Worker int32_t multiplier; 122*0e209d39SAndroid Build Coastguard Worker int32_t multiplierScale; // ICU4C-only 123*0e209d39SAndroid Build Coastguard Worker UnicodeString negativePrefix; 124*0e209d39SAndroid Build Coastguard Worker UnicodeString negativePrefixPattern; 125*0e209d39SAndroid Build Coastguard Worker UnicodeString negativeSuffix; 126*0e209d39SAndroid Build Coastguard Worker UnicodeString negativeSuffixPattern; 127*0e209d39SAndroid Build Coastguard Worker NullableValue<PadPosition> padPosition; 128*0e209d39SAndroid Build Coastguard Worker UnicodeString padString; 129*0e209d39SAndroid Build Coastguard Worker bool parseCaseSensitive; 130*0e209d39SAndroid Build Coastguard Worker bool parseIntegerOnly; 131*0e209d39SAndroid Build Coastguard Worker NullableValue<ParseMode> parseMode; 132*0e209d39SAndroid Build Coastguard Worker bool parseNoExponent; 133*0e209d39SAndroid Build Coastguard Worker bool parseToBigDecimal; // TODO: Not needed in ICU4C? 134*0e209d39SAndroid Build Coastguard Worker UNumberFormatAttributeValue parseAllInput; // ICU4C-only 135*0e209d39SAndroid Build Coastguard Worker //PluralRules pluralRules; 136*0e209d39SAndroid Build Coastguard Worker UnicodeString positivePrefix; 137*0e209d39SAndroid Build Coastguard Worker UnicodeString positivePrefixPattern; 138*0e209d39SAndroid Build Coastguard Worker UnicodeString positiveSuffix; 139*0e209d39SAndroid Build Coastguard Worker UnicodeString positiveSuffixPattern; 140*0e209d39SAndroid Build Coastguard Worker double roundingIncrement; 141*0e209d39SAndroid Build Coastguard Worker NullableValue<RoundingMode> roundingMode; 142*0e209d39SAndroid Build Coastguard Worker int32_t secondaryGroupingSize; 143*0e209d39SAndroid Build Coastguard Worker bool signAlwaysShown; 144*0e209d39SAndroid Build Coastguard Worker 145*0e209d39SAndroid Build Coastguard Worker DecimalFormatProperties(); 146*0e209d39SAndroid Build Coastguard Worker 147*0e209d39SAndroid Build Coastguard Worker inline bool operator==(const DecimalFormatProperties& other) const { 148*0e209d39SAndroid Build Coastguard Worker return _equals(other, false); 149*0e209d39SAndroid Build Coastguard Worker } 150*0e209d39SAndroid Build Coastguard Worker 151*0e209d39SAndroid Build Coastguard Worker void clear(); 152*0e209d39SAndroid Build Coastguard Worker 153*0e209d39SAndroid Build Coastguard Worker /** 154*0e209d39SAndroid Build Coastguard Worker * Checks for equality to the default DecimalFormatProperties, but ignores the prescribed set of 155*0e209d39SAndroid Build Coastguard Worker * options for fast-path formatting. 156*0e209d39SAndroid Build Coastguard Worker */ 157*0e209d39SAndroid Build Coastguard Worker bool equalsDefaultExceptFastFormat() const; 158*0e209d39SAndroid Build Coastguard Worker 159*0e209d39SAndroid Build Coastguard Worker /** 160*0e209d39SAndroid Build Coastguard Worker * Returns the default DecimalFormatProperties instance. 161*0e209d39SAndroid Build Coastguard Worker */ 162*0e209d39SAndroid Build Coastguard Worker static const DecimalFormatProperties& getDefault(); 163*0e209d39SAndroid Build Coastguard Worker 164*0e209d39SAndroid Build Coastguard Worker private: 165*0e209d39SAndroid Build Coastguard Worker bool _equals(const DecimalFormatProperties& other, bool ignoreForFastFormat) const; 166*0e209d39SAndroid Build Coastguard Worker }; 167*0e209d39SAndroid Build Coastguard Worker 168*0e209d39SAndroid Build Coastguard Worker } // namespace number::impl 169*0e209d39SAndroid Build Coastguard Worker 170*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 171*0e209d39SAndroid Build Coastguard Worker 172*0e209d39SAndroid Build Coastguard Worker 173*0e209d39SAndroid Build Coastguard Worker #endif //__NUMBER_DECIMFMTPROPS_H__ 174*0e209d39SAndroid Build Coastguard Worker 175*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */ 176