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