ICU 62.1  62.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 #if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
524 // Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
525 // prevent PluralSelectorAdapter from implementing private PluralSelector.
526 // xlC error message:
527 // 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
528 public:
529 #else
530 private:
531 #endif
532 
536  public:
537  virtual ~PluralSelector();
547  virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
548  };
549 
554  public:
555  PluralSelectorAdapter() : pluralRules(NULL) {
556  }
557 
558  virtual ~PluralSelectorAdapter();
559 
560  virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const;
562  void reset();
563 
564  PluralRules* pluralRules;
565  };
566 
567 #if defined(__xlC__)
568 // End of xlC bug workaround, keep remaining definitions private.
569 private:
570 #endif
571  Locale locale;
572  MessagePattern msgPattern;
573  NumberFormat* numberFormat;
574  double offset;
575  PluralSelectorAdapter pluralRulesWrapper;
576 
577  PluralFormat(); // default constructor not implemented
578  void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
583  void copyObjects(const PluralFormat& other);
584 
585  UnicodeString& format(const Formattable& numberObject, double number,
586  UnicodeString& appendTo,
587  FieldPosition& pos,
588  UErrorCode& status) const;
601  static int32_t findSubMessage(
602  const MessagePattern& pattern, int32_t partIndex,
603  const PluralSelector& selector, void *context, double number, UErrorCode& ec);
605  void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
606  Formattable& result, FieldPosition& pos) const;
607 
608  friend class MessageFormat;
609  friend class NFRule;
610 };
611 
613 
614 #endif /* #if !UCONFIG_NO_FORMATTING */
615 
616 #endif // _PLURFMT
617 //eof
icu::PluralFormat::PluralSelector::select
virtual UnicodeString select(void *context, double number, UErrorCode &ec) const =0
Given a number, returns the appropriate PluralFormat keyword.
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:50
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
icu::NumberFormat
Definition: numfmt.h:174
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_I18N_API
#define U_I18N_API
Definition: utypes.h:360
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
icu::PluralFormat::PluralSelectorAdapter
Definition: plurfmt.h:553
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:196
icu::PluralFormat::findSubMessage
static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, const PluralSelector &selector, void *context, double number, UErrorCode &ec)
Finds the PluralFormat sub-message for the given number, or the "other" sub-message.
icu::Format::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:121
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::PluralFormat
Definition: plurfmt.h:146
NULL
#define NULL
Definition: utypes.h:188
icu::MessageFormat
Definition: msgfmt.h:325
icu::MessagePattern
Parses and represents ICU MessageFormat patterns.
Definition: messagepattern.h:360
icu::Format
Base class for all formats.
Definition: format.h:96
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::PluralFormat::PluralSelector
Definition: plurfmt.h:535
icu::Format::operator=
Format & operator=(const Format &)
icu::PluralFormat::copyObjects
void copyObjects(const PluralFormat &other)
Copies dynamically allocated values (pointer fields).
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:93
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:396
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:112
messagepattern.h
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
numfmt.h
C++ API: Compatibility APIs for number formatting.
plurrule.h
C++ API: PluralRules object.
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
U_NAMESPACE_END
#define U_NAMESPACE_END
Definition: uversion.h:138
icu::PluralFormat::format
UnicodeString format(int32_t number, UErrorCode &status) const
Formats a plural message for a given number.
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
Definition: uversion.h:137
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188