ICU 63.1  63.1
plurfmt.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) 2007-2014, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
8 *
9 
10 * File PLURFMT.H
11 ********************************************************************************
12 */
13 
14 #ifndef PLURFMT
15 #define PLURFMT
16 
17 #include "unicode/utypes.h"
18 
24 #if !UCONFIG_NO_FORMATTING
25 
26 #include "unicode/messagepattern.h"
27 #include "unicode/numfmt.h"
28 #include "unicode/plurrule.h"
29 
31 
32 class Hashtable;
33 class NFRule;
34 
147 public:
148 
157  PluralFormat(UErrorCode& status);
158 
168  PluralFormat(const Locale& locale, UErrorCode& status);
169 
179  PluralFormat(const PluralRules& rules, UErrorCode& status);
180 
197  PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
198 
209  PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
210 
221  PluralFormat(const UnicodeString& pattern, UErrorCode& status);
222 
237  PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
238 
250  PluralFormat(const PluralRules& rules,
251  const UnicodeString& pattern,
252  UErrorCode& status);
253 
268  PluralFormat(const Locale& locale,
269  const PluralRules& rules,
270  const UnicodeString& pattern,
271  UErrorCode& status);
272 
286  PluralFormat(const Locale& locale,
287  UPluralType type,
288  const UnicodeString& pattern,
289  UErrorCode& status);
290 
295  PluralFormat(const PluralFormat& other);
296 
301  virtual ~PluralFormat();
302 
315  void applyPattern(const UnicodeString& pattern, UErrorCode& status);
316 
317 
318  using Format::format;
319 
332  UnicodeString format(int32_t number, UErrorCode& status) const;
333 
346  UnicodeString format(double number, UErrorCode& status) const;
347 
364  UnicodeString& format(int32_t number,
365  UnicodeString& appendTo,
366  FieldPosition& pos,
367  UErrorCode& status) const;
368 
385  UnicodeString& format(double number,
386  UnicodeString& appendTo,
387  FieldPosition& pos,
388  UErrorCode& status) const;
389 
390 #ifndef U_HIDE_DEPRECATED_API
391 
406  void setLocale(const Locale& locale, UErrorCode& status);
407 #endif /* U_HIDE_DEPRECATED_API */
408 
418  void setNumberFormat(const NumberFormat* format, UErrorCode& status);
419 
426  PluralFormat& operator=(const PluralFormat& other);
427 
435  virtual UBool operator==(const Format& other) const;
436 
444  virtual UBool operator!=(const Format& other) const;
445 
451  virtual Format* clone(void) const;
452 
467  UnicodeString& format(const Formattable& obj,
468  UnicodeString& appendTo,
469  FieldPosition& pos,
470  UErrorCode& status) const;
471 
480  UnicodeString& toPattern(UnicodeString& appendTo);
481 
504  virtual void parseObject(const UnicodeString& source,
505  Formattable& result,
506  ParsePosition& parse_pos) const;
507 
514  static UClassID U_EXPORT2 getStaticClassID(void);
515 
521  virtual UClassID getDynamicClassID() const;
522 
523 private:
527  class U_I18N_API PluralSelector : public UMemory {
528  public:
529  virtual ~PluralSelector();
539  virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
540  };
541 
545  class U_I18N_API PluralSelectorAdapter : public PluralSelector {
546  public:
547  PluralSelectorAdapter() : pluralRules(NULL) {
548  }
549 
550  virtual ~PluralSelectorAdapter();
551 
552  virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const;
554  void reset();
555 
556  PluralRules* pluralRules;
557  };
558 
559  Locale locale;
560  MessagePattern msgPattern;
561  NumberFormat* numberFormat;
562  double offset;
563  PluralSelectorAdapter pluralRulesWrapper;
564 
565  PluralFormat(); // default constructor not implemented
566  void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
571  void copyObjects(const PluralFormat& other);
572 
573  UnicodeString& format(const Formattable& numberObject, double number,
574  UnicodeString& appendTo,
575  FieldPosition& pos,
576  UErrorCode& status) const;
589  static int32_t findSubMessage(
590  const MessagePattern& pattern, int32_t partIndex,
591  const PluralSelector& selector, void *context, double number, UErrorCode& ec);
593  void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
594  Formattable& result, FieldPosition& pos) const;
595 
596  friend class MessageFormat;
597  friend class NFRule;
598 };
599 
601 
602 #endif /* #if !UCONFIG_NO_FORMATTING */
603 
604 #endif // _PLURFMT
605 //eof
Base class for all formats.
Definition: format.h:96
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:121
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:90
virtual Format * clone() const =0
Clone this object polymorphically.
C++ API: PluralRules object.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:194
Parses and represents ICU MessageFormat patterns.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:50
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
Basic definitions for ICU, for both C and C++ APIs.
Format & operator=(const Format &)
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
C++ API: Compatibility APIs for number formatting.
UMemory is the common ICU base class.
Definition: uobject.h:109
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192