ICU 4.2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
msgfmt.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007-2009, International Business Machines Corporation and others. All Rights Reserved.
3 ********************************************************************************
4 *
5 * File MSGFMT.H
6 *
7 * Modification History:
8 *
9 * Date Name Description
10 * 02/19/97 aliu Converted from java.
11 * 03/20/97 helena Finished first cut of implementation.
12 * 07/22/98 stephen Removed operator!= (defined in Format)
13 * 08/19/2002 srl Removing Javaisms
14 ********************************************************************************
15 */
16 
17 #ifndef MSGFMT_H
18 #define MSGFMT_H
19 
20 #include "unicode/utypes.h"
21 
27 #if !UCONFIG_NO_FORMATTING
28 
29 #include "unicode/format.h"
30 #include "unicode/locid.h"
31 #include "unicode/parseerr.h"
32 #include "unicode/uchar.h"
33 
35 
36 class NumberFormat;
37 class DateFormat;
38 
307 public:
319  kMaxFormat = 10
320  };
321 
331  MessageFormat(const UnicodeString& pattern,
332  UErrorCode &status);
333 
342  MessageFormat(const UnicodeString& pattern,
343  const Locale& newLocale,
344  UErrorCode& status);
355  MessageFormat(const UnicodeString& pattern,
356  const Locale& newLocale,
357  UParseError& parseError,
358  UErrorCode& status);
364 
369  const MessageFormat& operator=(const MessageFormat&);
370 
375  virtual ~MessageFormat();
376 
382  virtual Format* clone(void) const;
383 
391  virtual UBool operator==(const Format& other) const;
392 
399  virtual void setLocale(const Locale& theLocale);
400 
407  virtual const Locale& getLocale(void) const;
408 
417  virtual void applyPattern(const UnicodeString& pattern,
418  UErrorCode& status);
429  virtual void applyPattern(const UnicodeString& pattern,
430  UParseError& parseError,
431  UErrorCode& status);
432 
441  virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
442 
456  virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
457 
469  virtual void setFormats(const Format** newFormats, int32_t cnt);
470 
471 
482  virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
483 
493  virtual void setFormat(int32_t formatNumber, const Format& format);
494 
503  virtual StringEnumeration* getFormatNames(UErrorCode& status);
504 
518  virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status);
519 
533  virtual void setFormat(const UnicodeString& formatName, const Format& format, UErrorCode& status);
534 
549  virtual void adoptFormat(const UnicodeString& formatName, Format* formatToAdopt, UErrorCode& status);
550 
551 
563  virtual const Format** getFormats(int32_t& count) const;
564 
579  UnicodeString& format( const Formattable* source,
580  int32_t count,
581  UnicodeString& appendTo,
582  FieldPosition& ignore,
583  UErrorCode& status) const;
584 
599  static UnicodeString& format(const UnicodeString& pattern,
600  const Formattable* arguments,
601  int32_t count,
602  UnicodeString& appendTo,
603  UErrorCode& status);
604 
622  virtual UnicodeString& format(const Formattable& obj,
623  UnicodeString& appendTo,
624  FieldPosition& pos,
625  UErrorCode& status) const;
626 
641  UnicodeString& format(const Formattable& obj,
642  UnicodeString& appendTo,
643  UErrorCode& status) const;
644 
645 
664  UnicodeString& format(const UnicodeString* argumentNames,
665  const Formattable* arguments,
666  int32_t count,
667  UnicodeString& appendTo,
668  UErrorCode& status) const;
682  virtual Formattable* parse( const UnicodeString& source,
683  ParsePosition& pos,
684  int32_t& count) const;
685 
700  virtual Formattable* parse( const UnicodeString& source,
701  int32_t& count,
702  UErrorCode& status) const;
703 
716  virtual void parseObject(const UnicodeString& source,
717  Formattable& result,
718  ParsePosition& pos) const;
719 
739  static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern,
740  UErrorCode& status);
741 
749  UBool usesNamedArguments() const;
750 
751 
762  int32_t getArgTypeCount() const;
763 
775  virtual UClassID getDynamicClassID(void) const;
776 
788  static UClassID U_EXPORT2 getStaticClassID(void);
789 
790 private:
791 
792  Locale fLocale;
793  UnicodeString fPattern;
794  Format** formatAliases; // see getFormats
795  int32_t formatAliasesCapacity;
796  UProperty idStart;
797  UProperty idContinue;
798 
799  MessageFormat(); // default constructor not implemented
800 
801  /*
802  * A structure representing one subformat of this MessageFormat.
803  * Each subformat has a Format object, an offset into the plain
804  * pattern text fPattern, and an argument number. The argument
805  * number corresponds to the array of arguments to be formatted.
806  * @internal
807  */
808  class Subformat;
809 
814  Subformat* subformats;
815  int32_t subformatCount;
816  int32_t subformatCapacity;
817 
826  Formattable::Type* argTypes;
827  int32_t argTypeCount;
828  int32_t argTypeCapacity;
829 
834  UBool isArgNumeric;
835 
836  // Variable-size array management
837  UBool allocateSubformats(int32_t capacity);
838  UBool allocateArgTypes(int32_t capacity);
839 
847  NumberFormat* defaultNumberFormat;
848  DateFormat* defaultDateFormat;
849 
854  const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
855  const DateFormat* getDefaultDateFormat(UErrorCode&) const;
856 
863  static int32_t findKeyword( const UnicodeString& s,
864  const UChar * const *list);
865 
882  UnicodeString& format( const Formattable* arguments,
883  int32_t cnt,
884  UnicodeString& appendTo,
885  FieldPosition& status,
886  int32_t recursionProtection,
887  UErrorCode& success) const;
888 
889  UnicodeString& format( const Formattable* arguments,
890  const UnicodeString *argumentNames,
891  int32_t cnt,
892  UnicodeString& appendTo,
893  FieldPosition& status,
894  int32_t recursionProtection,
895  UErrorCode& success) const;
896 
897  void makeFormat(int32_t offsetNumber,
898  UnicodeString* segments,
899  UParseError& parseError,
900  UErrorCode& success);
901 
905  NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
906 
916  static void copyAndFixQuotes(const UnicodeString& appendTo, int32_t start, int32_t end, UnicodeString& target);
917 
926  const Formattable::Type* getArgTypeList(int32_t& listCount) const {
927  listCount = argTypeCount;
928  return argTypes;
929  }
930 
936  UBool isLegalArgName(const UnicodeString& argName) const;
937 
938  friend class MessageFormatAdapter; // getFormatTypeList() access
939 };
940 
941 inline UnicodeString&
943  UnicodeString& appendTo,
944  UErrorCode& status) const {
945  return Format::format(obj, appendTo, status);
946 }
948 
949 #endif /* #if !UCONFIG_NO_FORMATTING */
950 
951 #endif // _MSGFMT
952 //eof
953 
virtual UClassID getDynamicClassID() const =0
Returns a unique class ID POLYMORPHICALLY.
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &parse_pos) const =0
Parse a string to produce an object.
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:138
C++ API: Base class for all formats.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:475
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:183
Abstract base class for all number formats.
Definition: numfmt.h:162
Type
Selector for flavor of data type contained within a Formattable object.
Definition: fmtable.h:189
EFormatNumber
Enum type for kMaxFormat.
Definition: msgfmt.h:313
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
virtual UBool operator==(const Format &other) const =0
Return true if the given Format objects are semantically equal.
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.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:187
#define U_EXPORT2
Definition: platform.h:338
C API: Unicode Properties.
virtual Format * clone() const =0
Clone this object polymorphically.
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
uint16_t UChar
Define UChar to be wchar_t if that is 16 bits wide; always assumed to be unsigned.
Definition: umachine.h:299
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API If the compiler doesn't support namespaces...
Definition: uversion.h:184
C API: Parse Error Information.
UProperty
Selection constants for Unicode properties.
Definition: uchar.h:174
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:47
void * UClassID
UClassID is used to identify classes without using RTTI, since RTTI is not yet supported by all C++ c...
Definition: utypes.h:339
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:593
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:55
C++ API: Locale ID object.
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
Base class for all formats.
Definition: format.h:93
Basic definitions for ICU, for both C and C++ APIs.
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this format object.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:181
signed int int32_t
Define 64 bit limits.
Definition: pwin32.h:143
A MessageFormat produces concatenated messages in a language-neutral way.
Definition: msgfmt.h:306
int8_t UBool
The ICU boolean type.
Definition: umachine.h:208
Format & operator=(const Format &)