ICU 63.1 63.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
24 #if !UCONFIG_NO_FORMATTING
25
26 #include "unicode/messagepattern.h"
27 #include "unicode/numfmt.h"
28 #include "unicode/plurrule.h"
29
30 U_NAMESPACE_BEGIN
31
32 class Hashtable;
33 class NFRule;
34
146 class U_I18N_API PluralFormat : public Format {
147 public:
148
157 PluralFormat(UErrorCode& status);
158
168 PluralFormat(const Locale& locale, UErrorCode& status);
169
179 PluralFormat(const PluralRules& rules, UErrorCode& status);
180
197 PluralFormat(const Locale& locale, const PluralRules& rules, UErrorCode& status);
198
209 PluralFormat(const Locale& locale, UPluralType type, UErrorCode& status);
210
221 PluralFormat(const UnicodeString& pattern, UErrorCode& status);
222
237 PluralFormat(const Locale& locale, const UnicodeString& pattern, UErrorCode& status);
238
250 PluralFormat(const PluralRules& rules,
251 const UnicodeString& pattern,
252 UErrorCode& status);
253
268 PluralFormat(const Locale& locale,
269 const PluralRules& rules,
270 const UnicodeString& pattern,
271 UErrorCode& status);
272
286 PluralFormat(const Locale& locale,
287 UPluralType type,
288 const UnicodeString& pattern,
289 UErrorCode& status);
290
295 PluralFormat(const PluralFormat& other);
296
301 virtual ~PluralFormat();
302
315 void applyPattern(const UnicodeString& pattern, UErrorCode& status);
316
317
318 using Format::format;
319
332 UnicodeString format(int32_t number, UErrorCode& status) const;
333
346 UnicodeString format(double number, UErrorCode& status) const;
347
364 UnicodeString& format(int32_t number,
365 UnicodeString& appendTo,
366 FieldPosition& pos,
367 UErrorCode& status) const;
368
385 UnicodeString& format(double number,
386 UnicodeString& appendTo,
387 FieldPosition& pos,
388 UErrorCode& status) const;
389
390 #ifndef U_HIDE_DEPRECATED_API
391
406 void setLocale(const Locale& locale, UErrorCode& status);
407 #endif /* U_HIDE_DEPRECATED_API */
408
418 void setNumberFormat(const NumberFormat* format, UErrorCode& status);
419
426 PluralFormat& operator=(const PluralFormat& other);
427
435 virtual UBool operator==(const Format& other) const;
436
444 virtual UBool operator!=(const Format& other) const;
445
451 virtual Format* clone(void) const;
452
467 UnicodeString& format(const Formattable& obj,
468 UnicodeString& appendTo,
469 FieldPosition& pos,
470 UErrorCode& status) const;
471
480 UnicodeString& toPattern(UnicodeString& appendTo);
481
504 virtual void parseObject(const UnicodeString& source,
505 Formattable& result,
506 ParsePosition& parse_pos) const;
507
514 static UClassID U_EXPORT2 getStaticClassID(void);
515
521 virtual UClassID getDynamicClassID() const;
522
523 private:
527 class U_I18N_API PluralSelector : public UMemory {
528 public:
529 virtual ~PluralSelector();
539 virtual UnicodeString select(void *context, double number, UErrorCode& ec) const = 0;
540 };
541
545 class U_I18N_API PluralSelectorAdapter : public PluralSelector {
546 public:
547 PluralSelectorAdapter() : pluralRules(NULL) {
548 }
549
550 virtual ~PluralSelectorAdapter();
551
552 virtual UnicodeString select(void *context, double number, UErrorCode& /*ec*/) const;
554 void reset();
555
556 PluralRules* pluralRules;
557 };
558
559 Locale locale;
560 MessagePattern msgPattern;
561 NumberFormat* numberFormat;
562 double offset;
563 PluralSelectorAdapter pluralRulesWrapper;
564
565 PluralFormat(); // default constructor not implemented
566 void init(const PluralRules* rules, UPluralType type, UErrorCode& status);
571 void copyObjects(const PluralFormat& other);
572
573 UnicodeString& format(const Formattable& numberObject, double number,
574 UnicodeString& appendTo,
575 FieldPosition& pos,
576 UErrorCode& status) const;
589 static int32_t findSubMessage(
590 const MessagePattern& pattern, int32_t partIndex,
591 const PluralSelector& selector, void *context, double number, UErrorCode& ec);
593 void parseType(const UnicodeString& source, const NFRule *rbnfLenientScanner,
594 Formattable& result, FieldPosition& pos) const;
595
596 friend class MessageFormat;
597 friend class NFRule;
598 };
599
600 U_NAMESPACE_END
601
602 #endif /* #if !UCONFIG_NO_FORMATTING */
603
604 #endif // _PLURFMT
605 //eof
icu::Format
Base class for all formats.
Definition: format.h:96
icu::Format::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:121
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::NumberFormat
Definition: numfmt.h:173
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:90
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
plurrule.h
C++ API: PluralRules object.
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:194
icu::MessagePattern
Parses and represents ICU MessageFormat patterns.
Definition: messagepattern.h:360
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:301
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
NULL
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
icu::PluralFormat
Definition: plurfmt.h:146
icu::MessageFormat
Definition: msgfmt.h:328
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
UPluralType
UPluralType
Type of plurals and PluralRules.
Definition: upluralrules.h:50
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
icu::Format::operator==
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
icu::Format::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Format::operator=
Format & operator=(const Format &)
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
messagepattern.h
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
numfmt.h
C++ API: Compatibility APIs for number formatting.
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:109
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192