00001 /* 00002 * Copyright © {1997-1999}, 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 ******************************************************************************** 00014 */ 00015 // ***************************************************************************** 00016 // This file was generated from the java source file MessageFormat.java 00017 // ***************************************************************************** 00018 00019 #ifndef MSGFMT_H 00020 #define MSGFMT_H 00021 00022 #include "unicode/utypes.h" 00023 #include "unicode/format.h" 00024 #include "unicode/locid.h" 00025 class NumberFormat; 00026 00176 class U_I18N_API MessageFormat : public Format { 00177 public: 00178 enum EFormatNumber { kMaxFormat = 10 }; 00187 MessageFormat(const UnicodeString& pattern, 00188 UErrorCode &status); 00189 00198 MessageFormat(const UnicodeString& pattern, 00199 const Locale& newLocale, 00200 UErrorCode& success); 00201 00206 MessageFormat(const MessageFormat&); 00207 00212 const MessageFormat& operator=(const MessageFormat&); 00213 00218 virtual ~MessageFormat(); 00219 00225 virtual Format* clone(void) const; 00226 00232 virtual UBool operator==(const Format& other) const; 00233 00239 virtual void setLocale(const Locale& theLocale); 00240 00246 virtual const Locale& getLocale(void) const; 00247 00257 virtual void applyPattern(const UnicodeString& pattern, 00258 UErrorCode& status); 00259 00264 virtual UnicodeString& toPattern(UnicodeString& result) const; 00265 00272 virtual void adoptFormats(Format** formatsToAdopt, int32_t count); 00273 00279 virtual void setFormats(const Format** newFormats,int32_t cnt); 00280 00281 00288 virtual void adoptFormat(int32_t formatNumber, Format* formatToAdopt); 00289 00295 virtual void setFormat(int32_t variable, const Format& newFormat); 00296 00297 00303 virtual const Format** getFormats(int32_t& count) const; 00304 00315 UnicodeString& format( const Formattable* source, 00316 int32_t count, 00317 UnicodeString& result, 00318 FieldPosition& ignore, 00319 UErrorCode& success) const; 00320 00326 static UnicodeString& format( const UnicodeString& pattern, 00327 const Formattable* arguments, 00328 int32_t count, 00329 UnicodeString& result, 00330 UErrorCode& success); 00331 00347 virtual UnicodeString& format(const Formattable& obj, 00348 UnicodeString& toAppendTo, 00349 FieldPosition& pos, 00350 UErrorCode& status) const; 00351 00356 UnicodeString& format(const Formattable& obj, 00357 UnicodeString& result, 00358 UErrorCode& status) const; 00359 00391 virtual Formattable* parse( const UnicodeString& source, 00392 ParsePosition& status, 00393 int32_t& count) const; 00394 00406 virtual Formattable* parse( const UnicodeString& source, 00407 int32_t& count, 00408 UErrorCode& status) const; 00409 00439 virtual void parseObject(const UnicodeString& source, 00440 Formattable& result, 00441 ParsePosition& parse_pos) const; 00442 00443 public: 00455 virtual UClassID getDynamicClassID(void) const; 00456 00468 static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } 00469 00470 private: 00471 static char fgClassID; 00472 static NumberFormat* fgNumberFormat; 00473 00474 // fgNumberFormat is held in a cache of one. 00475 00476 static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache. 00477 static void releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache. 00478 00479 Locale fLocale; 00480 UnicodeString fPattern; 00481 // later, allow more than ten items 00482 Format *fFormats[kMaxFormat]; 00483 int32_t *fOffsets; 00484 int32_t fCount; 00485 int32_t *fArgumentNumbers; 00486 int32_t fMaxOffset; 00487 00494 static const int32_t fgListLength; 00495 static const UnicodeString fgTypeList[]; 00496 static const UnicodeString fgModifierList[]; 00497 static const UnicodeString fgDateModifierList[]; 00498 00505 static int32_t findKeyword( const UnicodeString& s, 00506 const UnicodeString* list); 00507 00519 UnicodeString& format( const Formattable* arguments, 00520 int32_t cnt, 00521 UnicodeString& result, 00522 FieldPosition& status, 00523 int32_t recursionProtection, 00524 UErrorCode& success) const; 00525 00534 void makeFormat( /*int32_t position, */ 00535 int32_t offsetNumber, 00536 UnicodeString* segments, 00537 UErrorCode& success); 00538 00542 NumberFormat* createIntegerFormat(const Locale& locale, UErrorCode& status) const; 00543 00552 static void copyAndFixQuotes(const UnicodeString& source, int32_t start, int32_t end, UnicodeString& target); 00553 00562 static int32_t stoi(const UnicodeString& string, UErrorCode& status); 00563 00572 static UnicodeString& itos(int32_t i, UnicodeString& string); 00573 }; 00574 00575 inline UClassID 00576 MessageFormat::getDynamicClassID() const 00577 { 00578 return MessageFormat::getStaticClassID(); 00579 } 00580 00581 inline UnicodeString& 00582 MessageFormat::format(const Formattable& obj, 00583 UnicodeString& result, 00584 UErrorCode& status) const { 00585 return Format::format(obj, result, status); 00586 } 00587 00588 #endif // _MSGFMT 00589 //eof