class PluralRules

Defined at line 212 of file ../../third_party/icu/latest/source/i18n/unicode/plurrule.h

Defines rules for mapping non-negative numeric values onto a small set of

keywords. Rules are constructed from a text description, consisting

of a series of keywords and conditions. The {

Public Methods

void PluralRules (UErrorCode & status)

Constructor.

ICU 4.0

Parameters

status Output param set to success/failure code on exit, which must not indicate a failure before the function call.
void PluralRules (const PluralRules & other)

Copy constructor.

ICU 4.0

bool operator!= (const PluralRules & other)

Compares the inequality of two PluralRules objects.

Parameters

other The PluralRules object to be compared with.

Returns

true if the given PluralRules is not the same as this

PluralRules; false otherwise.

ICU 4.0

Defined at line 547 of file ../../third_party/icu/latest/source/i18n/unicode/plurrule.h

void ~PluralRules ()

Destructor.

ICU 4.0

PluralRules * clone ()

Clone

ICU 4.0

PluralRules & operator= (const PluralRules & )

Assignment operator.

ICU 4.0

PluralRules * createRules (const UnicodeString & description, UErrorCode & status)

Creates a PluralRules from a description if it is parsable, otherwise

returns nullptr.

Parameters

description rule description
status Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns

new PluralRules pointer. nullptr if there is an error.

ICU 4.0

PluralRules * createDefaultRules (UErrorCode & status)

The default rules that accept any number.

Parameters

status Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns

new PluralRules pointer. nullptr if there is an error.

ICU 4.0

PluralRules * forLocale (const Locale & locale, UErrorCode & status)

Provides access to the predefined cardinal-number

PluralRules

for a given

locale.

Same as forLocale(locale, UPLURAL_TYPE_CARDINAL, status).

Parameters

locale The locale for which a PluralRules object is returned.
status Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns

The predefined

PluralRules

object pointer for

this locale. If there's no predefined rules for this locale,

the rules for the closest parent in the locale hierarchy

that has one will be returned. The final fallback always

returns the default 'other' rules.

ICU 4.0

PluralRules * forLocale (const Locale & locale, UPluralType type, UErrorCode & status)

Provides access to the predefined

PluralRules

for a given

locale and the plural type.

Parameters

locale The locale for which a PluralRules object is returned.
type The plural type (e.g., cardinal or ordinal).
status Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns

The predefined

PluralRules

object pointer for

this locale. If there's no predefined rules for this locale,

the rules for the closest parent in the locale hierarchy

that has one will be returned. The final fallback always

returns the default 'other' rules.

ICU 50

StringEnumeration * getAvailableLocales (UErrorCode & status)

Return a StringEnumeration over the locales for which there is plurals data.

Returns

a StringEnumeration over the locales available.

PluralRules * internalForLocale (const Locale & locale, UPluralType type, UErrorCode & status)

For ICU use only.

creates a SharedPluralRules object

const SharedPluralRules * createSharedInstance (const Locale & locale, UPluralType type, UErrorCode & status)

For ICU use only.

Returns handle to the shared, cached PluralRules instance.

Caller must call removeRef() on returned value once it is done with

the shared instance.

UnicodeString select (int32_t number)

Given an integer, returns the keyword of the first rule

that applies to the number. This function can be used with

isKeyword* functions to determine the keyword for default plural rules.

Parameters

number The number for which the rule has to be determined.

Returns

The keyword of the selected rule.

ICU 4.0

UnicodeString select (double number)

Given a floating-point number, returns the keyword of the first rule

that applies to the number. This function can be used with

isKeyword* functions to determine the keyword for default plural rules.

Parameters

number The number for which the rule has to be determined.

Returns

The keyword of the selected rule.

ICU 4.0

UnicodeString select (const number::FormattedNumber & number, UErrorCode & status)

Given a formatted number, returns the keyword of the first rule

that applies to the number. This function can be used with

isKeyword* functions to determine the keyword for default plural rules.

A FormattedNumber allows you to specify an exponent or trailing zeros,

which can affect the plural category. To get a FormattedNumber, see

NumberFormatter.

Parameters

number The number for which the rule has to be determined.
status Set if an error occurs while selecting plural keyword. This could happen if the FormattedNumber is invalid.

Returns

The keyword of the selected rule.

ICU 64

UnicodeString select (const number::FormattedNumberRange & range, UErrorCode & status)

Given a formatted number range, returns the overall plural form of the

range. For example, "3-5" returns "other" in English.

To get a FormattedNumberRange, see NumberRangeFormatter.

This method only works if PluralRules was created with a locale. If it was created

from PluralRules::createRules(), this method sets status code U_UNSUPPORTED_ERROR.

Parameters

range The number range onto which the rules will be applied.
status Set if an error occurs while selecting plural keyword. This could happen if the FormattedNumberRange is invalid, or if plural ranges data is unavailable.

Returns

The keyword of the selected rule.

ICU 68

UnicodeString select (const IFixedDecimal & number)
UnicodeString select (const number::impl::UFormattedNumberRangeData * urange, UErrorCode & status)
StringEnumeration * getKeywords (UErrorCode & status)

Returns a list of all rule keywords used in this

PluralRules

object. The rule 'other' is always present by default.

Parameters

status Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns

StringEnumeration with the keywords.

The caller must delete the object.

ICU 4.0

double getUniqueKeywordValue (const UnicodeString & keyword)

Deprecated Function, does not return useful results.

Originally intended to return a unique value for this keyword if it exists,

else the constant UPLRULES_NO_UNIQUE_VALUE.

Parameters

keyword The keyword.

Returns

Stub deprecated function returns UPLRULES_NO_UNIQUE_VALUE always.

int32_t getAllKeywordValues (const UnicodeString & keyword, double * dest, int32_t destCapacity, UErrorCode & status)

Deprecated Function, does not produce useful results.

Originally intended to return all the values for which select() would return the keyword.

If the keyword is unknown, returns no values, but this is not an error. If

the number of values is unlimited, returns no values and -1 as the

count.

The number of returned values is typically small.

Parameters

keyword The keyword.
dest Array into which to put the returned values. May be nullptr if destCapacity is 0.
destCapacity The capacity of the array, must be at least 0.
status The error code. Deprecated function, always sets U_UNSUPPORTED_ERROR.

Returns

The count of values available, or -1. This count

can be larger than destCapacity, but no more than

destCapacity values will be written.

int32_t getSamples (const UnicodeString & keyword, double * dest, int32_t destCapacity, UErrorCode & status)

Returns sample values for which select() would return the keyword. If

the keyword is unknown, returns no values, but this is not an error.

The number of returned values is typically small.

Parameters

keyword The keyword.
dest Array into which to put the returned values. May be nullptr if destCapacity is 0.
destCapacity The capacity of the array, must be at least 0.
status The error code.

Returns

The count of values written.

If more than destCapacity samples are available, then

only destCapacity are written, and destCapacity is returned as the count,

rather than setting a U_BUFFER_OVERFLOW_ERROR.

(The actual number of keyword values could be unlimited.)

ICU 4.8

int32_t getSamples (const UnicodeString & keyword, DecimalQuantity * dest, int32_t destCapacity, UErrorCode & status)

Internal-only function that returns DecimalQuantitys instead of doubles.

Returns sample values for which select() would return the keyword. If

the keyword is unknown, returns no values, but this is not an error.

The number of returned values is typically small.

Parameters

keyword The keyword.
dest Array into which to put the returned values. May be nullptr if destCapacity is 0.
destCapacity The capacity of the array, must be at least 0.
status The error code.

Returns

The count of values written.

If more than destCapacity samples are available, then

only destCapacity are written, and destCapacity is returned as the count,

rather than setting a U_BUFFER_OVERFLOW_ERROR.

(The actual number of keyword values could be unlimited.)

UBool isKeyword (const UnicodeString & keyword)

Returns true if the given keyword is defined in this

PluralRules

object.

Parameters

keyword the input keyword.

Returns

true if the input keyword is defined.

Otherwise, return false.

ICU 4.0

UnicodeString getKeywordOther ()

Returns keyword for default plural form.

Returns

keyword for default plural form.

ICU 4.0

UnicodeString getRules ()
bool operator== (const PluralRules & other)

Compares the equality of two PluralRules objects.

Parameters

other The other PluralRules object to be compared with.

Returns

true if the given PluralRules is the same as this

PluralRules; false otherwise.

ICU 4.0

UClassID getStaticClassID ()

ICU "poor man's RTTI", returns a UClassID for this class.

ICU 4.0

UClassID getDynamicClassID ()

ICU "poor man's RTTI", returns a UClassID for the actual class.

ICU 4.0

Friends

class PluralRuleParser