ICU 57.1 57.1
plurfmt.h
Go to the documentation of this file.
1/*
2*******************************************************************************
3* Copyright (C) 2007-2014, International Business Machines Corporation and
4* others. All Rights Reserved.
5*******************************************************************************
6*
7
8* File PLURFMT.H
9********************************************************************************
10*/
11
12#ifndef PLURFMT
13#define PLURFMT
14
15#include "unicode/utypes.h"
16
21
22#if !UCONFIG_NO_FORMATTING
23
25#include "unicode/numfmt.h"
26#include "unicode/plurrule.h"
27
29
30class Hashtable;
31class NFRule;
32
143
145public:
146
156
166 PluralFormat(const Locale& locale, UErrorCode& status);
167
177 PluralFormat(const PluralRules& rules, UErrorCode& status);
178
195 PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
196
207 PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
208
219 PluralFormat(const UnicodeString& pattern, UErrorCode& status);
220
235 PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
236
249 const UnicodeString& pattern,
250 UErrorCode& status);
251
266 PluralFormat(const Locale& locale,
267 const PluralRules& rules,
268 const UnicodeString& pattern,
269 UErrorCode& status);
270
284 PluralFormat(const Locale& locale,
285 UPluralType type,
286 const UnicodeString& pattern,
287 UErrorCode& status);
288
294
299 virtual ~PluralFormat();
300
313 void applyPattern(const UnicodeString& pattern, UErrorCode& status);
314
315
316 using Format::format;
317
330 UnicodeString format(int32_t number, UErrorCode& status) const;
331
344 UnicodeString format(double number, UErrorCode& status) const;
345
362 UnicodeString& format(int32_t number,
363 UnicodeString& appendTo,
364 FieldPosition& pos,
365 UErrorCode& status) const;
366
383 UnicodeString& format(double number,
384 UnicodeString& appendTo,
385 FieldPosition& pos,
386 UErrorCode& status) const;
387
388#ifndef U_HIDE_DEPRECATED_API
404 void setLocale(const Locale& locale, UErrorCode& status);
405#endif /* U_HIDE_DEPRECATED_API */
406
417
425
433 virtual UBool operator==(const Format& other) const;
434
442 virtual UBool operator!=(const Format& other) const;
443
449 virtual Format* clone(void) const;
450
466 UnicodeString& appendTo,
467 FieldPosition& pos,
468 UErrorCode& status) const;
469
479
502 virtual void parseObject(const UnicodeString& source,
503 Formattable& result,
504 ParsePosition& parse_pos) const;
505
512 static UClassID U_EXPORT2 getStaticClassID(void);
513
520
521#if (defined(__xlC__) && (__xlC__ < 0x0C00)) || (U_PLATFORM == U_PF_OS390) || (U_PLATFORM ==U_PF_OS400)
522// Work around a compiler bug on xlC 11.1 on AIX 7.1 that would
523// prevent PluralSelectorAdapter from implementing private PluralSelector.
524// xlC error message:
525// 1540-0300 (S) The "private" member "class icu_49::PluralFormat::PluralSelector" cannot be accessed.
526public:
527#else
528private:
529#endif
534 public:
535 virtual ~PluralSelector();
545 virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
546 };
547
551 class U_I18N_API PluralSelectorAdapter : public PluralSelector {
552 public:
553 PluralSelectorAdapter() : pluralRules(NULL) {
554 }
555
556 virtual ~PluralSelectorAdapter();
557
558 virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const;
559
560 void reset();
561
562 PluralRules* pluralRules;
563 };
564
565#if defined(__xlC__)
566// End of xlC bug workaround, keep remaining definitions private.
567private:
568#endif
569 Locale locale;
570 MessagePattern msgPattern;
571 NumberFormat* numberFormat;
572 double offset;
573 PluralSelectorAdapter pluralRulesWrapper;
574
575 PluralFormat(); // default constructor not implemented
576 void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
581 void copyObjects(const PluralFormat& other);
582
583 UnicodeString& format(const Formattable& numberObject, double number,
584 UnicodeString& appendTo,
585 FieldPosition& pos,
586 UErrorCode& status) const;
587
599 static int32_t findSubMessage(
600 const MessagePattern& pattern, int32_t partIndex,
601 const PluralSelector& selector, void *context, double number, UErrorCode& ec);
602
603 void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
604 Formattable& result, FieldPosition& pos) const;
605
606 friend class MessageFormat;
607 friend class NFRule;
608};
609
611
612#endif /* #if !UCONFIG_NO_FORMATTING */
613
614#endif // _PLURFMT
615//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:66
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:185
Parses and represents ICU MessageFormat patterns.
Abstract base class for all number formats.
Definition numfmt.h:167
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(void *context, double number, UErrorCode &) const
virtual UnicodeString select(void *context, 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
Formats a plural message for a number taken from a Formattable object.
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.
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).
UnicodeString & format(const Formattable &numberObject, double number, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
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.
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:192
UMemory is the common ICU base class.
Definition uobject.h:110
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:294
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:234
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:91
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