ICU 60.2  60.2
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 
28 #if !UCONFIG_NO_FORMATTING
29 
30 #include "unicode/format.h"
31 #include "unicode/upluralrules.h"
32 #ifndef U_HIDE_INTERNAL_API
33 #include "unicode/numfmt.h"
34 #endif /* U_HIDE_INTERNAL_API */
35 
41 #define UPLRULES_NO_UNIQUE_VALUE ((double)-0.00123456777)
42 
44 
45 class Hashtable;
46 class IFixedDecimal;
47 class VisibleDigitsWithExponent;
48 class RuleChain;
49 class PluralRuleParser;
50 class PluralKeywordEnumeration;
51 class AndConstraint;
52 class SharedPluralRules;
53 
198 public:
199 
207  PluralRules(UErrorCode& status);
208 
213  PluralRules(const PluralRules& other);
214 
219  virtual ~PluralRules();
220 
225  PluralRules* clone() const;
226 
231  PluralRules& operator=(const PluralRules&);
232 
243  static PluralRules* U_EXPORT2 createRules(const UnicodeString& description,
244  UErrorCode& status);
245 
254  static PluralRules* U_EXPORT2 createDefaultRules(UErrorCode& status);
255 
272  static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UErrorCode& status);
273 
290  static PluralRules* U_EXPORT2 forLocale(const Locale& locale, UPluralType type, UErrorCode& status);
291 
292 #ifndef U_HIDE_INTERNAL_API
293 
298  static StringEnumeration* U_EXPORT2 getAvailableLocales(UErrorCode &status);
299 
306  static UBool hasOverride(const Locale &locale);
307 
313  static PluralRules* U_EXPORT2 internalForLocale(const Locale& locale, UPluralType type, UErrorCode& status);
314 
322  static const SharedPluralRules* U_EXPORT2 createSharedInstance(
323  const Locale& locale, UPluralType type, UErrorCode& status);
324 
325 
326 #endif /* U_HIDE_INTERNAL_API */
327 
337  UnicodeString select(int32_t number) const;
338 
348  UnicodeString select(double number) const;
349 
350 #ifndef U_HIDE_INTERNAL_API
351 
365  UnicodeString select(const Formattable& obj, const NumberFormat& fmt, UErrorCode& status) const;
366 
370  UnicodeString select(const IFixedDecimal &number) const;
374  UnicodeString select(const VisibleDigitsWithExponent &number) const;
375 #endif /* U_HIDE_INTERNAL_API */
376 
387  StringEnumeration* getKeywords(UErrorCode& status) const;
388 
389 #ifndef U_HIDE_DEPRECATED_API
390 
400  double getUniqueKeywordValue(const UnicodeString& keyword);
401 
422  int32_t getAllKeywordValues(const UnicodeString &keyword,
423  double *dest, int32_t destCapacity,
424  UErrorCode& status);
425 #endif /* U_HIDE_DEPRECATED_API */
426 
445  int32_t getSamples(const UnicodeString &keyword,
446  double *dest, int32_t destCapacity,
447  UErrorCode& status);
448 
458  UBool isKeyword(const UnicodeString& keyword) const;
459 
460 
467  UnicodeString getKeywordOther() const;
468 
469 #ifndef U_HIDE_INTERNAL_API
470 
474  UnicodeString getRules() const;
475 #endif /* U_HIDE_INTERNAL_API */
476 
485  virtual UBool operator==(const PluralRules& other) const;
486 
495  UBool operator!=(const PluralRules& other) const {return !operator==(other);}
496 
497 
504  static UClassID U_EXPORT2 getStaticClassID(void);
505 
511  virtual UClassID getDynamicClassID() const;
512 
513 
514 private:
515  RuleChain *mRules;
516 
517  PluralRules(); // default constructor not implemented
518  void parseDescription(const UnicodeString& ruleData, UErrorCode &status);
519  int32_t getNumberValue(const UnicodeString& token) const;
520  UnicodeString getRuleFromResource(const Locale& locale, UPluralType type, UErrorCode& status);
521  RuleChain *rulesForKeyword(const UnicodeString &keyword) const;
522 
523  friend class PluralRuleParser;
524 };
525 
527 
528 #endif /* #if !UCONFIG_NO_FORMATTING */
529 
530 #endif // _PLURRULE
531 //eof
Abstract base class for all number formats.
Definition: numfmt.h:174
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
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:93
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:57
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:197
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:360
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
C API: Plural rules, select plural keywords for numeric values.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UBool operator!=(const PluralRules &other) const
Compares the inequality of two PluralRules objects.
Definition: plurrule.h:495
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:50
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:286
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
C++ API: Abstract base class for all number formats.
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188