ICU 77.1 77.1

plurrule.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2008-2015, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
8 *
9 *
10 * File PLURRULE.H
11 *
12 * Modification History:*
13 * Date Name Description
14 *
15 ********************************************************************************
16 */
17
18 #ifndef PLURRULE
19 #define PLURRULE
20
21 #include "unicode/utypes.h"
22
23 #if U_SHOW_CPLUSPLUS_API
24
30 #if !UCONFIG_NO_FORMATTING
31
32 #include "unicode/format.h"
33 #include "unicode/upluralrules.h"
34 #ifndef U_HIDE_INTERNAL_API
35 #include "unicode/numfmt.h"
36 #endif /* U_HIDE_INTERNAL_API */
37
43 #define UPLRULES_NO_UNIQUE_VALUE ((double)-0.00123456777)
44
45 U_NAMESPACE_BEGIN
46
47 class Hashtable;
48 class IFixedDecimal;
49 class FixedDecimal;
50 class RuleChain;
51 class PluralRuleParser;
52 class PluralKeywordEnumeration;
53 class AndConstraint;
54 class SharedPluralRules;
55 class StandardPluralRanges;
56
57 namespace number {
58 class FormattedNumber;
59 class FormattedNumberRange;
60 namespace impl {
61 class UFormattedNumberRangeData;
62 class DecimalQuantity;
63 class DecNum;
64 }
65 }
66
67 #ifndef U_HIDE_INTERNAL_API
68 using icu::number::impl::DecimalQuantity;
69 #endif /* U_HIDE_INTERNAL_API */
70
212 class U_I18N_API PluralRules : public UObject {
213 public:
214
222 PluralRules(UErrorCode& status);
223
228 PluralRules(const PluralRules& other);
229
234 virtual ~PluralRules();
235
240 PluralRules* clone() const;
241
246 PluralRules& operator=(const PluralRules&);
247
258 static PluralRules* U_EXPORT2 createRules(const UnicodeString& description,
259 UErrorCode& status);
260
269 static PluralRules* U_EXPORT2 createDefaultRules(UErrorCode& status);
270
287 static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UErrorCode& status);
288
305 static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UPluralType type, UErrorCode& status);
306
307 #ifndef U_HIDE_INTERNAL_API
313 static StringEnumeration* U_EXPORT2 getAvailableLocales(UErrorCode &status);
314
320 static PluralRules* U_EXPORT2 internalForLocale(const Locale& locale, UPluralType type, UErrorCode& status);
321
329 static const SharedPluralRules* U_EXPORT2 createSharedInstance(
330 const Locale& locale, UPluralType type, UErrorCode& status);
331
332
333 #endif /* U_HIDE_INTERNAL_API */
334
344 UnicodeString select(int32_t number) const;
345
355 UnicodeString select(double number) const;
356
372 UnicodeString select(const number::FormattedNumber& number, UErrorCode& status) const;
373
390 UnicodeString select(const number::FormattedNumberRange& range, UErrorCode& status) const;
391
392 #ifndef U_HIDE_INTERNAL_API
396 UnicodeString select(const IFixedDecimal &number) const;
400 UnicodeString select(const number::impl::UFormattedNumberRangeData* urange, UErrorCode& status) const;
401 #endif /* U_HIDE_INTERNAL_API */
402
413 StringEnumeration* getKeywords(UErrorCode& status) const;
414
415 #ifndef U_HIDE_DEPRECATED_API
426 double getUniqueKeywordValue(const UnicodeString& keyword);
427
448 int32_t getAllKeywordValues(const UnicodeString &keyword,
449 double *dest, int32_t destCapacity,
450 UErrorCode& status);
451 #endif /* U_HIDE_DEPRECATED_API */
452
471 int32_t getSamples(const UnicodeString &keyword,
472 double *dest, int32_t destCapacity,
473 UErrorCode& status);
474
475 #ifndef U_HIDE_INTERNAL_API
496 int32_t getSamples(const UnicodeString &keyword,
497 DecimalQuantity *dest, int32_t destCapacity,
498 UErrorCode& status);
499 #endif /* U_HIDE_INTERNAL_API */
500
510 UBool isKeyword(const UnicodeString& keyword) const;
511
512
519 UnicodeString getKeywordOther() const;
520
521 #ifndef U_HIDE_INTERNAL_API
526 UnicodeString getRules() const;
527 #endif /* U_HIDE_INTERNAL_API */
528
537 virtual bool operator==(const PluralRules& other) const;
538
547 bool operator!=(const PluralRules& other) const {return !operator==(other);}
548
549
556 static UClassID U_EXPORT2 getStaticClassID();
557
563 virtual UClassID getDynamicClassID() const override;
564
565
566 private:
567 RuleChain *mRules;
568 StandardPluralRanges *mStandardPluralRanges;
569
570 PluralRules() = delete; // default constructor not implemented
571 UnicodeString getRuleFromResource(const Locale& locale, UPluralType type, UErrorCode& status);
572 RuleChain *rulesForKeyword(const UnicodeString &keyword) const;
573 PluralRules *clone(UErrorCode& status) const;
574
579 UErrorCode mInternalStatus;
580
581 friend class PluralRuleParser;
582 };
583
584 U_NAMESPACE_END
585
586 #endif /* #if !UCONFIG_NO_FORMATTING */
587
588 #endif /* U_SHOW_CPLUSPLUS_API */
589
590 #endif // _PLURRULE
591 //eof
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:212
icu::PluralRules::operator=
PluralRules & operator=(const PluralRules &)
Assignment operator.
icu::PluralRules::getKeywords
StringEnumeration * getKeywords(UErrorCode &status) const
Returns a list of all rule keywords used in this PluralRules object.
icu::PluralRules::select
UnicodeString select(const number::FormattedNumber &number, UErrorCode &status) const
Given a formatted number, returns the keyword of the first rule that applies to the number.
icu::PluralRules::select
UnicodeString select(const number::FormattedNumberRange &range, UErrorCode &status) const
Given a formatted number range, returns the overall plural form of the range.
icu::PluralRules::getDynamicClassID
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::PluralRules::forLocale
static PluralRules * forLocale(const Locale &locale, UErrorCode &status)
Provides access to the predefined cardinal-number PluralRules for a given locale.
icu::PluralRules::getAvailableLocales
static StringEnumeration * getAvailableLocales(UErrorCode &status)
Return a StringEnumeration over the locales for which there is plurals data.
icu::PluralRules::internalForLocale
static PluralRules * internalForLocale(const Locale &locale, UPluralType type, UErrorCode &status)
For ICU use only.
icu::PluralRules::createRules
static PluralRules * createRules(const UnicodeString &description, UErrorCode &status)
Creates a PluralRules from a description if it is parsable, otherwise returns nullptr.
icu::PluralRules::createDefaultRules
static PluralRules * createDefaultRules(UErrorCode &status)
The default rules that accept any number.
icu::PluralRules::isKeyword
UBool isKeyword(const UnicodeString &keyword) const
Returns true if the given keyword is defined in this PluralRules object.
icu::PluralRules::PluralRules
PluralRules(UErrorCode &status)
Constructor.
icu::PluralRules::PluralRules
PluralRules(const PluralRules &other)
Copy constructor.
icu::PluralRules::getUniqueKeywordValue
double getUniqueKeywordValue(const UnicodeString &keyword)
Deprecated Function, does not return useful results.
icu::PluralRules::select
UnicodeString select(const number::impl::UFormattedNumberRangeData *urange, UErrorCode &status) const
icu::PluralRules::~PluralRules
virtual ~PluralRules()
Destructor.
icu::PluralRules::clone
PluralRules * clone() const
Clone.
icu::PluralRules::select
UnicodeString select(double number) const
Given a floating-point number, returns the keyword of the first rule that applies to the number.
icu::PluralRules::getKeywordOther
UnicodeString getKeywordOther() const
Returns keyword for default plural form.
icu::PluralRules::getRules
UnicodeString getRules() const
icu::PluralRules::createSharedInstance
static const SharedPluralRules * createSharedInstance(const Locale &locale, UPluralType type, UErrorCode &status)
For ICU use only.
icu::PluralRules::forLocale
static PluralRules * forLocale(const Locale &locale, UPluralType type, UErrorCode &status)
Provides access to the predefined PluralRules for a given locale and the plural type.
icu::PluralRules::select
UnicodeString select(int32_t number) const
Given an integer, returns the keyword of the first rule that applies to the number.
icu::PluralRules::getSamples
int32_t getSamples(const UnicodeString &keyword, double *dest, int32_t destCapacity, UErrorCode &status)
Returns sample values for which select() would return the keyword.
icu::PluralRules::getSamples
int32_t getSamples(const UnicodeString &keyword, DecimalQuantity *dest, int32_t destCapacity, UErrorCode &status)
Internal-only function that returns DecimalQuantitys instead of doubles.
icu::PluralRules::operator!=
bool operator!=(const PluralRules &other) const
Compares the inequality of two PluralRules objects.
Definition: plurrule.h:547
icu::PluralRules::getAllKeywordValues
int32_t getAllKeywordValues(const UnicodeString &keyword, double *dest, int32_t destCapacity, UErrorCode &status)
Deprecated Function, does not produce useful results.
icu::PluralRules::select
UnicodeString select(const IFixedDecimal &number) const
icu::PluralRules::operator==
virtual bool operator==(const PluralRules &other) const
Compares the equality of two PluralRules objects.
icu::PluralRules::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::number::FormattedNumberRange
The result of a number range formatting operation.
Definition: numberrangeformatter.h:610
icu::number::FormattedNumber
The result of a number formatting operation.
Definition: formattednumber.h:48
format.h
C++ API: Base class for all formats.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
numfmt.h
C++ API: Compatibility APIs for number formatting.
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
upluralrules.h
C API: Plural rules, select plural keywords for numeric values.
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:59
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316