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
00246 class U_I18N_API MessageFormat : public Format {
00247 public:
00253 enum EFormatNumber {
00259 kMaxFormat = 10
00260 };
00261
00271 MessageFormat(const UnicodeString& pattern,
00272 UErrorCode &status);
00273
00282 MessageFormat(const UnicodeString& pattern,
00283 const Locale& newLocale,
00284 UErrorCode& status);
00295 MessageFormat(const UnicodeString& pattern,
00296 const Locale& newLocale,
00297 UParseError& parseError,
00298 UErrorCode& status);
00303 MessageFormat(const MessageFormat&);
00304
00309 const MessageFormat& operator=(const MessageFormat&);
00310
00315 virtual ~MessageFormat();
00316
00322 virtual Format* clone(void) const;
00323
00331 virtual UBool operator==(const Format& other) const;
00332
00339 virtual void setLocale(const Locale& theLocale);
00340
00347 virtual const Locale& getLocale(void) const;
00348
00357 virtual void applyPattern(const UnicodeString& pattern,
00358 UErrorCode& status);
00369 virtual void applyPattern(const UnicodeString& pattern,
00370 UParseError& parseError,
00371 UErrorCode& status);
00372
00381 virtual UnicodeString& toPattern(UnicodeString& appendTo) const;
00382
00396 virtual void adoptFormats(Format** formatsToAdopt, int32_t count);
00397
00409 virtual void setFormats(const Format** newFormats,int32_t cnt);
00410
00411
00422 virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt);
00423
00433 virtual void setFormat(int32_t formatNumber, const Format& format);
00434
00446 virtual const Format** getFormats(int32_t& count) const;
00447
00462 UnicodeString& format( const Formattable* source,
00463 int32_t count,
00464 UnicodeString& appendTo,
00465 FieldPosition& ignore,
00466 UErrorCode& status) const;
00467
00482 static UnicodeString& format( const UnicodeString& pattern,
00483 const Formattable* arguments,
00484 int32_t count,
00485 UnicodeString& appendTo,
00486 UErrorCode& status);
00487
00505 virtual UnicodeString& format(const Formattable& obj,
00506 UnicodeString& appendTo,
00507 FieldPosition& pos,
00508 UErrorCode& status) const;
00509
00524 UnicodeString& format(const Formattable& obj,
00525 UnicodeString& appendTo,
00526 UErrorCode& status) const;
00527
00541 virtual Formattable* parse( const UnicodeString& source,
00542 ParsePosition& pos,
00543 int32_t& count) const;
00544
00556 virtual Formattable* parse( const UnicodeString& source,
00557 int32_t& count,
00558 UErrorCode& status) const;
00559
00572 virtual void parseObject(const UnicodeString& source,
00573 Formattable& result,
00574 ParsePosition& pos) const;
00575
00587 virtual UClassID getDynamicClassID(void) const;
00588
00600 static UClassID U_EXPORT2 getStaticClassID(void);
00601
00602 private:
00603
00604 Locale fLocale;
00605 UnicodeString fPattern;
00606 Format** formatAliases;
00607 int32_t formatAliasesCapacity;
00608
00609 MessageFormat();
00610
00611
00612
00613
00614
00615
00616
00617
00618 class Subformat {
00619 public:
00623 Format* format;
00627 int32_t offset;
00631 int32_t arg;
00632
00638 Subformat& operator=(const Subformat& that) {
00639 format = that.format ? that.format->clone() : NULL;
00640 offset = that.offset;
00641 arg = that.arg;
00642 return *this;
00643 }
00644
00648 UBool operator==(const Subformat& that) const {
00649
00650 return offset == that.offset &&
00651 arg == that.arg &&
00652 ((format == that.format) ||
00653 (*format == *that.format));
00654 }
00655
00659 UBool operator!=(const Subformat& that) const {
00660 return !operator==(that);
00661 }
00662 };
00663
00668 Subformat* subformats;
00669 int32_t subformatCount;
00670 int32_t subformatCapacity;
00671
00680 Formattable::Type* argTypes;
00681 int32_t argTypeCount;
00682 int32_t argTypeCapacity;
00683
00684
00685 UBool allocateSubformats(int32_t capacity);
00686 UBool allocateArgTypes(int32_t capacity);
00687
00695 NumberFormat* defaultNumberFormat;
00696 DateFormat* defaultDateFormat;
00697
00702 const NumberFormat* getDefaultNumberFormat(UErrorCode&) const;
00703 const DateFormat* getDefaultDateFormat(UErrorCode&) const;
00704
00711 static int32_t findKeyword( const UnicodeString& s,
00712 const UChar * const *list);
00713
00730 UnicodeString& format( const Formattable* arguments,
00731 int32_t cnt,
00732 UnicodeString& appendTo,
00733 FieldPosition& status,
00734 int32_t recursionProtection,
00735 UErrorCode& success) const;
00736
00737 void makeFormat(int32_t offsetNumber,
00738 UnicodeString* segments,
00739 UParseError& parseError,
00740 UErrorCode& success);
00741
00745 NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const;
00746
00756 static void copyAndFixQuotes(const UnicodeString& appendTo, int32_t start, int32_t end, UnicodeString& target);
00757
00766 const Formattable::Type* getArgTypeList(int32_t& listCount) const {
00767 listCount = argTypeCount;
00768 return argTypes;
00769 }
00770
00771 friend class MessageFormatAdapter;
00772 };
00773
00774 inline UnicodeString&
00775 MessageFormat::format(const Formattable& obj,
00776 UnicodeString& appendTo,
00777 UErrorCode& status) const {
00778 return Format::format(obj, appendTo, status);
00779 }
00780 U_NAMESPACE_END
00781
00782 #endif
00783
00784 #endif // _MSGFMT
00785
00786