ICU 78.3: i18n/unicode/plurfmt.h Source File

ICU 78.3 78.3

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
19 #if U_SHOW_CPLUSPLUS_API
20
26 #if !UCONFIG_NO_FORMATTING
27
28 #include "unicode/messagepattern.h"
29 #include "unicode/numfmt.h"
30 #include "unicode/plurrule.h"
31
32 U_NAMESPACE_BEGIN
33
34 class Hashtable;
35 class NFRule;
36
148 class U_I18N_API_CLASS PluralFormat : public Format {
149 public:
150
159 U_I18N_API PluralFormat(UErrorCode& status);
160
170 U_I18N_API PluralFormat(const Locale& locale, UErrorCode& status);
171
181 U_I18N_API PluralFormat(const PluralRules& rules, UErrorCode& status);
182
194 U_I18N_API PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
195
206 U_I18N_API PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
207
218 U_I18N_API PluralFormat(const UnicodeString& pattern, UErrorCode& status);
219
234 U_I18N_API PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
235
247 U_I18N_API PluralFormat(const PluralRules& rules, const UnicodeString& pattern, UErrorCode& status);
248
263 U_I18N_API PluralFormat(const Locale& locale,
264 const PluralRules& rules,
265 const UnicodeString& pattern,
266 UErrorCode& status);
267
281 U_I18N_API PluralFormat(const Locale& locale,
282 UPluralType type,
283 const UnicodeString& pattern,
284 UErrorCode& status);
285
290 U_I18N_API PluralFormat(const PluralFormat& other);
291
296 U_I18N_API virtual ~PluralFormat();
297
310 U_I18N_API void applyPattern(const UnicodeString& pattern, UErrorCode& status);
311
312 using Format::format;
313
326 U_I18N_API UnicodeString format(int32_t number, UErrorCode& status) const;
327
340 U_I18N_API UnicodeString format(double number, UErrorCode& status) const;
341
358 U_I18N_API UnicodeString& format(int32_t number,
359 UnicodeString& appendTo,
360 FieldPosition& pos,
361 UErrorCode& status) const;
362
379 U_I18N_API UnicodeString& format(double number,
380 UnicodeString& appendTo,
381 FieldPosition& pos,
382 UErrorCode& status) const;
383
384 #ifndef U_HIDE_DEPRECATED_API
400 U_I18N_API void setLocale(const Locale& locale, UErrorCode& status);
401 #endif /* U_HIDE_DEPRECATED_API */
402
412 U_I18N_API void setNumberFormat(const NumberFormat* format, UErrorCode& status);
413
420 U_I18N_API PluralFormat& operator=(const PluralFormat& other);
421
429 U_I18N_API virtual bool operator==(const Format& other) const override;
430
438 U_I18N_API virtual bool operator!=(const Format& other) const;
439
445 U_I18N_API virtual PluralFormat* clone() const override;
446
461 U_I18N_API UnicodeString& format(const Formattable& obj,
462 UnicodeString& appendTo,
463 FieldPosition& pos,
464 UErrorCode& status) const override;
465
474 U_I18N_API UnicodeString& toPattern(UnicodeString& appendTo);
475
498 U_I18N_API virtual void parseObject(const UnicodeString& source,
499 Formattable& result,
500 ParsePosition& parse_pos) const override;
501
508 U_I18N_API static UClassID getStaticClassID();
509
515 U_I18N_API virtual UClassID getDynamicClassID() const override;
516
517 private:
518 class PluralSelector : public UMemory {
519 public:
520 virtual ~PluralSelector();
529 virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
530 };
531
532 class PluralSelectorAdapter : public PluralSelector {
533 public:
534 PluralSelectorAdapter() : pluralRules(nullptr) {
535 }
536
537 virtual ~PluralSelectorAdapter();
538
539 virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const override;
540
541 void reset();
542
543 PluralRules* pluralRules;
544 };
545
546 Locale locale;
547 MessagePattern msgPattern;
548 NumberFormat* numberFormat;
549 double offset;
550 PluralSelectorAdapter pluralRulesWrapper;
551
552 PluralFormat() = delete; // default constructor not implemented
553 void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
558 void copyObjects(const PluralFormat& other);
559
560 UnicodeString& format(const Formattable& numberObject, double number,
561 UnicodeString& appendTo,
562 FieldPosition& pos,
563 UErrorCode& status) const;
564
576 static int32_t findSubMessage(
577 const MessagePattern& pattern, int32_t partIndex,
578 const PluralSelector& selector, void *context, double number, UErrorCode& ec);
579
580 void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
581 Formattable& result, FieldPosition& pos) const;
582
583 friend class MessageFormat;
584 friend class NFRule;
585 };
586
587 U_NAMESPACE_END
588
589 #endif /* #if !UCONFIG_NO_FORMATTING */
590
591 #endif /* U_SHOW_CPLUSPLUS_API */
592
593 #endif // _PLURFMT
594 //eof
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
icu::Format
Base class for all formats.
Definition: format.h:98
icu::Format::format
U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:63
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:198
icu::NumberFormat
Definition: numfmt.h:175
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
icu::PluralFormat
Definition: plurfmt.h:148
icu::PluralFormat::operator!=
virtual U_I18N_API bool operator!=(const Format &other) const
Return true if another object is semantically unequal to this one.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const Locale &locale, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given locale.
icu::PluralFormat::clone
virtual U_I18N_API PluralFormat * clone() const override
Clones this Format object polymorphically.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const PluralRules &rules, const UnicodeString &pattern, UErrorCode &status)
Creates a new PluralFormat for a given set of rules, a pattern and a locale.
icu::PluralFormat::setLocale
U_I18N_API void setLocale(const Locale &locale, UErrorCode &status)
Sets the locale used by this PluraFormat object.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const Locale &locale, const UnicodeString &pattern, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given pattern string and locale.
icu::PluralFormat::format
U_I18N_API UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a plural message for a given number.
icu::PluralFormat::setNumberFormat
U_I18N_API void setNumberFormat(const NumberFormat *format, UErrorCode &status)
Sets the number format used by this formatter.
icu::PluralFormat::operator==
virtual U_I18N_API bool operator==(const Format &other) const override
Return true if another object is semantically equal to this one.
icu::PluralFormat::toPattern
U_I18N_API UnicodeString & toPattern(UnicodeString &appendTo)
Returns the pattern from applyPattern() or constructor().
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const PluralFormat &other)
copy constructor.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const Locale &locale, const PluralRules &rules, UErrorCode &status)
Creates a new PluralFormat for a given set of rules.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const Locale &locale, UPluralType type, UErrorCode &status)
Creates a new PluralFormat for the plural type.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(UErrorCode &status)
Creates a new cardinal-number PluralFormat for the default locale.
icu::PluralFormat::parseObject
virtual U_I18N_API void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const override
This method is not yet supported by PluralFormat.
icu::PluralFormat::format
U_I18N_API UnicodeString format(int32_t number, UErrorCode &status) const
Formats a plural message for a given number.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const PluralRules &rules, UErrorCode &status)
Creates a new PluralFormat for a given set of rules.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const Locale &locale, const PluralRules &rules, const UnicodeString &pattern, UErrorCode &status)
Creates a new PluralFormat for a given set of rules, a pattern and a locale.
icu::PluralFormat::operator=
U_I18N_API PluralFormat & operator=(const PluralFormat &other)
Assignment operator.
icu::PluralFormat::getDynamicClassID
virtual U_I18N_API UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::PluralFormat::~PluralFormat
virtual U_I18N_API ~PluralFormat()
Destructor.
icu::PluralFormat::applyPattern
U_I18N_API void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the pattern used by this plural format.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const Locale &locale, UPluralType type, const UnicodeString &pattern, UErrorCode &status)
Creates a new PluralFormat for a plural type, a pattern and a locale.
icu::PluralFormat::getStaticClassID
static U_I18N_API UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::PluralFormat::format
U_I18N_API UnicodeString format(double number, UErrorCode &status) const
Formats a plural message for a given number.
icu::PluralFormat::PluralFormat
U_I18N_API PluralFormat(const UnicodeString &pattern, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given pattern string.
icu::PluralFormat::format
U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Formats a plural message for a number taken from a Formattable object.
icu::PluralFormat::format
U_I18N_API UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a plural message for a given number.
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:212
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:303
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.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:59
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:509
U_I18N_API_CLASS
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition: utypes.h:457
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316