ICU 69.1 69.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 }
63 }
64
206 class U_I18N_API PluralRules : public UObject {
207 public:
208
216 PluralRules(UErrorCode& status);
217
222 PluralRules(const PluralRules& other);
223
228 virtual ~PluralRules();
229
234 PluralRules* clone() const;
235
240 PluralRules& operator=(const PluralRules&);
241
252 static PluralRules* U_EXPORT2 createRules(const UnicodeString& description,
253 UErrorCode& status);
254
263 static PluralRules* U_EXPORT2 createDefaultRules(UErrorCode& status);
264
281 static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UErrorCode& status);
282
299 static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UPluralType type, UErrorCode& status);
300
301 #ifndef U_HIDE_INTERNAL_API
302
307 static StringEnumeration* U_EXPORT2 getAvailableLocales(UErrorCode &status);
308
315 static UBool hasOverride(const Locale &locale);
316
322 static PluralRules* U_EXPORT2 internalForLocale(const Locale& locale, UPluralType type, UErrorCode& status);
323
331 static const SharedPluralRules* U_EXPORT2 createSharedInstance(
332 const Locale& locale, UPluralType type, UErrorCode& status);
333
334
335 #endif /* U_HIDE_INTERNAL_API */
336
346 UnicodeString select(int32_t number) const;
347
357 UnicodeString select(double number) const;
358
374 UnicodeString select(const number::FormattedNumber& number, UErrorCode& status) const;
375
376 #ifndef U_HIDE_DRAFT_API
377
393 UnicodeString select(const number::FormattedNumberRange& range, UErrorCode& status) const;
394 #endif // U_HIDE_DRAFT_API
395
396 #ifndef U_HIDE_INTERNAL_API
397
400 UnicodeString select(const IFixedDecimal &number) const;
404 UnicodeString select(const number::impl::UFormattedNumberRangeData* urange, UErrorCode& status) const;
405 #endif /* U_HIDE_INTERNAL_API */
406
417 StringEnumeration* getKeywords(UErrorCode& status) const;
418
419 #ifndef U_HIDE_DEPRECATED_API
420
430 double getUniqueKeywordValue(const UnicodeString& keyword);
431
452 int32_t getAllKeywordValues(const UnicodeString &keyword,
453 double *dest, int32_t destCapacity,
454 UErrorCode& status);
455 #endif /* U_HIDE_DEPRECATED_API */
456
475 int32_t getSamples(const UnicodeString &keyword,
476 double *dest, int32_t destCapacity,
477 UErrorCode& status);
478
479 #ifndef U_HIDE_INTERNAL_API
480
500 int32_t getSamples(const UnicodeString &keyword,
501 FixedDecimal *dest, int32_t destCapacity,
502 UErrorCode& status);
503 #endif /* U_HIDE_INTERNAL_API */
504
514 UBool isKeyword(const UnicodeString& keyword) const;
515
516
523 UnicodeString getKeywordOther() const;
524
525 #ifndef U_HIDE_INTERNAL_API
526
530 UnicodeString getRules() const;
531 #endif /* U_HIDE_INTERNAL_API */
532
541 virtual UBool operator==(const PluralRules& other) const;
542
551 UBool operator!=(const PluralRules& other) const {return !operator==(other);}
552
553
560 static UClassID U_EXPORT2 getStaticClassID(void);
561
567 virtual UClassID getDynamicClassID() const;
568
569
570 private:
571 RuleChain *mRules;
572 StandardPluralRanges *mStandardPluralRanges;
573
574 PluralRules(); // default constructor not implemented
575 void parseDescription(const UnicodeString& ruleData, UErrorCode &status);
576 int32_t getNumberValue(const UnicodeString& token) const;
577 UnicodeString getRuleFromResource(const Locale& locale, UPluralType type, UErrorCode& status);
578 RuleChain *rulesForKeyword(const UnicodeString &keyword) const;
579 PluralRules *clone(UErrorCode& status) const;
580
585 UErrorCode mInternalStatus;
586
587 friend class PluralRuleParser;
588 };
589
590 U_NAMESPACE_END
591
592 #endif /* #if !UCONFIG_NO_FORMATTING */
593
594 #endif /* U_SHOW_CPLUSPLUS_API */
595
596 #endif // _PLURRULE
597 //eof
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:58
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_I18N_API
#define U_I18N_API
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
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.
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:206
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
icu::number::FormattedNumberRange
The result of a number range formatting operation.
Definition: numberrangeformatter.h:581
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
icu::number::FormattedNumber
The result of a number formatting operation.
Definition: numberformatter.h:2635
numfmt.h
C++ API: Compatibility APIs for number formatting.
icu::PluralRules::operator!=
UBool operator!=(const PluralRules &other) const
Compares the inequality of two PluralRules objects.
Definition: plurrule.h:551
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
upluralrules.h
C API: Plural rules, select plural keywords for numeric values.