Loading...
Searching...
No Matches
plurfmt.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2007-2014, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
* File PLURFMT.H
********************************************************************************
*/
#ifndef PLURFMT
#define PLURFMT
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/messagepattern.h"
#include "unicode/numfmt.h"
#include "unicode/plurrule.h"
U_NAMESPACE_BEGIN
class Hashtable;
class NFRule;
class U_I18N_API_CLASS PluralFormat : public Format {
public:
U_I18N_API PluralFormat(UErrorCode& status);
U_I18N_API PluralFormat(const Locale& locale, UErrorCode& status);
U_I18N_API PluralFormat(const PluralRules& rules, UErrorCode& status);
U_I18N_API PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
U_I18N_API PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
U_I18N_API PluralFormat(const UnicodeString& pattern, UErrorCode& status);
U_I18N_API PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
U_I18N_API PluralFormat(const PluralRules& rules, const UnicodeString& pattern, UErrorCode& status);
U_I18N_API PluralFormat(const Locale& locale,
const PluralRules& rules,
const UnicodeString& pattern,
UErrorCode& status);
U_I18N_API PluralFormat(const Locale& locale,
UPluralType type,
const UnicodeString& pattern,
UErrorCode& status);
U_I18N_API PluralFormat(const PluralFormat& other);
U_I18N_API virtual ~PluralFormat();
U_I18N_API void applyPattern(const UnicodeString& pattern, UErrorCode& status);
using Format::format;
U_I18N_API UnicodeString format(int32_t number, UErrorCode& status) const;
U_I18N_API UnicodeString format(double number, UErrorCode& status) const;
U_I18N_API UnicodeString& format(int32_t number,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const;
U_I18N_API UnicodeString& format(double number,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const;
#ifndef U_HIDE_DEPRECATED_API
U_I18N_API void setLocale(const Locale& locale, UErrorCode& status);
#endif /* U_HIDE_DEPRECATED_API */
U_I18N_API void setNumberFormat(const NumberFormat* format, UErrorCode& status);
U_I18N_API PluralFormat& operator=(const PluralFormat& other);
U_I18N_API virtual bool operator==(const Format& other) const override;
U_I18N_API virtual bool operator!=(const Format& other) const;
U_I18N_API virtual PluralFormat* clone() const override;
U_I18N_API UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const override;
U_I18N_API UnicodeString& toPattern(UnicodeString& appendTo);
U_I18N_API virtual void parseObject(const UnicodeString& source,
Formattable& result,
ParsePosition& parse_pos) const override;
U_I18N_API static UClassID getStaticClassID();
U_I18N_API virtual UClassID getDynamicClassID() const override;
private:
class PluralSelector : public UMemory {
public:
virtual ~PluralSelector();
virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
};
class PluralSelectorAdapter : public PluralSelector {
public:
PluralSelectorAdapter() : pluralRules(nullptr) {
}
virtual ~PluralSelectorAdapter();
virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const override;
void reset();
PluralRules* pluralRules;
};
Locale locale;
MessagePattern msgPattern;
NumberFormat* numberFormat;
double offset;
PluralSelectorAdapter pluralRulesWrapper;
PluralFormat() = delete; // default constructor not implemented
void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
void copyObjects(const PluralFormat& other);
UnicodeString& format(const Formattable& numberObject, double number,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const;
static int32_t findSubMessage(
const MessagePattern& pattern, int32_t partIndex,
const PluralSelector& selector, void *context, double number, UErrorCode& ec);
void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
Formattable& result, FieldPosition& pos) const;
friend class MessageFormat;
friend class NFRule;
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // _PLURFMT
//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::Format
U_I18N_API Format()
Default constructor for subclass use only.
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::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::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::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(int32_t 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::clone
virtual U_I18N_API PluralFormat * clone() const override
Clones this Format object polymorphically.
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::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::PluralFormat
U_I18N_API PluralFormat(const Locale &locale, UPluralType type, UErrorCode &status)
Creates a new PluralFormat for the plural type.
icu::PluralFormat::operator=
U_I18N_API PluralFormat & operator=(const PluralFormat &other)
Assignment operator.
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::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::toPattern
U_I18N_API UnicodeString & toPattern(UnicodeString &appendTo)
Returns the pattern from applyPattern() or constructor().
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