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

- File List
- Globals

# msgfmt.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (C) 2007-2010, International Business Machines Corporation and
    00003 * others. All Rights Reserved.
    00004 ********************************************************************************
    00005 *
    00006 * File MSGFMT.H
    00007 *
    00008 * Modification History:
    00009 *
    00010 *   Date        Name        Description
    00011 *   02/19/97    aliu        Converted from java.
    00012 *   03/20/97    helena      Finished first cut of implementation.
    00013 *   07/22/98    stephen     Removed operator!= (defined in Format)
    00014 *   08/19/2002  srl         Removing Javaisms
    00015 *******************************************************************************/
    00016
    00017 #ifndef MSGFMT_H
    00018 #define MSGFMT_H
    00019
    00020 #include "unicode/utypes.h"
    00021
    00027 #if !UCONFIG_NO_FORMATTING
    00028
    00029 #include "unicode/format.h"
    00030 #include "unicode/locid.h"
    00031 #include "unicode/parseerr.h"
    00032 #include "unicode/uchar.h"
    00033
    00034 U_NAMESPACE_BEGIN
    00035
    00036 class NumberFormat;
    00037 class DateFormat;
    00038
    00317 class U_I18N_API MessageFormat : public Format {
    00318 public:
    00324     enum EFormatNumber {
    00330         kMaxFormat = 10
    00331     };
    00332
    00342     MessageFormat(const UnicodeString& pattern,
    00343                   UErrorCode &status);
    00344
    00353     MessageFormat(const UnicodeString& pattern,
    00354                   const Locale& newLocale,
    00355                         UErrorCode& status);
    00366     MessageFormat(const UnicodeString& pattern,
    00367                   const Locale& newLocale,
    00368                   UParseError& parseError,
    00369                   UErrorCode& status);
    00374     MessageFormat(const MessageFormat&);
    00375
    00380     const MessageFormat& operator=(const MessageFormat&);
    00381
    00386     virtual ~MessageFormat();
    00387
    00393     virtual Format* clone(void) const;
    00394
    00402     virtual UBool operator==(const Format& other) const;
    00403
    00410     virtual void setLocale(const Locale& theLocale);
    00411
    00418     virtual const Locale& getLocale(void) const;
    00419
    00428     virtual void applyPattern(const UnicodeString& pattern,
    00429                               UErrorCode& status);
    00440     virtual void applyPattern(const UnicodeString& pattern,
    00441                              UParseError& parseError,
    00442                              UErrorCode& status);
    00443
    00452     virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
    00453
    00470     virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
    00471
    00486     virtual void setFormats(const Format** newFormats, int32_t cnt);
    00487
    00488
    00503     virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
    00504
    00514     virtual void setFormat(int32_t formatNumber, const Format& format);
    00515
    00524     virtual StringEnumeration* getFormatNames(UErrorCode& status);
    00525
    00539     virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status);
    00540
    00554     virtual void setFormat(const UnicodeString& formatName, const Format& format, UErrorCode& status);
    00555
    00570     virtual void adoptFormat(const UnicodeString& formatName, Format* formatToAdopt, UErrorCode& status);
    00571
    00584     virtual const Format** getFormats(int32_t& count) const;
    00585
    00586
    00587     using Format::format;
    00588
    00606     UnicodeString& format(const Formattable* source,
    00607                           int32_t count,
    00608                           UnicodeString& appendTo,
    00609                           FieldPosition& ignore,
    00610                           UErrorCode& status) const;
    00611
    00629     static UnicodeString& format(const UnicodeString& pattern,
    00630                                  const Formattable* arguments,
    00631                                  int32_t count,
    00632                                  UnicodeString& appendTo,
    00633                                  UErrorCode& status);
    00634
    00655     virtual UnicodeString& format(const Formattable& obj,
    00656                                   UnicodeString& appendTo,
    00657                                   FieldPosition& pos,
    00658                                   UErrorCode& status) const;
    00659
    00674     UnicodeString& format(const Formattable& obj,
    00675                           UnicodeString& appendTo,
    00676                           UErrorCode& status) const;
    00677
    00678
    00697     UnicodeString& format(const UnicodeString* argumentNames,
    00698                           const Formattable* arguments,
    00699                           int32_t count,
    00700                           UnicodeString& appendTo,
    00701                           UErrorCode& status) const;
    00715     virtual Formattable* parse(const UnicodeString& source,
    00716                                ParsePosition& pos,
    00717                                int32_t& count) const;
    00718
    00734     virtual Formattable* parse(const UnicodeString& source,
    00735                                int32_t& count,
    00736                                UErrorCode& status) const;
    00737
    00750     virtual void parseObject(const UnicodeString& source,
    00751                              Formattable& result,
    00752                              ParsePosition& pos) const;
    00753
    00773     static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern,
    00774         UErrorCode& status);
    00775
    00783     UBool usesNamedArguments() const;
    00784
    00785
    00796     int32_t getArgTypeCount() const;
    00797
    00809     virtual UClassID getDynamicClassID(void) const;
    00810
    00822     static UClassID U_EXPORT2 getStaticClassID(void);
    00823
    00824 private:
    00825
    00826     Locale              fLocale;
    00827     UnicodeString       fPattern;
    00828     Format**            formatAliases; // see getFormats
    00829     int32_t             formatAliasesCapacity;
    00830     UProperty           idStart;
    00831     UProperty           idContinue;
    00832
    00833     MessageFormat(); // default constructor not implemented
    00834
    00835     /*
    00836      * A structure representing one subformat of this MessageFormat.
    00837      * Each subformat has a Format object, an offset into the plain
    00838      * pattern text fPattern, and an argument number.  The argument
    00839      * number corresponds to the array of arguments to be formatted.
    00840      * @internal
    00841      */
    00842     class Subformat;
    00843
    00848     Subformat* subformats;
    00849     int32_t    subformatCount;
    00850     int32_t    subformatCapacity;
    00851
    00860     Formattable::Type* argTypes;
    00861     int32_t            argTypeCount;
    00862     int32_t            argTypeCapacity;
    00863
    00868     UBool isArgNumeric;
    00869
    00870     // Variable-size array management
    00871     UBool allocateSubformats(int32_t capacity);
    00872     UBool allocateArgTypes(int32_t capacity);
    00873
    00881     NumberFormat* defaultNumberFormat;
    00882     DateFormat*   defaultDateFormat;
    00883
    00888     const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
    00889     const DateFormat*   getDefaultDateFormat(UErrorCode&) const;
    00890
    00897     static int32_t findKeyword( const UnicodeString& s,
    00898                                 const UChar * const *list);
    00899
    00916     UnicodeString&  format( const Formattable* arguments,
    00917                             int32_t cnt,
    00918                             UnicodeString& appendTo,
    00919                             FieldPosition& status,
    00920                             int32_t recursionProtection,
    00921                             UErrorCode& success) const;
    00922
    00923     UnicodeString&  format( const Formattable* arguments,
    00924                             const UnicodeString *argumentNames,
    00925                             int32_t cnt,
    00926                             UnicodeString& appendTo,
    00927                             FieldPosition& status,
    00928                             int32_t recursionProtection,
    00929                             UErrorCode& success) const;
    00930
    00931     void             makeFormat(int32_t offsetNumber,
    00932                                 UnicodeString* segments,
    00933                                 UParseError& parseError,
    00934                                 UErrorCode& success);
    00935
    00939     NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
    00940
    00950     static void copyAndFixQuotes(const UnicodeString& appendTo, int32_t start, int32_t end, UnicodeString& target);
    00951
    00960     const Formattable::Type* getArgTypeList(int32_t& listCount) const {
    00961         listCount = argTypeCount;
    00962         return argTypes;
    00963     }
    00964
    00970     UBool isLegalArgName(const UnicodeString& argName) const;
    00971
    00972     friend class MessageFormatAdapter; // getFormatTypeList() access
    00973 };
    00974
    00975 inline UnicodeString&
    00976 MessageFormat::format(const Formattable& obj,
    00977                       UnicodeString& appendTo,
    00978                       UErrorCode& status) const {
    00979     return Format::format(obj, appendTo, status);
    00980 }
    00981
    00982 U_NAMESPACE_END
    00983
    00984 #endif /* #if !UCONFIG_NO_FORMATTING */
    00985
    00986 #endif // _MSGFMT
    00987 //eof

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines