Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

msgfmt.h

00001 /*
00002 * Copyright (C) {1997-2003}, 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 
00022 #if !UCONFIG_NO_FORMATTING
00023 
00024 #include "unicode/format.h"
00025 #include "unicode/locid.h"
00026 #include "unicode/parseerr.h"
00027 
00028 U_NAMESPACE_BEGIN
00029 
00030 class NumberFormat;
00031 class DateFormat;
00032 
00242 class U_I18N_API MessageFormat : public Format {
00243 public:
00249     enum EFormatNumber {
00255         kMaxFormat = 10
00256     };
00257 
00267     MessageFormat(const UnicodeString& pattern,
00268                   UErrorCode &status);
00269 
00278     MessageFormat(const UnicodeString& pattern,
00279                   const Locale& newLocale,
00280                         UErrorCode& status);
00291     MessageFormat(const UnicodeString& pattern,
00292                   const Locale& newLocale,
00293                   UParseError& parseError,
00294                   UErrorCode& status);
00299     MessageFormat(const MessageFormat&);
00300 
00305     const MessageFormat& operator=(const MessageFormat&);
00306 
00311     virtual ~MessageFormat();
00312 
00318     virtual Format* clone(void) const;
00319 
00327     virtual UBool operator==(const Format& other) const;
00328 
00335     virtual void setLocale(const Locale& theLocale);
00336 
00343     virtual const Locale& getLocale(void) const;
00344 
00353     virtual void applyPattern(const UnicodeString& pattern,
00354                               UErrorCode& status);
00365     virtual void applyPattern(const UnicodeString& pattern,
00366                              UParseError& parseError,
00367                              UErrorCode& status);
00368 
00377     virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
00378 
00392     virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
00393 
00405     virtual void setFormats(const Format** newFormats,int32_t cnt);
00406 
00407 
00418     virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
00419 
00429     virtual void setFormat(int32_t formatNumber, const Format& format);
00430 
00442     virtual const Format** getFormats(int32_t& count) const;
00443 
00458     UnicodeString& format(  const Formattable* source,
00459                             int32_t count,
00460                             UnicodeString& appendTo,
00461                             FieldPosition& ignore,
00462                             UErrorCode& status) const;
00463 
00478     static UnicodeString& format(   const UnicodeString& pattern,
00479                                     const Formattable* arguments,
00480                                     int32_t count,
00481                                     UnicodeString& appendTo,
00482                                     UErrorCode& status);
00483 
00501     virtual UnicodeString& format(const Formattable& obj,
00502                                   UnicodeString& appendTo,
00503                                   FieldPosition& pos,
00504                                   UErrorCode& status) const;
00505 
00520     UnicodeString& format(const Formattable& obj,
00521                           UnicodeString& appendTo,
00522                           UErrorCode& status) const;
00523 
00537     virtual Formattable* parse( const UnicodeString& source,
00538                                 ParsePosition& pos,
00539                                 int32_t& count) const;
00540 
00552     virtual Formattable* parse( const UnicodeString& source,
00553                                 int32_t& count,
00554                                 UErrorCode& status) const;
00555 
00568     virtual void parseObject(const UnicodeString& source,
00569                              Formattable& result,
00570                              ParsePosition& pos) const;
00571 
00583     virtual UClassID getDynamicClassID(void) const;
00584 
00596     static inline UClassID getStaticClassID(void);
00597     
00598 private:
00599     static const char fgClassID;
00600 
00601     Locale              fLocale;
00602     UnicodeString       fPattern;
00603     Format**            formatAliases; // see getFormats
00604     int32_t             formatAliasesCapacity;
00605 
00606     MessageFormat(); // default constructor not implemented
00607 
00615     class Subformat {
00616     public:
00620         Format* format; // formatter
00624         int32_t offset; // offset into fPattern
00628         int32_t arg;    // 0-based argument number
00629 
00635         Subformat& operator=(const Subformat& that) {
00636             format = that.format ? that.format->clone() : NULL;
00637             offset = that.offset;
00638             arg = that.arg;
00639             return *this;
00640         }
00641 
00645         UBool operator==(const Subformat& that) const {
00646             // Do cheap comparisons first
00647             return offset == that.offset &&
00648                    arg == that.arg &&
00649                    ((format == that.format) || // handles NULL
00650                     (*format == *that.format));
00651         }
00652 
00656         UBool operator!=(const Subformat& that) const {
00657             return !operator==(that);
00658         }
00659     };
00660 
00665     Subformat* subformats;
00666     int32_t    subformatCount;
00667     int32_t    subformatCapacity;
00668 
00677     Formattable::Type* argTypes;
00678     int32_t            argTypeCount;
00679     int32_t            argTypeCapacity;
00680 
00681     // Variable-size array management
00682     UBool allocateSubformats(int32_t capacity);
00683     UBool allocateArgTypes(int32_t capacity);
00684 
00692     NumberFormat* defaultNumberFormat;
00693     DateFormat*   defaultDateFormat;
00694 
00699     const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
00700     const DateFormat*   getDefaultDateFormat(UErrorCode&) const;
00701 
00708     static int32_t findKeyword( const UnicodeString& s,
00709                                 const UChar * const *list);
00710 
00727     UnicodeString&  format( const Formattable* arguments,
00728                             int32_t cnt,
00729                             UnicodeString& appendTo,
00730                             FieldPosition& status,
00731                             int32_t recursionProtection,
00732                             UErrorCode& success) const;
00733 
00734     void             makeFormat(int32_t offsetNumber,
00735                                 UnicodeString* segments,
00736                                 UParseError& parseError,
00737                                 UErrorCode& success);
00738 
00742     NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
00743 
00753     static void copyAndFixQuotes(const UnicodeString& appendTo, int32_t start, int32_t end, UnicodeString& target);
00754 
00763     const Formattable::Type* getArgTypeList(int32_t& listCount) const {
00764         listCount = argTypeCount;
00765         return argTypes; 
00766     }
00767 
00768     friend class MessageFormatAdapter; // getFormatTypeList() access
00769 };
00770 
00771 inline UClassID
00772 MessageFormat::getStaticClassID(void)
00773 { return (UClassID)&fgClassID; }
00774 
00775 inline UClassID
00776 MessageFormat::getDynamicClassID() const
00777 { return MessageFormat::getStaticClassID(); }
00778 
00779 
00780 inline UnicodeString&
00781 MessageFormat::format(const Formattable& obj,
00782                       UnicodeString& appendTo,
00783                       UErrorCode& status) const {
00784     return Format::format(obj, appendTo, status);
00785 }
00786 U_NAMESPACE_END
00787 
00788 #endif /* #if !UCONFIG_NO_FORMATTING */
00789 
00790 #endif // _MSGFMT
00791 //eof

Generated on Wed Sep 3 17:47:09 2003 for ICU 2.6 by doxygen 1.3.2