annotate modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/i18n/number_patternmodifier.h @ 11038:20a8447c71c6

8207159: Update ICU to version 62.1 Reviewed-by: mbilla, kcr, ghb
author arajkumar
date Fri, 24 Aug 2018 15:06:40 +0530
parents
children
rev   line source
arajkumar@11038 1 // © 2017 and later: Unicode, Inc. and others.
arajkumar@11038 2 // License & terms of use: http://www.unicode.org/copyright.html
arajkumar@11038 3
arajkumar@11038 4 #include "unicode/utypes.h"
arajkumar@11038 5
arajkumar@11038 6 #if !UCONFIG_NO_FORMATTING
arajkumar@11038 7 #ifndef __NUMBER_PATTERNMODIFIER_H__
arajkumar@11038 8 #define __NUMBER_PATTERNMODIFIER_H__
arajkumar@11038 9
arajkumar@11038 10 #include "standardplural.h"
arajkumar@11038 11 #include "unicode/numberformatter.h"
arajkumar@11038 12 #include "number_patternstring.h"
arajkumar@11038 13 #include "number_types.h"
arajkumar@11038 14 #include "number_modifiers.h"
arajkumar@11038 15 #include "number_utils.h"
arajkumar@11038 16 #include "number_currencysymbols.h"
arajkumar@11038 17
arajkumar@11038 18 U_NAMESPACE_BEGIN
arajkumar@11038 19
arajkumar@11038 20 // Export an explicit template instantiation of the LocalPointer that is used as a
arajkumar@11038 21 // data member of ParameterizedModifier.
arajkumar@11038 22 // (When building DLLs for Windows this is required.)
arajkumar@11038 23 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
arajkumar@11038 24 // Ignore warning 4661 as LocalPointerBase does not use operator== or operator!=
arajkumar@11038 25 #pragma warning(suppress: 4661)
arajkumar@11038 26 template class U_I18N_API LocalPointerBase<number::impl::ParameterizedModifier>;
arajkumar@11038 27 template class U_I18N_API LocalPointer<number::impl::ParameterizedModifier>;
arajkumar@11038 28 #endif
arajkumar@11038 29
arajkumar@11038 30 namespace number {
arajkumar@11038 31 namespace impl {
arajkumar@11038 32
arajkumar@11038 33 // Forward declaration
arajkumar@11038 34 class MutablePatternModifier;
arajkumar@11038 35
arajkumar@11038 36 // Exported as U_I18N_API because it is needed for the unit test PatternModifierTest
arajkumar@11038 37 class U_I18N_API ImmutablePatternModifier : public MicroPropsGenerator, public UMemory {
arajkumar@11038 38 public:
arajkumar@11038 39 ~ImmutablePatternModifier() U_OVERRIDE = default;
arajkumar@11038 40
arajkumar@11038 41 void processQuantity(DecimalQuantity&, MicroProps& micros, UErrorCode& status) const U_OVERRIDE;
arajkumar@11038 42
arajkumar@11038 43 void applyToMicros(MicroProps& micros, DecimalQuantity& quantity) const;
arajkumar@11038 44
arajkumar@11038 45 const Modifier* getModifier(int8_t signum, StandardPlural::Form plural) const;
arajkumar@11038 46
arajkumar@11038 47 private:
arajkumar@11038 48 ImmutablePatternModifier(ParameterizedModifier* pm, const PluralRules* rules,
arajkumar@11038 49 const MicroPropsGenerator* parent);
arajkumar@11038 50
arajkumar@11038 51 const LocalPointer<ParameterizedModifier> pm;
arajkumar@11038 52 const PluralRules* rules;
arajkumar@11038 53 const MicroPropsGenerator* parent;
arajkumar@11038 54
arajkumar@11038 55 friend class MutablePatternModifier;
arajkumar@11038 56 };
arajkumar@11038 57
arajkumar@11038 58 /**
arajkumar@11038 59 * This class is a {@link Modifier} that wraps a decimal format pattern. It applies the pattern's affixes in
arajkumar@11038 60 * {@link Modifier#apply}.
arajkumar@11038 61 *
arajkumar@11038 62 * <p>
arajkumar@11038 63 * In addition to being a Modifier, this class contains the business logic for substituting the correct locale symbols
arajkumar@11038 64 * into the affixes of the decimal format pattern.
arajkumar@11038 65 *
arajkumar@11038 66 * <p>
arajkumar@11038 67 * In order to use this class, create a new instance and call the following four setters: {@link #setPatternInfo},
arajkumar@11038 68 * {@link #setPatternAttributes}, {@link #setSymbols}, and {@link #setNumberProperties}. After calling these four
arajkumar@11038 69 * setters, the instance will be ready for use as a Modifier.
arajkumar@11038 70 *
arajkumar@11038 71 * <p>
arajkumar@11038 72 * This is a MUTABLE, NON-THREAD-SAFE class designed for performance. Do NOT save references to this or attempt to use
arajkumar@11038 73 * it from multiple threads! Instead, you can obtain a safe, immutable decimal format pattern modifier by calling
arajkumar@11038 74 * {@link MutablePatternModifier#createImmutable}, in effect treating this instance as a builder for the immutable
arajkumar@11038 75 * variant.
arajkumar@11038 76 */
arajkumar@11038 77 class U_I18N_API MutablePatternModifier
arajkumar@11038 78 : public MicroPropsGenerator,
arajkumar@11038 79 public Modifier,
arajkumar@11038 80 public SymbolProvider,
arajkumar@11038 81 public UMemory {
arajkumar@11038 82 public:
arajkumar@11038 83
arajkumar@11038 84 ~MutablePatternModifier() U_OVERRIDE = default;
arajkumar@11038 85
arajkumar@11038 86 /**
arajkumar@11038 87 * @param isStrong
arajkumar@11038 88 * Whether the modifier should be considered strong. For more information, see
arajkumar@11038 89 * {@link Modifier#isStrong()}. Most of the time, decimal format pattern modifiers should be considered
arajkumar@11038 90 * as non-strong.
arajkumar@11038 91 */
arajkumar@11038 92 explicit MutablePatternModifier(bool isStrong);
arajkumar@11038 93
arajkumar@11038 94 /**
arajkumar@11038 95 * Sets a reference to the parsed decimal format pattern, usually obtained from
arajkumar@11038 96 * {@link PatternStringParser#parseToPatternInfo(String)}, but any implementation of {@link AffixPatternProvider} is
arajkumar@11038 97 * accepted.
arajkumar@11038 98 */
arajkumar@11038 99 void setPatternInfo(const AffixPatternProvider *patternInfo);
arajkumar@11038 100
arajkumar@11038 101 /**
arajkumar@11038 102 * Sets attributes that imply changes to the literal interpretation of the pattern string affixes.
arajkumar@11038 103 *
arajkumar@11038 104 * @param signDisplay
arajkumar@11038 105 * Whether to force a plus sign on positive numbers.
arajkumar@11038 106 * @param perMille
arajkumar@11038 107 * Whether to substitute the percent sign in the pattern with a permille sign.
arajkumar@11038 108 */
arajkumar@11038 109 void setPatternAttributes(UNumberSignDisplay signDisplay, bool perMille);
arajkumar@11038 110
arajkumar@11038 111 /**
arajkumar@11038 112 * Sets locale-specific details that affect the symbols substituted into the pattern string affixes.
arajkumar@11038 113 *
arajkumar@11038 114 * @param symbols
arajkumar@11038 115 * The desired instance of DecimalFormatSymbols.
arajkumar@11038 116 * @param currencySymbols
arajkumar@11038 117 * The currency symbols to be used when substituting currency values into the affixes.
arajkumar@11038 118 * @param unitWidth
arajkumar@11038 119 * The width used to render currencies.
arajkumar@11038 120 * @param rules
arajkumar@11038 121 * Required if the triple currency sign, "¤¤¤", appears in the pattern, which can be determined from the
arajkumar@11038 122 * convenience method {@link #needsPlurals()}.
arajkumar@11038 123 */
arajkumar@11038 124 void setSymbols(const DecimalFormatSymbols* symbols, const CurrencySymbols* currencySymbols,
arajkumar@11038 125 UNumberUnitWidth unitWidth, const PluralRules* rules);
arajkumar@11038 126
arajkumar@11038 127 /**
arajkumar@11038 128 * Sets attributes of the current number being processed.
arajkumar@11038 129 *
arajkumar@11038 130 * @param signum
arajkumar@11038 131 * -1 if negative; +1 if positive; or 0 if zero.
arajkumar@11038 132 * @param plural
arajkumar@11038 133 * The plural form of the number, required only if the pattern contains the triple
arajkumar@11038 134 * currency sign, "¤¤¤" (and as indicated by {@link #needsPlurals()}).
arajkumar@11038 135 */
arajkumar@11038 136 void setNumberProperties(int8_t signum, StandardPlural::Form plural);
arajkumar@11038 137
arajkumar@11038 138 /**
arajkumar@11038 139 * Returns true if the pattern represented by this MurkyModifier requires a plural keyword in order to localize.
arajkumar@11038 140 * This is currently true only if there is a currency long name placeholder in the pattern ("¤¤¤").
arajkumar@11038 141 */
arajkumar@11038 142 bool needsPlurals() const;
arajkumar@11038 143
arajkumar@11038 144 /**
arajkumar@11038 145 * Creates a new quantity-dependent Modifier that behaves the same as the current instance, but which is immutable
arajkumar@11038 146 * and can be saved for future use. The number properties in the current instance are mutated; all other properties
arajkumar@11038 147 * are left untouched.
arajkumar@11038 148 *
arajkumar@11038 149 * <p>
arajkumar@11038 150 * The resulting modifier cannot be used in a QuantityChain.
arajkumar@11038 151 *
arajkumar@11038 152 * <p>
arajkumar@11038 153 * CREATES A NEW HEAP OBJECT; THE CALLER GETS OWNERSHIP.
arajkumar@11038 154 *
arajkumar@11038 155 * @return An immutable that supports both positive and negative numbers.
arajkumar@11038 156 */
arajkumar@11038 157 ImmutablePatternModifier *createImmutable(UErrorCode &status);
arajkumar@11038 158
arajkumar@11038 159 /**
arajkumar@11038 160 * Creates a new quantity-dependent Modifier that behaves the same as the current instance, but which is immutable
arajkumar@11038 161 * and can be saved for future use. The number properties in the current instance are mutated; all other properties
arajkumar@11038 162 * are left untouched.
arajkumar@11038 163 *
arajkumar@11038 164 * <p>
arajkumar@11038 165 * CREATES A NEW HEAP OBJECT; THE CALLER GETS OWNERSHIP.
arajkumar@11038 166 *
arajkumar@11038 167 * @param parent
arajkumar@11038 168 * The QuantityChain to which to chain this immutable.
arajkumar@11038 169 * @return An immutable that supports both positive and negative numbers.
arajkumar@11038 170 */
arajkumar@11038 171 ImmutablePatternModifier *
arajkumar@11038 172 createImmutableAndChain(const MicroPropsGenerator *parent, UErrorCode &status);
arajkumar@11038 173
arajkumar@11038 174 MicroPropsGenerator &addToChain(const MicroPropsGenerator *parent);
arajkumar@11038 175
arajkumar@11038 176 void processQuantity(DecimalQuantity &, MicroProps &micros, UErrorCode &status) const U_OVERRIDE;
arajkumar@11038 177
arajkumar@11038 178 int32_t apply(NumberStringBuilder &output, int32_t leftIndex, int32_t rightIndex,
arajkumar@11038 179 UErrorCode &status) const U_OVERRIDE;
arajkumar@11038 180
arajkumar@11038 181 int32_t getPrefixLength(UErrorCode &status) const U_OVERRIDE;
arajkumar@11038 182
arajkumar@11038 183 int32_t getCodePointCount(UErrorCode &status) const U_OVERRIDE;
arajkumar@11038 184
arajkumar@11038 185 bool isStrong() const U_OVERRIDE;
arajkumar@11038 186
arajkumar@11038 187 /**
arajkumar@11038 188 * Returns the string that substitutes a given symbol type in a pattern.
arajkumar@11038 189 */
arajkumar@11038 190 UnicodeString getSymbol(AffixPatternType type) const U_OVERRIDE;
arajkumar@11038 191
arajkumar@11038 192 UnicodeString toUnicodeString() const;
arajkumar@11038 193
arajkumar@11038 194 private:
arajkumar@11038 195 // Modifier details (initialized in constructor)
arajkumar@11038 196 const bool fStrong;
arajkumar@11038 197
arajkumar@11038 198 // Pattern details (initialized in setPatternInfo and setPatternAttributes)
arajkumar@11038 199 const AffixPatternProvider *patternInfo;
arajkumar@11038 200 UNumberSignDisplay signDisplay;
arajkumar@11038 201 bool perMilleReplacesPercent;
arajkumar@11038 202
arajkumar@11038 203 // Symbol details (initialized in setSymbols)
arajkumar@11038 204 const DecimalFormatSymbols *symbols;
arajkumar@11038 205 UNumberUnitWidth unitWidth;
arajkumar@11038 206 const CurrencySymbols *currencySymbols;
arajkumar@11038 207 const PluralRules *rules;
arajkumar@11038 208
arajkumar@11038 209 // Number details (initialized in setNumberProperties)
arajkumar@11038 210 int8_t signum;
arajkumar@11038 211 StandardPlural::Form plural;
arajkumar@11038 212
arajkumar@11038 213 // QuantityChain details (initialized in addToChain)
arajkumar@11038 214 const MicroPropsGenerator *parent;
arajkumar@11038 215
arajkumar@11038 216 // Transient fields for rendering
arajkumar@11038 217 UnicodeString currentAffix;
arajkumar@11038 218
arajkumar@11038 219 /**
arajkumar@11038 220 * Uses the current properties to create a single {@link ConstantMultiFieldModifier} with currency spacing support
arajkumar@11038 221 * if required.
arajkumar@11038 222 *
arajkumar@11038 223 * <p>
arajkumar@11038 224 * CREATES A NEW HEAP OBJECT; THE CALLER GETS OWNERSHIP.
arajkumar@11038 225 *
arajkumar@11038 226 * @param a
arajkumar@11038 227 * A working NumberStringBuilder object; passed from the outside to prevent the need to create many new
arajkumar@11038 228 * instances if this method is called in a loop.
arajkumar@11038 229 * @param b
arajkumar@11038 230 * Another working NumberStringBuilder object.
arajkumar@11038 231 * @return The constant modifier object.
arajkumar@11038 232 */
arajkumar@11038 233 ConstantMultiFieldModifier *createConstantModifier(UErrorCode &status);
arajkumar@11038 234
arajkumar@11038 235 int32_t insertPrefix(NumberStringBuilder &sb, int position, UErrorCode &status);
arajkumar@11038 236
arajkumar@11038 237 int32_t insertSuffix(NumberStringBuilder &sb, int position, UErrorCode &status);
arajkumar@11038 238
arajkumar@11038 239 void prepareAffix(bool isPrefix);
arajkumar@11038 240 };
arajkumar@11038 241
arajkumar@11038 242
arajkumar@11038 243 } // namespace impl
arajkumar@11038 244 } // namespace number
arajkumar@11038 245 U_NAMESPACE_END
arajkumar@11038 246
arajkumar@11038 247 #endif //__NUMBER_PATTERNMODIFIER_H__
arajkumar@11038 248
arajkumar@11038 249 #endif /* #if !UCONFIG_NO_FORMATTING */