00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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 UClassID getStaticClassID(void);
00597
00606 virtual Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
00607
00616 virtual const char* getLocaleInternal(ULocDataLocaleType type, UErrorCode &status) const;
00617
00618 private:
00619
00620 Locale fLocale;
00621 UnicodeString fPattern;
00622 Format** formatAliases;
00623 int32_t formatAliasesCapacity;
00624
00625 MessageFormat();
00626
00634 class Subformat {
00635 public:
00639 Format* format;
00643 int32_t offset;
00647 int32_t arg;
00648
00654 Subformat& operator=(const Subformat& that) {
00655 format = that.format ? that.format->clone() : NULL;
00656 offset = that.offset;
00657 arg = that.arg;
00658 return *this;
00659 }
00660
00664 UBool operator==(const Subformat& that) const {
00665
00666 return offset == that.offset &&
00667 arg == that.arg &&
00668 ((format == that.format) ||
00669 (*format == *that.format));
00670 }
00671
00675 UBool operator!=(const Subformat& that) const {
00676 return !operator==(that);
00677 }
00678 };
00679
00684 Subformat* subformats;
00685 int32_t subformatCount;
00686 int32_t subformatCapacity;
00687
00696 Formattable::Type* argTypes;
00697 int32_t argTypeCount;
00698 int32_t argTypeCapacity;
00699
00700
00701 UBool allocateSubformats(int32_t capacity);
00702 UBool allocateArgTypes(int32_t capacity);
00703
00711 NumberFormat* defaultNumberFormat;
00712 DateFormat* defaultDateFormat;
00713
00718 const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
00719 const DateFormat* getDefaultDateFormat(UErrorCode&) const;
00720
00727 static int32_t findKeyword( const UnicodeString& s,
00728 const UChar * const *list);
00729
00746 UnicodeString& format( const Formattable* arguments,
00747 int32_t cnt,
00748 UnicodeString& appendTo,
00749 FieldPosition& status,
00750 int32_t recursionProtection,
00751 UErrorCode& success) const;
00752
00753 void makeFormat(int32_t offsetNumber,
00754 UnicodeString* segments,
00755 UParseError& parseError,
00756 UErrorCode& success);
00757
00761 NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
00762
00772 static void copyAndFixQuotes(const UnicodeString& appendTo, int32_t start, int32_t end, UnicodeString& target);
00773
00782 const Formattable::Type* getArgTypeList(int32_t& listCount) const {
00783 listCount = argTypeCount;
00784 return argTypes;
00785 }
00786
00787 friend class MessageFormatAdapter;
00788 };
00789
00790 inline UnicodeString&
00791 MessageFormat::format(const Formattable& obj,
00792 UnicodeString& appendTo,
00793 UErrorCode& status) const {
00794 return Format::format(obj, appendTo, status);
00795 }
00796 U_NAMESPACE_END
00797
00798 #endif
00799
00800 #endif // _MSGFMT
00801