]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/pluralaffix.h
2 *******************************************************************************
3 * Copyright (C) 2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 * created on: 2015jan06
9 * created by: Travis Keep
12 #ifndef __PLURALAFFIX_H__
13 #define __PLURALAFFIX_H__
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_FORMATTING
19 #include "unicode/unum.h"
20 #include "unicode/uobject.h"
22 #include "digitaffix.h"
23 #include "pluralmap.h"
27 class FieldPositionHandler
;
29 // Export an explicit template instantiation.
31 // MSVC requires this, even though it should not be necessary.
32 // No direct access leaks out of the i18n library.
34 // Macintosh produces duplicate definition linker errors with the explicit template
37 #if !U_PLATFORM_IS_DARWIN_BASED
38 template class U_I18N_API PluralMap
<DigitAffix
>;
43 * A plural aware prefix or suffix of a formatted number.
45 * PluralAffix is essentially a map of DigitAffix objects keyed by plural
46 * category. The 'other' category is the default and always has some
47 * value. The rest of the categories are optional. Querying for a category that
48 * is not set always returns the DigitAffix stored in the 'other' category.
50 * To use one of these objects, build it up first using append() and
51 * setVariant() methods. Once built, leave unchanged and let multiple threads
54 * The following code is sample code for building up:
58 * and storing it in "negativeCurrencyPrefix"
60 * UErrorCode status = U_ZERO_ERROR;
62 * PluralAffix negativeCurrencyPrefix;
64 * PluralAffix currencyName;
65 * currencyName.setVariant("one", "US Dollar", status);
66 * currencyName.setVariant("other", "US Dollars", status);
68 * negativeCurrencyPrefix.append(currencyName, UNUM_CURRENCY_FIELD, status);
69 * negativeCurrencyPrefix.append(" ");
70 * negativeCurrencyPrefix.append("-", UNUM_SIGN_FIELD, status);
72 class U_I18N_API PluralAffix
: public UMemory
{
76 * Create empty PluralAffix.
78 PluralAffix() : affixes() { }
81 * Create a PluralAffix where the 'other' variant is otherVariant.
83 PluralAffix(const DigitAffix
&otherVariant
) : affixes(otherVariant
) { }
86 * Sets a particular variant for a plural category while overwriting
87 * anything that may have been previously stored for that plural
88 * category. The set value has no field annotations.
89 * @param category "one", "two", "few", ...
90 * @param variant the variant to store under the particular category
91 * @param status Any error returned here.
95 const UnicodeString
&variant
,
98 * Make the 'other' variant be the empty string with no field annotations
99 * and remove the variants for the rest of the plural categories.
104 * Append value to all set plural categories. If fieldId present, value
105 * is that field type.
107 void appendUChar(UChar value
, int32_t fieldId
=UNUM_FIELD_COUNT
);
110 * Append value to all set plural categories. If fieldId present, value
111 * is that field type.
113 void append(const UnicodeString
&value
, int32_t fieldId
=UNUM_FIELD_COUNT
);
116 * Append value to all set plural categories. If fieldId present, value
117 * is that field type.
119 void append(const UChar
*value
, int32_t charCount
, int32_t fieldId
=UNUM_FIELD_COUNT
);
122 * Append the value for each plural category in rhs to the corresponding
123 * plural category in this instance. Each value appended from rhs is
127 const PluralAffix
&rhs
,
131 * Get the DigitAffix for a paricular category such as "zero", "one", ...
132 * If the particular category is not set, returns the 'other' category
133 * which is always set.
135 const DigitAffix
&getByCategory(const char *category
) const;
138 * Get the DigitAffix for a paricular category such as "zero", "one", ...
139 * If the particular category is not set, returns the 'other' category
140 * which is always set.
142 const DigitAffix
&getByCategory(const UnicodeString
&category
) const;
145 * Get the DigitAffix for the other category which is always set.
147 const DigitAffix
&getOtherVariant() const {
148 return affixes
.getOther();
152 * Returns TRUE if this instance has variants stored besides the "other"
155 UBool
hasMultipleVariants() const;
158 * Returns TRUE if this instance equals rhs.
160 UBool
equals(const PluralAffix
&rhs
) const {
161 return affixes
.equals(rhs
.affixes
, &eq
);
165 PluralMap
<DigitAffix
> affixes
;
167 static UBool
eq(const DigitAffix
&x
, const DigitAffix
&y
) {
174 #endif /* #if !UCONFIG_NO_FORMATTING */
175 #endif // __PLURALAFFIX_H__