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 UClassID getStaticClassID(void); 00597 00598 private: 00599 00600 Locale fLocale; 00601 UnicodeString fPattern; 00602 Format** formatAliases; // see getFormats 00603 int32_t formatAliasesCapacity; 00604 00605 MessageFormat(); // default constructor not implemented 00606 00607 /* 00608 * A structure representing one subformat of this MessageFormat. 00609 * Each subformat has a Format object, an offset into the plain 00610 * pattern text fPattern, and an argument number. The argument 00611 * number corresponds to the array of arguments to be formatted. 00612 * @internal 00613 */ 00614 class Subformat { 00615 public: 00619 Format* format; // formatter 00623 int32_t offset; // offset into fPattern 00627 int32_t arg; // 0-based argument number 00628 00634 Subformat& operator=(const Subformat& that) { 00635 format = that.format ? that.format->clone() : NULL; 00636 offset = that.offset; 00637 arg = that.arg; 00638 return *this; 00639 } 00640 00644 UBool operator==(const Subformat& that) const { 00645 // Do cheap comparisons first 00646 return offset == that.offset && 00647 arg == that.arg && 00648 ((format == that.format) || // handles NULL 00649 (*format == *that.format)); 00650 } 00651 00655 UBool operator!=(const Subformat& that) const { 00656 return !operator==(that); 00657 } 00658 }; 00659 00664 Subformat* subformats; 00665 int32_t subformatCount; 00666 int32_t subformatCapacity; 00667 00676 Formattable::Type* argTypes; 00677 int32_t argTypeCount; 00678 int32_t argTypeCapacity; 00679 00680 // Variable-size array management 00681 UBool allocateSubformats(int32_t capacity); 00682 UBool allocateArgTypes(int32_t capacity); 00683 00691 NumberFormat* defaultNumberFormat; 00692 DateFormat* defaultDateFormat; 00693 00698 const NumberFormat* getDefaultNumberFormat(UErrorCode&) const; 00699 const DateFormat* getDefaultDateFormat(UErrorCode&) const; 00700 00707 static int32_t findKeyword( const UnicodeString& s, 00708 const UChar * const *list); 00709 00726 UnicodeString& format( const Formattable* arguments, 00727 int32_t cnt, 00728 UnicodeString& appendTo, 00729 FieldPosition& status, 00730 int32_t recursionProtection, 00731 UErrorCode& success) const; 00732 00733 void makeFormat(int32_t offsetNumber, 00734 UnicodeString* segments, 00735 UParseError& parseError, 00736 UErrorCode& success); 00737 00741 NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const; 00742 00752 static void copyAndFixQuotes(const UnicodeString& appendTo, int32_t start, int32_t end, UnicodeString& target); 00753 00762 const Formattable::Type* getArgTypeList(int32_t& listCount) const { 00763 listCount = argTypeCount; 00764 return argTypes; 00765 } 00766 00767 friend class MessageFormatAdapter; // getFormatTypeList() access 00768 }; 00769 00770 inline UnicodeString& 00771 MessageFormat::format(const Formattable& obj, 00772 UnicodeString& appendTo, 00773 UErrorCode& status) const { 00774 return Format::format(obj, appendTo, status); 00775 } 00776 U_NAMESPACE_END 00777 00778 #endif /* #if !UCONFIG_NO_FORMATTING */ 00779 00780 #endif // _MSGFMT 00781 //eof 00782

Generated on Wed Sep 15 17:18:09 2004 for ICU 2.8 by doxygen 1.3.8