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 MessageFormat : public Format {
public:
#ifndef U_HIDE_OBSOLETE_API
enum EFormatNumber {
kMaxFormat = 10
};
#endif /* U_HIDE_OBSOLETE_API */
MessageFormat(const UnicodeString& pattern,
UErrorCode &status);
MessageFormat(const UnicodeString& pattern,
const Locale& newLocale,
UErrorCode& status);
MessageFormat(const UnicodeString& pattern,
const Locale& newLocale,
UParseError& parseError,
UErrorCode& status);
MessageFormat(const MessageFormat&);
const MessageFormat& operator=(const MessageFormat&);
virtual ~MessageFormat();
virtual MessageFormat* clone() const override;
virtual bool operator==(const Format& other) const override;
virtual void setLocale(const Locale& theLocale);
virtual const Locale& getLocale() const;
virtual void applyPattern(const UnicodeString& pattern,
UErrorCode& status);
virtual void applyPattern(const UnicodeString& pattern,
UParseError& parseError,
UErrorCode& status);
virtual void applyPattern(const UnicodeString& pattern,
UMessagePatternApostropheMode aposMode,
UParseError* parseError,
UErrorCode& status);
UMessagePatternApostropheMode getApostropheMode() const {
return msgPattern.getApostropheMode();
}
virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
virtual void setFormats(const Format** newFormats, int32_t cnt);
virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
virtual void setFormat(int32_t formatNumber, const Format& format);
virtual StringEnumeration* getFormatNames(UErrorCode& status);
virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status);
virtual void setFormat(const UnicodeString& formatName, const Format& format, UErrorCode& status);
virtual void adoptFormat(const UnicodeString& formatName, Format* formatToAdopt, UErrorCode& status);
virtual const Format** getFormats(int32_t& count) const;
using Format::format;
UnicodeString& format(const Formattable* source,
int32_t count,
UnicodeString& appendTo,
FieldPosition& ignore,
UErrorCode& status) const;
static UnicodeString& format(const UnicodeString& pattern,
const Formattable* arguments,
int32_t count,
UnicodeString& appendTo,
UErrorCode& status);
virtual UnicodeString& format(const Formattable& obj,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const override;
UnicodeString& format(const UnicodeString* argumentNames,
const Formattable* arguments,
int32_t count,
UnicodeString& appendTo,
UErrorCode& status) const;
virtual Formattable* parse(const UnicodeString& source,
ParsePosition& pos,
int32_t& count) const;
virtual Formattable* parse(const UnicodeString& source,
int32_t& count,
UErrorCode& status) const;
virtual void parseObject(const UnicodeString& source,
Formattable& result,
ParsePosition& pos) const override;
static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern,
UErrorCode& status);
UBool usesNamedArguments() const;
#ifndef U_HIDE_INTERNAL_API
int32_t getArgTypeCount() const;
#endif /* U_HIDE_INTERNAL_API */
virtual UClassID getDynamicClassID() const override;
static UClassID U_EXPORT2 getStaticClassID();
#ifndef U_HIDE_INTERNAL_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 U_I18N_API 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 U_I18N_API 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:156
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::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
icu::Format::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::Format::operator==
virtual bool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
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::LocalPointerBase
"Smart pointer" base class; do not use directly: use LocalPointer etc.
Definition localpointer.h:68
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
icu::MessageFormat
Definition msgfmt.h:345
icu::MessageFormat::parse
virtual Formattable * parse(const UnicodeString &source, ParsePosition &pos, int32_t &count) const
Parses the given string into an array of output arguments.
icu::MessageFormat::format
virtual 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::toPattern
virtual UnicodeString & toPattern(UnicodeString &appendTo) const
Returns a pattern that can be used to recreate this object.
icu::MessageFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern, UMessagePatternApostropheMode aposMode, UParseError *parseError, UErrorCode &status)
Sets the UMessagePatternApostropheMode and the pattern used by this message format.
icu::MessageFormat::parse
virtual Formattable * parse(const UnicodeString &source, int32_t &count, UErrorCode &status) const
Parses the given string into an array of output arguments.
icu::MessageFormat::adoptFormat
virtual void adoptFormat(const UnicodeString &formatName, Format *formatToAdopt, UErrorCode &status)
Sets one subformat for given format name.
icu::MessageFormat::MessageFormat
MessageFormat(const UnicodeString &pattern, UErrorCode &status)
Constructs a new MessageFormat using the given pattern and the default locale.
icu::MessageFormat::MessageFormat
MessageFormat(const UnicodeString &pattern, const Locale &newLocale, UParseError &parseError, UErrorCode &status)
Constructs a new MessageFormat using the given pattern and locale.
icu::MessageFormat::equalFormats
static UBool equalFormats(const void *left, const void *right)
Compares two Format objects.
icu::MessageFormat::getLocale
virtual const Locale & getLocale() const
Gets the locale used for creating argument Format objects.
icu::MessageFormat::setFormats
virtual void setFormats(const Format **newFormats, int32_t cnt)
Sets subformats.
icu::MessageFormat::autoQuoteApostrophe
static UnicodeString autoQuoteApostrophe(const UnicodeString &pattern, UErrorCode &status)
Convert an 'apostrophe-friendly' pattern into a standard pattern.
icu::MessageFormat::setFormat
virtual void setFormat(int32_t formatNumber, const Format &format)
Sets one subformat.
icu::MessageFormat::getApostropheMode
UMessagePatternApostropheMode getApostropheMode() const
Definition msgfmt.h:500
icu::MessageFormat::getArgTypeCount
int32_t getArgTypeCount() const
This API is for ICU internal use only.
icu::MessageFormat::operator=
const MessageFormat & operator=(const MessageFormat &)
Assignment operator.
icu::MessageFormat::MessageFormat
MessageFormat(const MessageFormat &)
Constructs a new MessageFormat from an existing one.
icu::MessageFormat::EFormatNumber
EFormatNumber
Enum type for kMaxFormat.
Definition msgfmt.h:353
icu::MessageFormat::parseObject
virtual 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::setLocale
virtual void setLocale(const Locale &theLocale)
Sets the locale to be used for creating argument Format objects.
icu::MessageFormat::~MessageFormat
virtual ~MessageFormat()
Destructor.
icu::MessageFormat::usesNamedArguments
UBool usesNamedArguments() const
Returns true if this MessageFormat uses named arguments, and false otherwise.
icu::MessageFormat::setFormat
virtual void setFormat(const UnicodeString &formatName, const Format &format, UErrorCode &status)
Sets one subformat for given format name.
icu::MessageFormat::operator==
virtual bool operator==(const Format &other) const override
Returns true if the given Format objects are semantically equal.
icu::MessageFormat::getFormats
virtual const Format ** getFormats(int32_t &count) const
Gets an array of subformats of this object.
icu::MessageFormat::format
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::adoptFormat
virtual void adoptFormat(int32_t formatNumber, Format *formatToAdopt)
Sets one subformat.
icu::MessageFormat::clone
virtual MessageFormat * clone() const override
Clones this Format object polymorphically.
icu::MessageFormat::format
static 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::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::MessageFormat::getFormat
virtual Format * getFormat(const UnicodeString &formatName, UErrorCode &status)
Gets subformat pointer for given format name.
icu::MessageFormat::MessageFormat
MessageFormat(const UnicodeString &pattern, const Locale &newLocale, UErrorCode &status)
Constructs a new MessageFormat using the given pattern and locale.
icu::MessageFormat::format
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::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::MessageFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern, UParseError &parseError, UErrorCode &status)
Applies the given pattern string to this message format.
icu::MessageFormat::adoptFormats
virtual void adoptFormats(Format **formatsToAdopt, int32_t count)
Sets subformats.
icu::MessageFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Applies the given pattern string to this message format.
icu::MessageFormat::getFormatNames
virtual StringEnumeration * getFormatNames(UErrorCode &status)
Gets format names.
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:296
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:247
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:430
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