ICU 50.2 50.2
plurfmt.h
Go to the documentation of this file.
1/*
2*******************************************************************************
3* Copyright (C) 2007-2012, International Business Machines Corporation and
4* others. All Rights Reserved.
5*******************************************************************************
6*
7
8* File PLURFMT.H
9*
10* Modification History:*
11* Date Name Description
12*
13********************************************************************************
14*/
15
16#ifndef PLURFMT
17#define PLURFMT
18
19#include "unicode/utypes.h"
20
25
26#if !UCONFIG_NO_FORMATTING
27
29#include "unicode/numfmt.h"
30#include "unicode/plurrule.h"
31
33
34class Hashtable;
35
146
148public:
149
159
169 PluralFormat(const Locale& locale, UErrorCode& status);
170
180 PluralFormat(const PluralRules& rules, UErrorCode& status);
181
193 PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
194
205 PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
206
217 PluralFormat(const UnicodeString& pattern, UErrorCode& status);
218
233 PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
234
247 const UnicodeString& pattern,
248 UErrorCode& status);
249
264 PluralFormat(const Locale& locale,
265 const PluralRules& rules,
266 const UnicodeString& pattern,
267 UErrorCode& status);
268
282 PluralFormat(const Locale& locale,
283 UPluralType type,
284 const UnicodeString& pattern,
285 UErrorCode& status);
286
292
297 virtual ~PluralFormat();
298
311 void applyPattern(const UnicodeString& pattern, UErrorCode& status);
312
313
314 using Format::format;
315
328 UnicodeString format(int32_t number, UErrorCode& status) const;
329
342 UnicodeString format(double number, UErrorCode& status) const;
343
360 UnicodeString& format(int32_t number,
361 UnicodeString& appendTo,
362 FieldPosition& pos,
363 UErrorCode& status) const;
364
381 UnicodeString& format(double number,
382 UnicodeString& appendTo,
383 FieldPosition& pos,
384 UErrorCode& status) const;
385
401 void setLocale(const Locale& locale, UErrorCode& status);
402
413
421
429 virtual UBool operator==(const Format& other) const;
430
438 virtual UBool operator!=(const Format& other) const;
439
445 virtual Format* clone(void) const;
446
460 UnicodeString& appendTo,
461 FieldPosition& pos,
462 UErrorCode& status) const;
463
473
496 virtual void parseObject(const UnicodeString& source,
497 Formattable& result,
498 ParsePosition& parse_pos) const;
499
506 static UClassID U_EXPORT2 getStaticClassID(void);
507
514
515#if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
516// Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
517// prevent PluralSelectorAdapter from implementing private PluralSelector.
518// xlC error message:
519// 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
520public:
521#else
522private:
523#endif
528 public:
529 virtual ~PluralSelector();
537 virtual UnicodeString select(double number, UErrorCode& ec) const = 0;
538 };
539
543 class U_I18N_API PluralSelectorAdapter : public PluralSelector {
544 public:
545 PluralSelectorAdapter() : pluralRules(NULL) {
546 }
547
548 virtual ~PluralSelectorAdapter();
549
550 virtual UnicodeString select(double number, UErrorCode& /*ec*/) const;
551
552 void reset();
553
554 PluralRules* pluralRules;
555 };
556
557#if defined(__xlC__)
558// End of xlC bug workaround, keep remaining definitions private.
559private:
560#endif
561 Locale locale;
562 MessagePattern msgPattern;
563 NumberFormat* numberFormat;
564 double offset;
565 PluralSelectorAdapter pluralRulesWrapper;
566
567 PluralFormat(); // default constructor not implemented
568 void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
573 void copyObjects(const PluralFormat& other);
574
585 static int32_t findSubMessage(
586 const MessagePattern& pattern, int32_t partIndex,
587 const PluralSelector& selector, double number, UErrorCode& ec);
588
589 friend class MessageFormat;
590};
591
593
594#endif /* #if !UCONFIG_NO_FORMATTING */
595
596#endif // _PLURFMT
597//eof
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:106
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
Format()
Default constructor for subclass use only.
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
Parses and represents ICU MessageFormat patterns.
Abstract base class for all number formats.
Definition numfmt.h:166
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
virtual UnicodeString select(double number, UErrorCode &) const
Given a number, returns the appropriate PluralFormat keyword.
virtual UnicodeString select(double number, UErrorCode &ec) const =0
Given a number, returns the appropriate PluralFormat keyword.
UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a plural message for a given number.
PluralFormat(const PluralRules &rules, UErrorCode &status)
Creates a new PluralFormat for a given set of rules.
PluralFormat(const PluralFormat &other)
copy constructor.
virtual UBool operator==(const Format &other) const
Return true if another object is semantically equal to this one.
void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the pattern used by this plural format.
UnicodeString format(double number, UErrorCode &status) const
Formats a plural message for a given number.
virtual UBool operator!=(const Format &other) const
Return true if another object is semantically unequal to this one.
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Redeclared Format method.
PluralFormat(const Locale &locale, UPluralType type, UErrorCode &status)
Creates a new PluralFormat for the plural type.
PluralFormat(const PluralRules &rules, const UnicodeString &pattern, UErrorCode &status)
Creates a new PluralFormat for a given set of rules, a pattern and a locale.
PluralFormat(const Locale &locale, const PluralRules &rules, UErrorCode &status)
Creates a new PluralFormat for a given set of rules.
PluralFormat(const Locale &locale, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given locale.
PluralFormat(const UnicodeString &pattern, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given pattern string.
PluralFormat(UErrorCode &status)
Creates a new cardinal-number PluralFormat for the default locale.
void copyObjects(const PluralFormat &other)
Copies dynamically allocated values (pointer fields).
static UClassID getStaticClassID(void)
ICU "poor man's RTTI", returns a UClassID for this class.
PluralFormat(const Locale &locale, const UnicodeString &pattern, UErrorCode &status)
Creates a new cardinal-number PluralFormat for a given pattern string and locale.
UnicodeString & toPattern(UnicodeString &appendTo)
Returns the pattern from applyPattern() or constructor().
virtual ~PluralFormat()
Destructor.
void setNumberFormat(const NumberFormat *format, UErrorCode &status)
Sets the number format used by this formatter.
UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Formats a plural message for a given number.
UnicodeString format(int32_t number, UErrorCode &status) const
Formats a plural message for a given number.
PluralFormat & operator=(const PluralFormat &other)
Assignment operator.
PluralFormat(const Locale &locale, UPluralType type, const UnicodeString &pattern, UErrorCode &status)
Creates a new PluralFormat for a plural type, a pattern and a locale.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const
This method is not yet supported by PluralFormat.
virtual Format * clone(void) const
Clones this Format object polymorphically.
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.
static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, const PluralSelector &selector, double number, UErrorCode &ec)
Finds the PluralFormat sub-message for the given number, or the "other" sub-message.
void setLocale(const Locale &locale, UErrorCode &status)
Sets the locale used by this PluraFormat object.
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition plurrule.h:127
UMemory is the common ICU base class.
Definition uobject.h:115
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
C++ API: Abstract base class for all number formats.
C++ API: PluralRules object.
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
UPluralType
Type of plurals and PluralRules.
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition utypes.h:186
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129