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

- Search for |

- File List
- Globals

# msgfmt.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (C) 2007-2009, International Business Machines Corporation and others. All Rights Reserved.
    00003 ********************************************************************************
    00004 *
    00005 * File MSGFMT.H
    00006 *
    00007 * Modification History:
    00008 *
    00009 *   Date        Name        Description
    00010 *   02/19/97    aliu        Converted from java.
    00011 *   03/20/97    helena      Finished first cut of implementation.
    00012 *   07/22/98    stephen     Removed operator!= (defined in Format)
    00013 *   08/19/2002  srl         Removing Javaisms
    00014 ********************************************************************************
    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
    00306 class U_I18N_API MessageFormat : public Format {
    00307 public:
    00313     enum EFormatNumber {
    00319         kMaxFormat = 10
    00320     };
    00321
    00331     MessageFormat(const UnicodeString& pattern,
    00332                   UErrorCode &status);
    00333
    00342     MessageFormat(const UnicodeString& pattern,
    00343                   const Locale& newLocale,
    00344                         UErrorCode& status);
    00355     MessageFormat(const UnicodeString& pattern,
    00356                   const Locale& newLocale,
    00357                   UParseError& parseError,
    00358                   UErrorCode& status);
    00363     MessageFormat(const MessageFormat&);
    00364
    00369     const MessageFormat& operator=(const MessageFormat&);
    00370
    00375     virtual ~MessageFormat();
    00376
    00382     virtual Format* clone(void) const;
    00383
    00391     virtual UBool operator==(const Format& other) const;
    00392
    00399     virtual void setLocale(const Locale& theLocale);
    00400
    00407     virtual const Locale& getLocale(void) const;
    00408
    00417     virtual void applyPattern(const UnicodeString& pattern,
    00418                               UErrorCode& status);
    00429     virtual void applyPattern(const UnicodeString& pattern,
    00430                              UParseError& parseError,
    00431                              UErrorCode& status);
    00432
    00441     virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
    00442
    00456     virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
    00457
    00469     virtual void setFormats(const Format** newFormats, int32_t cnt);
    00470
    00471
    00482     virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
    00483
    00493     virtual void setFormat(int32_t formatNumber, const Format& format);
    00494
    00503     virtual StringEnumeration* getFormatNames(UErrorCode& status);
    00504
    00518     virtual Format* getFormat(const UnicodeString& formatName, UErrorCode& status);
    00519
    00533     virtual void setFormat(const UnicodeString& formatName, const Format& format, UErrorCode& status);
    00534
    00549     virtual void adoptFormat(const UnicodeString& formatName, Format* formatToAdopt, UErrorCode& status);
    00550
    00551
    00563     virtual const Format** getFormats(int32_t& count) const;
    00564
    00579     UnicodeString& format(  const Formattable* source,
    00580                             int32_t count,
    00581                             UnicodeString& appendTo,
    00582                             FieldPosition& ignore,
    00583                             UErrorCode& status) const;
    00584
    00599     static UnicodeString& format(const UnicodeString& pattern,
    00600                                  const Formattable* arguments,
    00601                                  int32_t count,
    00602                                  UnicodeString& appendTo,
    00603                                  UErrorCode& status);
    00604
    00622     virtual UnicodeString& format(const Formattable& obj,
    00623                                   UnicodeString& appendTo,
    00624                                   FieldPosition& pos,
    00625                                   UErrorCode& status) const;
    00626
    00641     UnicodeString& format(const Formattable& obj,
    00642                           UnicodeString& appendTo,
    00643                           UErrorCode& status) const;
    00644
    00645
    00664     UnicodeString& format(const UnicodeString* argumentNames,
    00665                           const Formattable* arguments,
    00666                           int32_t count,
    00667                           UnicodeString& appendTo,
    00668                           UErrorCode& status) const;
    00682     virtual Formattable* parse( const UnicodeString& source,
    00683                                 ParsePosition& pos,
    00684                                 int32_t& count) const;
    00685
    00700     virtual Formattable* parse( const UnicodeString& source,
    00701                                 int32_t& count,
    00702                                 UErrorCode& status) const;
    00703
    00716     virtual void parseObject(const UnicodeString& source,
    00717                              Formattable& result,
    00718                              ParsePosition& pos) const;
    00719
    00739     static UnicodeString autoQuoteApostrophe(const UnicodeString& pattern,
    00740         UErrorCode& status);
    00741
    00749     UBool usesNamedArguments() const;
    00750
    00751
    00762     int32_t getArgTypeCount() const;
    00763
    00775     virtual UClassID getDynamicClassID(void) const;
    00776
    00788     static UClassID U_EXPORT2 getStaticClassID(void);
    00789
    00790 private:
    00791
    00792     Locale              fLocale;
    00793     UnicodeString       fPattern;
    00794     Format**            formatAliases; // see getFormats
    00795     int32_t             formatAliasesCapacity;
    00796     UProperty           idStart;
    00797     UProperty           idContinue;
    00798
    00799     MessageFormat(); // default constructor not implemented
    00800
    00801     /*
    00802      * A structure representing one subformat of this MessageFormat.
    00803      * Each subformat has a Format object, an offset into the plain
    00804      * pattern text fPattern, and an argument number.  The argument
    00805      * number corresponds to the array of arguments to be formatted.
    00806      * @internal
    00807      */
    00808     class Subformat;
    00809
    00814     Subformat* subformats;
    00815     int32_t    subformatCount;
    00816     int32_t    subformatCapacity;
    00817
    00826     Formattable::Type* argTypes;
    00827     int32_t            argTypeCount;
    00828     int32_t            argTypeCapacity;
    00829
    00834     UBool isArgNumeric;
    00835
    00836     // Variable-size array management
    00837     UBool allocateSubformats(int32_t capacity);
    00838     UBool allocateArgTypes(int32_t capacity);
    00839
    00847     NumberFormat* defaultNumberFormat;
    00848     DateFormat*   defaultDateFormat;
    00849
    00854     const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
    00855     const DateFormat*   getDefaultDateFormat(UErrorCode&) const;
    00856
    00863     static int32_t findKeyword( const UnicodeString& s,
    00864                                 const UChar * const *list);
    00865
    00882     UnicodeString&  format( const Formattable* arguments,
    00883                             int32_t cnt,
    00884                             UnicodeString& appendTo,
    00885                             FieldPosition& status,
    00886                             int32_t recursionProtection,
    00887                             UErrorCode& success) const;
    00888
    00889     UnicodeString&  format( const Formattable* arguments,
    00890                             const UnicodeString *argumentNames,
    00891                             int32_t cnt,
    00892                             UnicodeString& appendTo,
    00893                             FieldPosition& status,
    00894                             int32_t recursionProtection,
    00895                             UErrorCode& success) const;
    00896
    00897     void             makeFormat(int32_t offsetNumber,
    00898                                 UnicodeString* segments,
    00899                                 UParseError& parseError,
    00900                                 UErrorCode& success);
    00901
    00905     NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
    00906
    00916     static void copyAndFixQuotes(const UnicodeString& appendTo, int32_t start, int32_t end, UnicodeString& target);
    00917
    00926     const Formattable::Type* getArgTypeList(int32_t& listCount) const {
    00927         listCount = argTypeCount;
    00928         return argTypes;
    00929     }
    00930
    00936     UBool isLegalArgName(const UnicodeString& argName) const;
    00937
    00938     friend class MessageFormatAdapter; // getFormatTypeList() access
    00939 };
    00940
    00941 inline UnicodeString&
    00942 MessageFormat::format(const Formattable& obj,
    00943                       UnicodeString& appendTo,
    00944                       UErrorCode& status) const {
    00945     return Format::format(obj, appendTo, status);
    00946 }
    00947 U_NAMESPACE_END
    00948
    00949 #endif /* #if !UCONFIG_NO_FORMATTING */
    00950
    00951 #endif // _MSGFMT
    00952 //eof
    00953