ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

msgfmt.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 * Copyright (C) 2007-2013, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 ********************************************************************************
7 *
8 * File MSGFMT.H
9 *
10 * Modification History:
11 *
12 * Date Name Description
13 * 02/19/97 aliu Converted from java.
14 * 03/20/97 helena Finished first cut of implementation.
15 * 07/22/98 stephen Removed operator!= (defined in Format)
16 * 08/19/2002 srl Removing Javaisms
17 *******************************************************************************/
18
19 #ifndef MSGFMT_H
20 #define MSGFMT_H
21
22 #include "unicode/utypes.h"
23
29 #if !UCONFIG_NO_FORMATTING
30
31 #include "unicode/format.h"
32 #include "unicode/locid.h"
33 #include "unicode/messagepattern.h"
34 #include "unicode/parseerr.h"
35 #include "unicode/plurfmt.h"
36 #include "unicode/plurrule.h"
37
38 U_CDECL_BEGIN
39 // Forward declaration.
40 struct UHashtable;
41 typedef struct UHashtable UHashtable;
42 U_CDECL_END
43
44 U_NAMESPACE_BEGIN
45
46 class AppendableWrapper;
47 class DateFormat;
48 class NumberFormat;
49
325 class U_I18N_API MessageFormat : public Format {
326 public:
327 #ifndef U_HIDE_OBSOLETE_API
328
333 enum EFormatNumber {
339 kMaxFormat = 10
340 };
341 #endif /* U_HIDE_OBSOLETE_API */
342
352 MessageFormat(const UnicodeString& pattern,
353 UErrorCode &status);
354
363 MessageFormat(const UnicodeString& pattern,
364 const Locale& newLocale,
365 UErrorCode& status);
376 MessageFormat(const UnicodeString& pattern,
377 const Locale& newLocale,
378 UParseError& parseError,
379 UErrorCode& status);
384 MessageFormat(const MessageFormat&);
385
390 const MessageFormat& operator=(const MessageFormat&);
391
396 virtual ~MessageFormat();
397
403 virtual Format* clone(void) const;
404
412 virtual UBool operator==(const Format& other) const;
413
419 virtual void setLocale(const Locale& theLocale);
420
427 virtual const Locale& getLocale(void) const;
428
437 virtual void applyPattern(const UnicodeString& pattern,
438 UErrorCode& status);
449 virtual void applyPattern(const UnicodeString& pattern,
450 UParseError& parseError,
451 UErrorCode& status);
452
471 virtual void applyPattern(const UnicodeString& pattern,
472 UMessagePatternApostropheMode aposMode,
473 UParseError* parseError,
474 UErrorCode& status);
475
480 UMessagePatternApostropheMode getApostropheMode() const {
481 return msgPattern.getApostropheMode();
482 }
483
492 virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
493
510 virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
511
526 virtual void setFormats(const Format** newFormats, int32_t cnt);
527
528
543 virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
544
554 virtual void setFormat(int32_t formatNumber, const Format& format);
555
564 virtual StringEnumeration* getFormatNames(UErrorCode& status);
565
579 virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status);
580
594 virtual void setFormat(const UnicodeString& formatName, const Format& format, UErrorCode& status);
595
610 virtual void adoptFormat(const UnicodeString& formatName, Format* formatToAdopt, UErrorCode& status);
611
624 virtual const Format** getFormats(int32_t& count) const;
625
626
627 using Format::format;
628
646 UnicodeString& format(const Formattable* source,
647 int32_t count,
648 UnicodeString& appendTo,
649 FieldPosition& ignore,
650 UErrorCode& status) const;
651
669 static UnicodeString& format(const UnicodeString& pattern,
670 const Formattable* arguments,
671 int32_t count,
672 UnicodeString& appendTo,
673 UErrorCode& status);
674
695 virtual UnicodeString& format(const Formattable& obj,
696 UnicodeString& appendTo,
697 FieldPosition& pos,
698 UErrorCode& status) const;
699
718 UnicodeString& format(const UnicodeString* argumentNames,
719 const Formattable* arguments,
720 int32_t count,
721 UnicodeString& appendTo,
722 UErrorCode& status) const;
736 virtual Formattable* parse(const UnicodeString& source,
737 ParsePosition& pos,
738 int32_t& count) const;
739
755 virtual Formattable* parse(const UnicodeString& source,
756 int32_t& count,
757 UErrorCode& status) const;
758
771 virtual void parseObject(const UnicodeString& source,
772 Formattable& result,
773 ParsePosition& pos) const;
774
794 static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern,
795 UErrorCode& status);
796
797
805 UBool usesNamedArguments() const;
806
807
808 #ifndef U_HIDE_INTERNAL_API
809
819 int32_t getArgTypeCount() const;
820 #endif /* U_HIDE_INTERNAL_API */
821
833 virtual UClassID getDynamicClassID(void) const;
834
846 static UClassID U_EXPORT2 getStaticClassID(void);
847
848 #ifndef U_HIDE_INTERNAL_API
849
859 static UBool equalFormats(const void* left, const void* right);
860 #endif /* U_HIDE_INTERNAL_API */
861
862 private:
863
864 Locale fLocale;
865 MessagePattern msgPattern;
866 Format** formatAliases; // see getFormats
867 int32_t formatAliasesCapacity;
868
869 MessageFormat(); // default constructor not implemented
870
877 class U_I18N_API PluralSelectorProvider : public PluralFormat::PluralSelector {
878 public:
879 PluralSelectorProvider(const MessageFormat &mf, UPluralType type);
880 virtual ~PluralSelectorProvider();
881 virtual UnicodeString select(void *ctx, double number, UErrorCode& ec) const;
882
883 void reset();
884 private:
885 const MessageFormat &msgFormat;
886 PluralRules* rules;
887 UPluralType type;
888 };
889
898 Formattable::Type* argTypes;
899 int32_t argTypeCount;
900 int32_t argTypeCapacity;
901
907 UBool hasArgTypeConflicts;
908
909 // Variable-size array management
910 UBool allocateArgTypes(int32_t capacity, UErrorCode& status);
911
919 NumberFormat* defaultNumberFormat;
920 DateFormat* defaultDateFormat;
921
922 UHashtable* cachedFormatters;
923 UHashtable* customFormatArgStarts;
924
925 PluralSelectorProvider pluralProvider;
926 PluralSelectorProvider ordinalProvider;
927
932 const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
933 const DateFormat* getDefaultDateFormat(UErrorCode&) const;
934
941 static int32_t findKeyword( const UnicodeString& s,
942 const char16_t * const *list);
943
949 UnicodeString& format(const Formattable* arguments,
950 const UnicodeString *argumentNames,
951 int32_t cnt,
952 UnicodeString& appendTo,
953 FieldPosition* pos,
954 UErrorCode& status) const;
955
973 void format(int32_t msgStart,
974 const void *plNumber,
975 const Formattable* arguments,
976 const UnicodeString *argumentNames,
977 int32_t cnt,
978 AppendableWrapper& appendTo,
979 FieldPosition* pos,
980 UErrorCode& success) const;
981
982 UnicodeString getArgName(int32_t partIndex);
983
984 void setArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status);
985
986 void setCustomArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status);
987
988 int32_t nextTopLevelArgStart(int32_t partIndex) const;
989
990 UBool argNameMatches(int32_t partIndex, const UnicodeString& argName, int32_t argNumber);
991
992 void cacheExplicitFormats(UErrorCode& status);
993
994 Format* createAppropriateFormat(UnicodeString& type,
995 UnicodeString& style,
996 Formattable::Type& formattableType,
997 UParseError& parseError,
998 UErrorCode& ec);
999
1000 const Formattable* getArgFromListByName(const Formattable* arguments,
1001 const UnicodeString *argumentNames,
1002 int32_t cnt, UnicodeString& name) const;
1003
1004 Formattable* parse(int32_t msgStart,
1005 const UnicodeString& source,
1006 ParsePosition& pos,
1007 int32_t& count,
1008 UErrorCode& ec) const;
1009
1010 FieldPosition* updateMetaData(AppendableWrapper& dest, int32_t prevLength,
1011 FieldPosition* fp, const Formattable* argId) const;
1012
1018 int32_t findOtherSubMessage(int32_t partIndex) const;
1019
1025 int32_t findFirstPluralNumberArg(int32_t msgStart, const UnicodeString &argName) const;
1026
1027 Format* getCachedFormatter(int32_t argumentNumber) const;
1028
1029 UnicodeString getLiteralStringUntilNextArgument(int32_t from) const;
1030
1031 void copyObjects(const MessageFormat& that, UErrorCode& ec);
1032
1033 void formatComplexSubMessage(int32_t msgStart,
1034 const void *plNumber,
1035 const Formattable* arguments,
1036 const UnicodeString *argumentNames,
1037 int32_t cnt,
1038 AppendableWrapper& appendTo,
1039 UErrorCode& success) const;
1040
1044 NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
1045
1053 const Formattable::Type* getArgTypeList(int32_t& listCount) const {
1054 listCount = argTypeCount;
1055 return argTypes;
1056 }
1057
1061 void resetPattern();
1062
1067 class U_I18N_API DummyFormat : public Format {
1068 public:
1069 virtual UBool operator==(const Format&) const;
1070 virtual Format* clone() const;
1071 virtual UnicodeString& format(const Formattable& obj,
1072 UnicodeString& appendTo,
1073 UErrorCode& status) const;
1074 virtual UnicodeString& format(const Formattable&,
1075 UnicodeString& appendTo,
1076 FieldPosition&,
1077 UErrorCode& status) const;
1078 virtual UnicodeString& format(const Formattable& obj,
1079 UnicodeString& appendTo,
1080 FieldPositionIterator* posIter,
1081 UErrorCode& status) const;
1082 virtual void parseObject(const UnicodeString&,
1083 Formattable&,
1084 ParsePosition&) const;
1085 };
1086
1087 friend class MessageFormatAdapter; // getFormatTypeList() access
1088 };
1089
1090 U_NAMESPACE_END
1091
1092 #endif /* #if !UCONFIG_NO_FORMATTING */
1093
1094 #endif // _MSGFMT
1095 //eof
icu::Format
Base class for all formats.
Definition: format.h:96
icu::PluralFormat::copyObjects
void copyObjects(const PluralFormat &other)
Copies dynamically allocated values (pointer fields).
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:174
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
icu::Formattable::Type
Type
Selector for flavor of data type contained within a Formattable object.
Definition: fmtable.h:225
icu::Format::getLocale
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
plurfmt.h
C++ API: PluralFormat object.
icu::StringEnumeration
Base class for &#39;pure&#39; C++ implementations of uenum api.
Definition: strenum.h:57
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
icu::PluralFormat::format
UnicodeString format(int32_t number, UErrorCode &status) const
Formats a plural message for a given number.
plurrule.h
C++ API: PluralRules object.
icu::MessageFormat::EFormatNumber
EFormatNumber
Enum type for kMaxFormat.
Definition: msgfmt.h:333
icu::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition: plurrule.h:197
format.h
C++ API: Base class for all formats.
icu::MessagePattern
Parses and represents ICU MessageFormat patterns.
Definition: messagepattern.h:360
U_CDECL_BEGIN
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:84
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:360
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:62
icu::PluralFormat::PluralSelector::select
virtual UnicodeString select(void *context, double number, UErrorCode &ec) const =0
Given a number, returns the appropriate PluralFormat keyword.
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::PluralFormat::PluralSelector
Definition: plurfmt.h:535
icu::MessageFormat::getApostropheMode
UMessagePatternApostropheMode getApostropheMode() const
Definition: msgfmt.h:480
icu::MessageFormat
Definition: msgfmt.h:325
U_CDECL_END
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:85
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
parseerr.h
C API: Parse Error Information.
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
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::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:149
locid.h
C++ API: Locale ID object.
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.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
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:286
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
messagepattern.h
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
UMessagePatternApostropheMode
UMessagePatternApostropheMode
Mode for when an apostrophe starts quoted literal text for MessageFormat output.
Definition: messagepattern.h:68
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:188