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

ICU 76.1 76.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
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
32U_NAMESPACE_BEGIN
33
34class Hashtable;
35class NFRule;
36
148 class U_I18N_API PluralFormat : public Format {
149public:
150
159 PluralFormat(UErrorCode& status);
160
170 PluralFormat(const Locale& locale, UErrorCode& status);
171
181 PluralFormat(const PluralRules& rules, UErrorCode& status);
182
194 PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
195
206 PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
207
218 PluralFormat(const UnicodeString& pattern, UErrorCode& status);
219
234 PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
235
247 PluralFormat(const PluralRules& rules,
248 const UnicodeString& pattern,
249 UErrorCode& status);
250
265 PluralFormat(const Locale& locale,
266 const PluralRules& rules,
267 const UnicodeString& pattern,
268 UErrorCode& status);
269
283 PluralFormat(const Locale& locale,
284 UPluralType type,
285 const UnicodeString& pattern,
286 UErrorCode& status);
287
292 PluralFormat(const PluralFormat& other);
293
298 virtual ~PluralFormat();
299
312 void applyPattern(const UnicodeString& pattern, UErrorCode& status);
313
314
315 using Format::format;
316
329 UnicodeString format(int32_t number, UErrorCode& status) const;
330
343 UnicodeString format(double number, UErrorCode& status) const;
344
361 UnicodeString& format(int32_t number,
362 UnicodeString& appendTo,
363 FieldPosition& pos,
364 UErrorCode& status) const;
365
382 UnicodeString& format(double number,
383 UnicodeString& appendTo,
384 FieldPosition& pos,
385 UErrorCode& status) const;
386
387#ifndef U_HIDE_DEPRECATED_API
403 void setLocale(const Locale& locale, UErrorCode& status);
404#endif /* U_HIDE_DEPRECATED_API */
405
415 void setNumberFormat(const NumberFormat* format, UErrorCode& status);
416
423 PluralFormat& operator=(const PluralFormat& other);
424
432 virtual bool operator==(const Format& other) const override;
433
441 virtual bool operator!=(const Format& other) const;
442
448 virtual PluralFormat* clone() const override;
449
464 UnicodeString& format(const Formattable& obj,
465 UnicodeString& appendTo,
466 FieldPosition& pos,
467 UErrorCode& status) const override;
468
477 UnicodeString& toPattern(UnicodeString& appendTo);
478
501 virtual void parseObject(const UnicodeString& source,
502 Formattable& result,
503 ParsePosition& parse_pos) const override;
504
511 static UClassID U_EXPORT2 getStaticClassID();
512
518 virtual UClassID getDynamicClassID() const override;
519
520private:
524 class U_I18N_API PluralSelector : public UMemory {
525 public:
526 virtual ~PluralSelector();
536 virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
537 };
538
539 class U_I18N_API PluralSelectorAdapter : public PluralSelector {
540 public:
541 PluralSelectorAdapter() : pluralRules(nullptr) {
542 }
543
544 virtual ~PluralSelectorAdapter();
545
546 virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const override;
547
548 void reset();
549
550 PluralRules* pluralRules;
551 };
552
553 Locale locale;
554 MessagePattern msgPattern;
555 NumberFormat* numberFormat;
556 double offset;
557 PluralSelectorAdapter pluralRulesWrapper;
558
559 PluralFormat() = delete; // default constructor not implemented
560 void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
565 void copyObjects(const PluralFormat& other);
566
567 UnicodeString& format(const Formattable& numberObject, double number,
568 UnicodeString& appendTo,
569 FieldPosition& pos,
570 UErrorCode& status) const;
571
583 static int32_t findSubMessage(
584 const MessagePattern& pattern, int32_t partIndex,
585 const PluralSelector& selector, void *context, double number, UErrorCode& ec);
586
587 void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
588 Formattable& result, FieldPosition& pos) const;
589
590 friend class MessageFormat;
591 friend class NFRule;
592};
593
594U_NAMESPACE_END
595
596#endif /* #if !UCONFIG_NO_FORMATTING */
597
598#endif /* U_SHOW_CPLUSPLUS_API */
599
600#endif // _PLURFMT
601//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
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:195
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::setNumberFormat
void setNumberFormat(const NumberFormat *format, UErrorCode &status)
Sets the number format used by this formatter.
icu::PluralFormat::PluralFormat
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::PluralFormat
PluralFormat(const Locale &locale, const UnicodeString &pattern, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given pattern string and locale.
icu::PluralFormat::getDynamicClassID
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::PluralFormat::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const override
This method is not yet supported by PluralFormat.
icu::PluralFormat::operator!=
virtual bool operator!=(const Format &other) const
Return true if another object is semantically unequal to this one.
icu::PluralFormat::PluralFormat
PluralFormat(const UnicodeString &pattern, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given pattern string.
icu::PluralFormat::clone
virtual PluralFormat * clone() const override
Clones this Format object polymorphically.
icu::PluralFormat::applyPattern
void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the pattern used by this plural format.
icu::PluralFormat::PluralFormat
PluralFormat(const PluralRules &rules, UErrorCode &status)
Creates a new PluralFormat for a given set of rules.
icu::PluralFormat::format
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::toPattern
UnicodeString & toPattern(UnicodeString &appendTo)
Returns the pattern from applyPattern() or constructor().
icu::PluralFormat::format
UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a plural message for a given number.
icu::PluralFormat::PluralFormat
PluralFormat(const Locale &locale, UPluralType type, UErrorCode &status)
Creates a new PluralFormat for the plural type.
icu::PluralFormat::PluralFormat
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::PluralFormat
PluralFormat(UErrorCode &status)
Creates a new cardinal-number PluralFormat for the default locale.
icu::PluralFormat::PluralFormat
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=
PluralFormat & operator=(const PluralFormat &other)
Assignment operator.
icu::PluralFormat::format
UnicodeString format(double number, UErrorCode &status) const
Formats a plural message for a given number.
icu::PluralFormat::setLocale
void setLocale(const Locale &locale, UErrorCode &status)
Sets the locale used by this PluraFormat object.
icu::PluralFormat::format
UnicodeString format(int32_t number, UErrorCode &status) const
Formats a plural message for a given number.
icu::PluralFormat::PluralFormat
PluralFormat(const PluralFormat &other)
copy constructor.
icu::PluralFormat::operator==
virtual bool operator==(const Format &other) const override
Return true if another object is semantically equal to this one.
icu::PluralFormat::PluralFormat
PluralFormat(const Locale &locale, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given locale.
icu::PluralFormat::format
UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a plural message for a given number.
icu::PluralFormat::PluralFormat
PluralFormat(const Locale &locale, const PluralRules &rules, UErrorCode &status)
Creates a new PluralFormat for a given set of rules.
icu::PluralFormat::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::PluralFormat::~PluralFormat
virtual ~PluralFormat()
Destructor.
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:296
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:430
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