Loading...
Searching...
No Matches
msgfmt.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-2013, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************************
*
* File MSGFMT.H
*
* Modification History:
*
* Date Name Description
* 02/19/97 aliu Converted from java.
* 03/20/97 helena Finished first cut of implementation.
* 07/22/98 stephen Removed operator!= (defined in Format)
* 08/19/2002 srl Removing Javaisms
*******************************************************************************/
#ifndef MSGFMT_H
#define MSGFMT_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/format.h"
#include "unicode/locid.h"
#include "unicode/messagepattern.h"
#include "unicode/parseerr.h"
#include "unicode/plurfmt.h"
#include "unicode/plurrule.h"
U_CDECL_BEGIN
// Forward declaration.
struct UHashtable;
typedef struct UHashtable UHashtable;
U_CDECL_END
U_NAMESPACE_BEGIN
class AppendableWrapper;
class DateFormat;
class NumberFormat;
class U_I18N_API_CLASS MessageFormat : public Format {
public:
#ifndef U_HIDE_OBSOLETE_API
enum EFormatNumber {
kMaxFormat = 10
};
#endif /* U_HIDE_OBSOLETE_API */
U_I18N_API MessageFormat(const UnicodeString& pattern, UErrorCode& status);
U_I18N_API MessageFormat(const UnicodeString& pattern, const Locale& newLocale, UErrorCode& status);
U_I18N_API MessageFormat(const UnicodeString& pattern,
const Locale& newLocale,
UParseError& parseError,
UErrorCode& status);
U_I18N_API MessageFormat(const MessageFormat&);
U_I18N_API const MessageFormat& operator=(const MessageFormat&);
U_I18N_API virtual ~MessageFormat();
U_I18N_API virtual MessageFormat* clone() const override;
U_I18N_API virtual bool operator==(const Format& other) const override;
U_I18N_API virtual void setLocale(const Locale& theLocale);
U_I18N_API virtual const Locale& getLocale() const;
U_I18N_API virtual void applyPattern(const UnicodeString& pattern, UErrorCode& status);
U_I18N_API virtual void applyPattern(const UnicodeString& pattern,
UParseError& parseError,
UErrorCode& status);
U_I18N_API virtual void applyPattern(const UnicodeString& pattern,
UMessagePatternApostropheMode aposMode,
UParseError* parseError,
UErrorCode& status);
U_I18N_API UMessagePatternApostropheMode getApostropheMode() const {
return msgPattern.getApostropheMode();
}
U_I18N_API virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
U_I18N_API virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
U_I18N_API virtual void setFormats(const Format** newFormats, int32_t cnt);
U_I18N_API virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
U_I18N_API virtual void setFormat(int32_t formatNumber, const Format& format);
U_I18N_API virtual StringEnumeration* getFormatNames(UErrorCode& status);
U_I18N_API virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status);
U_I18N_API virtual void setFormat(const UnicodeString& formatName,
const Format& format,
UErrorCode& status);
U_I18N_API virtual void adoptFormat(const UnicodeString& formatName,
Format* formatToAdopt,
UErrorCode& status);
U_I18N_API virtual const Format** getFormats(int32_t& count) const;
using Format::format;
U_I18N_API UnicodeString& format(const Formattable* source,
int32_t count,
UnicodeString& appendTo,
FieldPosition& ignore,
UErrorCode& status) const;
U_I18N_API static UnicodeString& format(const UnicodeString& pattern,
const Formattable* arguments,
int32_t count,
UnicodeString& appendTo,
UErrorCode& status);
U_I18N_API virtual UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const override;
U_I18N_API UnicodeString& format(const UnicodeString* argumentNames,
const Formattable* arguments,
int32_t count,
UnicodeString& appendTo,
UErrorCode& status) const;
U_I18N_API virtual Formattable* parse(const UnicodeString& source,
ParsePosition& pos,
int32_t& count) const;
U_I18N_API virtual Formattable* parse(const UnicodeString& source,
int32_t& count,
UErrorCode& status) const;
U_I18N_API virtual void parseObject(const UnicodeString& source,
Formattable& result,
ParsePosition& pos) const override;
U_I18N_API static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern, UErrorCode& status);
U_I18N_API UBool usesNamedArguments() const;
#ifndef U_HIDE_INTERNAL_API
U_I18N_API int32_t getArgTypeCount() const;
#endif /* U_HIDE_INTERNAL_API */
U_I18N_API virtual UClassID getDynamicClassID() const override;
U_I18N_API static UClassID getStaticClassID();
#ifndef U_HIDE_INTERNAL_API
U_I18N_API static UBool equalFormats(const void* left, const void* right);
#endif /* U_HIDE_INTERNAL_API */
private:
Locale fLocale;
MessagePattern msgPattern;
Format** formatAliases; // see getFormats
int32_t formatAliasesCapacity;
MessageFormat() = delete; // default constructor not implemented
class PluralSelectorProvider : public PluralFormat::PluralSelector {
public:
PluralSelectorProvider(const MessageFormat &mf, UPluralType type);
virtual ~PluralSelectorProvider();
virtual UnicodeString select(void *ctx, double number, UErrorCode& ec) const override;
void reset();
private:
const MessageFormat &msgFormat;
PluralRules* rules;
UPluralType type;
};
Formattable::Type* argTypes;
int32_t argTypeCount;
int32_t argTypeCapacity;
UBool hasArgTypeConflicts;
// Variable-size array management
UBool allocateArgTypes(int32_t capacity, UErrorCode& status);
NumberFormat* defaultNumberFormat;
DateFormat* defaultDateFormat;
UHashtable* cachedFormatters;
UHashtable* customFormatArgStarts;
PluralSelectorProvider pluralProvider;
PluralSelectorProvider ordinalProvider;
const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
const DateFormat* getDefaultDateFormat(UErrorCode&) const;
static int32_t findKeyword( const UnicodeString& s,
const char16_t * const *list);
UnicodeString& format(const Formattable* arguments,
const UnicodeString *argumentNames,
int32_t cnt,
UnicodeString& appendTo,
FieldPosition* pos,
UErrorCode& status) const;
void format(int32_t msgStart,
const void *plNumber,
const Formattable* arguments,
const UnicodeString *argumentNames,
int32_t cnt,
AppendableWrapper& appendTo,
FieldPosition* pos,
UErrorCode& success) const;
UnicodeString getArgName(int32_t partIndex);
void setArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status);
void setCustomArgStartFormat(int32_t argStart, Format* formatter, UErrorCode& status);
int32_t nextTopLevelArgStart(int32_t partIndex) const;
UBool argNameMatches(int32_t partIndex, const UnicodeString& argName, int32_t argNumber);
void cacheExplicitFormats(UErrorCode& status);
Format* createAppropriateFormat(UnicodeString& type,
UnicodeString& style,
Formattable::Type& formattableType,
UParseError& parseError,
UErrorCode& ec);
const Formattable* getArgFromListByName(const Formattable* arguments,
const UnicodeString *argumentNames,
int32_t cnt, UnicodeString& name) const;
Formattable* parse(int32_t msgStart,
const UnicodeString& source,
ParsePosition& pos,
int32_t& count,
UErrorCode& ec) const;
FieldPosition* updateMetaData(AppendableWrapper& dest, int32_t prevLength,
FieldPosition* fp, const Formattable* argId) const;
int32_t findOtherSubMessage(int32_t partIndex) const;
int32_t findFirstPluralNumberArg(int32_t msgStart, const UnicodeString &argName) const;
Format* getCachedFormatter(int32_t argumentNumber) const;
UnicodeString getLiteralStringUntilNextArgument(int32_t from) const;
void copyObjects(const MessageFormat& that, UErrorCode& ec);
void formatComplexSubMessage(int32_t msgStart,
const void *plNumber,
const Formattable* arguments,
const UnicodeString *argumentNames,
int32_t cnt,
AppendableWrapper& appendTo,
UErrorCode& success) const;
NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
const Formattable::Type* getArgTypeList(int32_t& listCount) const {
listCount = argTypeCount;
return argTypes;
}
void resetPattern();
class DummyFormat : public Format {
public:
virtual bool operator==(const Format&) const override;
virtual DummyFormat* clone() const override;
virtual UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
UErrorCode& status) const;
virtual UnicodeString& format(const Formattable&,
UnicodeString& appendTo,
FieldPosition&,
UErrorCode& status) const override;
virtual UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
FieldPositionIterator* posIter,
UErrorCode& status) const override;
virtual void parseObject(const UnicodeString&,
Formattable&,
ParsePosition&) const override;
};
friend class MessageFormatAdapter; // getFormatTypeList() access
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // _MSGFMT
//eof
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:144
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
Base class for all formats.
Definition format.h:98
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::Formattable::Type
Type
Selector for flavor of data type contained within a Formattable object.
Definition fmtable.h:220
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:198
icu::MessageFormat
Definition msgfmt.h:345
icu::MessageFormat::adoptFormats
virtual U_I18N_API void adoptFormats(Format **formatsToAdopt, int32_t count)
Sets subformats.
icu::MessageFormat::getLocale
virtual U_I18N_API const Locale & getLocale() const
Gets the locale used for creating argument Format objects.
icu::MessageFormat::getArgTypeCount
U_I18N_API int32_t getArgTypeCount() const
This API is for ICU internal use only.
icu::MessageFormat::MessageFormat
U_I18N_API MessageFormat(const UnicodeString &pattern, const Locale &newLocale, UErrorCode &status)
Constructs a new MessageFormat using the given pattern and locale.
icu::MessageFormat::format
virtual U_I18N_API UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Formats the given array of arguments into a user-readable string.
icu::MessageFormat::adoptFormat
virtual U_I18N_API void adoptFormat(const UnicodeString &formatName, Format *formatToAdopt, UErrorCode &status)
Sets one subformat for given format name.
icu::MessageFormat::parseObject
virtual U_I18N_API void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &pos) const override
Parses the given string into an array of output arguments stored within a single Formattable of type ...
icu::MessageFormat::getStaticClassID
static U_I18N_API UClassID getStaticClassID()
Return the class ID for this class.
icu::MessageFormat::parse
virtual U_I18N_API Formattable * parse(const UnicodeString &source, int32_t &count, UErrorCode &status) const
Parses the given string into an array of output arguments.
icu::MessageFormat::usesNamedArguments
U_I18N_API UBool usesNamedArguments() const
Returns true if this MessageFormat uses named arguments, and false otherwise.
icu::MessageFormat::getFormats
virtual U_I18N_API const Format ** getFormats(int32_t &count) const
Gets an array of subformats of this object.
icu::MessageFormat::setFormats
virtual U_I18N_API void setFormats(const Format **newFormats, int32_t cnt)
Sets subformats.
icu::MessageFormat::MessageFormat
U_I18N_API MessageFormat(const UnicodeString &pattern, UErrorCode &status)
Constructs a new MessageFormat using the given pattern and the default locale.
icu::MessageFormat::getFormat
virtual U_I18N_API Format * getFormat(const UnicodeString &formatName, UErrorCode &status)
Gets subformat pointer for given format name.
icu::MessageFormat::operator==
virtual U_I18N_API bool operator==(const Format &other) const override
Returns true if the given Format objects are semantically equal.
icu::MessageFormat::getDynamicClassID
virtual U_I18N_API UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::MessageFormat::adoptFormat
virtual U_I18N_API void adoptFormat(int32_t formatNumber, Format *formatToAdopt)
Sets one subformat.
icu::MessageFormat::parse
virtual U_I18N_API Formattable * parse(const UnicodeString &source, ParsePosition &pos, int32_t &count) const
Parses the given string into an array of output arguments.
icu::MessageFormat::EFormatNumber
EFormatNumber
Enum type for kMaxFormat.
Definition msgfmt.h:353
icu::MessageFormat::kMaxFormat
@ kMaxFormat
The maximum number of arguments.
Definition msgfmt.h:359
icu::MessageFormat::operator=
U_I18N_API const MessageFormat & operator=(const MessageFormat &)
Assignment operator.
icu::MessageFormat::format
static U_I18N_API UnicodeString & format(const UnicodeString &pattern, const Formattable *arguments, int32_t count, UnicodeString &appendTo, UErrorCode &status)
Formats the given array of arguments into a user-readable string using the given pattern.
icu::MessageFormat::format
U_I18N_API UnicodeString & format(const Formattable *source, int32_t count, UnicodeString &appendTo, FieldPosition &ignore, UErrorCode &status) const
Formats the given array of arguments into a user-readable string.
icu::MessageFormat::applyPattern
virtual U_I18N_API void applyPattern(const UnicodeString &pattern, UParseError &parseError, UErrorCode &status)
Applies the given pattern string to this message format.
icu::MessageFormat::MessageFormat
U_I18N_API MessageFormat(const MessageFormat &)
Constructs a new MessageFormat from an existing one.
icu::MessageFormat::setFormat
virtual U_I18N_API void setFormat(const UnicodeString &formatName, const Format &format, UErrorCode &status)
Sets one subformat for given format name.
icu::MessageFormat::clone
virtual U_I18N_API MessageFormat * clone() const override
Clones this Format object polymorphically.
icu::MessageFormat::~MessageFormat
virtual U_I18N_API ~MessageFormat()
Destructor.
icu::MessageFormat::applyPattern
virtual U_I18N_API void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Applies the given pattern string to this message format.
icu::MessageFormat::autoQuoteApostrophe
static U_I18N_API UnicodeString autoQuoteApostrophe(const UnicodeString &pattern, UErrorCode &status)
Convert an 'apostrophe-friendly' pattern into a standard pattern.
icu::MessageFormat::MessageFormat
U_I18N_API MessageFormat(const UnicodeString &pattern, const Locale &newLocale, UParseError &parseError, UErrorCode &status)
Constructs a new MessageFormat using the given pattern and locale.
icu::MessageFormat::setLocale
virtual U_I18N_API void setLocale(const Locale &theLocale)
Sets the locale to be used for creating argument Format objects.
icu::MessageFormat::format
U_I18N_API UnicodeString & format(const UnicodeString *argumentNames, const Formattable *arguments, int32_t count, UnicodeString &appendTo, UErrorCode &status) const
Formats the given array of arguments into a user-defined argument name array.
icu::MessageFormat::getApostropheMode
U_I18N_API UMessagePatternApostropheMode getApostropheMode() const
Definition msgfmt.h:496
icu::MessageFormat::getFormatNames
virtual U_I18N_API StringEnumeration * getFormatNames(UErrorCode &status)
Gets format names.
icu::MessageFormat::applyPattern
virtual U_I18N_API void applyPattern(const UnicodeString &pattern, UMessagePatternApostropheMode aposMode, UParseError *parseError, UErrorCode &status)
Sets the UMessagePatternApostropheMode and the pattern used by this message format.
icu::MessageFormat::setFormat
virtual U_I18N_API void setFormat(int32_t formatNumber, const Format &format)
Sets one subformat.
icu::MessageFormat::equalFormats
static U_I18N_API UBool equalFormats(const void *left, const void *right)
Compares two Format objects.
icu::MessageFormat::toPattern
virtual U_I18N_API UnicodeString & toPattern(UnicodeString &appendTo) const
Returns a pattern that can be used to recreate this object.
icu::MessagePattern
Parses and represents ICU MessageFormat patterns.
Definition messagepattern.h:362
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::PluralRules
Defines rules for mapping non-negative numeric values onto a small set of keywords.
Definition plurrule.h:212
icu::StringEnumeration
Base class for 'pure' C++ implementations of uenum api.
Definition strenum.h:61
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
format.h
C++ API: Base class for all formats.
locid.h
C++ API: Locale ID object.
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:70
UHashtable
struct UHashtable UHashtable
Definition msgfmt.h:43
parseerr.h
C API: Parse Error Information.
plurfmt.h
C++ API: PluralFormat object.
plurrule.h
C++ API: PluralRules object.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:58
U_CDECL_END
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:86
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
U_CDECL_BEGIN
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:85
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