ICU 65.1  65.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 RuleChain;
50 class PluralRuleParser;
51 class PluralKeywordEnumeration;
52 class AndConstraint;
53 class SharedPluralRules;
54 
55 namespace number {
56 class FormattedNumber;
57 }
58 
201 public:
202 
210  PluralRules(UErrorCode& status);
211 
216  PluralRules(const PluralRules& other);
217 
222  virtual ~PluralRules();
223 
228  PluralRules* clone() const;
229 
234  PluralRules& operator=(const PluralRules&);
235 
246  static PluralRules* U_EXPORT2 createRules(const UnicodeString& description,
247  UErrorCode& status);
248 
257  static PluralRules* U_EXPORT2 createDefaultRules(UErrorCode& status);
258 
275  static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UErrorCode& status);
276 
293  static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UPluralType type, UErrorCode& status);
294 
295 #ifndef U_HIDE_INTERNAL_API
296 
301  static StringEnumeration* U_EXPORT2 getAvailableLocales(UErrorCode &status);
302 
309  static UBool hasOverride(const Locale &locale);
310 
316  static PluralRules* U_EXPORT2 internalForLocale(const Locale& locale, UPluralType type, UErrorCode& status);
317 
325  static const SharedPluralRules* U_EXPORT2 createSharedInstance(
326  const Locale& locale, UPluralType type, UErrorCode& status);
327 
328 
329 #endif /* U_HIDE_INTERNAL_API */
330 
340  UnicodeString select(int32_t number) const;
341 
351  UnicodeString select(double number) const;
352 
353 #ifndef U_HIDE_DRAFT_API
354 
369  UnicodeString select(const number::FormattedNumber& number, UErrorCode& status) const;
370 #endif /* U_HIDE_DRAFT_API */
371 
372 #ifndef U_HIDE_INTERNAL_API
373 
376  UnicodeString select(const IFixedDecimal &number) const;
377 #endif /* U_HIDE_INTERNAL_API */
378 
389  StringEnumeration* getKeywords(UErrorCode& status) const;
390 
391 #ifndef U_HIDE_DEPRECATED_API
392 
402  double getUniqueKeywordValue(const UnicodeString& keyword);
403 
424  int32_t getAllKeywordValues(const UnicodeString &keyword,
425  double *dest, int32_t destCapacity,
426  UErrorCode& status);
427 #endif /* U_HIDE_DEPRECATED_API */
428 
447  int32_t getSamples(const UnicodeString &keyword,
448  double *dest, int32_t destCapacity,
449  UErrorCode& status);
450 
460  UBool isKeyword(const UnicodeString& keyword) const;
461 
462 
469  UnicodeString getKeywordOther() const;
470 
471 #ifndef U_HIDE_INTERNAL_API
472 
476  UnicodeString getRules() const;
477 #endif /* U_HIDE_INTERNAL_API */
478 
487  virtual UBool operator==(const PluralRules& other) const;
488 
497  UBool operator!=(const PluralRules& other) const {return !operator==(other);}
498 
499 
506  static UClassID U_EXPORT2 getStaticClassID(void);
507 
513  virtual UClassID getDynamicClassID() const;
514 
515 
516 private:
517  RuleChain *mRules;
518 
519  PluralRules(); // default constructor not implemented
520  void parseDescription(const UnicodeString& ruleData, UErrorCode &status);
521  int32_t getNumberValue(const UnicodeString& token) const;
522  UnicodeString getRuleFromResource(const Locale& locale, UPluralType type, UErrorCode& status);
523  RuleChain *rulesForKeyword(const UnicodeString &keyword) const;
524 
529  UErrorCode mInternalStatus;
530 
531  friend class PluralRuleParser;
532 };
533 
534 U_NAMESPACE_END
535 
536 #endif /* #if !UCONFIG_NO_FORMATTING */
537 
538 #endif /* U_SHOW_CPLUSPLUS_API */
539 
540 #endif // _PLURRULE
541 //eof
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:200
C++ API: Base class for all formats.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
C API: Plural rules, select plural keywords for numeric values.
UBool operator!=(const PluralRules &other) const
Compares the inequality of two PluralRules objects.
Definition: plurrule.h:497
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:53
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
The result of a number formatting operation.
C++ API: Compatibility APIs for number formatting.
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195