ICU 4.8.1.1
4.8.1.1
|
00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-2011, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ******************************************************************************** 00006 * 00007 * File CHOICFMT.H 00008 * 00009 * Modification History: 00010 * 00011 * Date Name Description 00012 * 02/19/97 aliu Converted from java. 00013 * 03/20/97 helena Finished first cut of implementation and got rid 00014 * of nextDouble/previousDouble and replaced with 00015 * boolean array. 00016 * 4/10/97 aliu Clean up. Modified to work on AIX. 00017 * 8/6/97 nos Removed overloaded constructor, member var 'buffer'. 00018 * 07/22/98 stephen Removed operator!= (implemented in Format) 00019 ******************************************************************************** 00020 */ 00021 00022 #ifndef CHOICFMT_H 00023 #define CHOICFMT_H 00024 00025 #include "unicode/utypes.h" 00026 00032 #if !UCONFIG_NO_FORMATTING 00033 00034 #include "unicode/fieldpos.h" 00035 #include "unicode/format.h" 00036 #include "unicode/messagepattern.h" 00037 #include "unicode/numfmt.h" 00038 #include "unicode/unistr.h" 00039 00040 U_NAMESPACE_BEGIN 00041 00042 class MessageFormat; 00043 00168 class U_I18N_API ChoiceFormat: public NumberFormat { 00169 public: 00178 ChoiceFormat(const UnicodeString& pattern, 00179 UErrorCode& status); 00180 00181 00194 ChoiceFormat(const double* limits, 00195 const UnicodeString* formats, 00196 int32_t count ); 00197 00212 ChoiceFormat(const double* limits, 00213 const UBool* closures, 00214 const UnicodeString* formats, 00215 int32_t count); 00216 00223 ChoiceFormat(const ChoiceFormat& that); 00224 00231 const ChoiceFormat& operator=(const ChoiceFormat& that); 00232 00237 virtual ~ChoiceFormat(); 00238 00246 virtual Format* clone(void) const; 00247 00256 virtual UBool operator==(const Format& other) const; 00257 00266 virtual void applyPattern(const UnicodeString& pattern, 00267 UErrorCode& status); 00268 00279 virtual void applyPattern(const UnicodeString& pattern, 00280 UParseError& parseError, 00281 UErrorCode& status); 00290 virtual UnicodeString& toPattern(UnicodeString &pattern) const; 00291 00305 virtual void setChoices(const double* limitsToCopy, 00306 const UnicodeString* formatsToCopy, 00307 int32_t count ); 00308 00319 virtual void setChoices(const double* limits, 00320 const UBool* closures, 00321 const UnicodeString* formats, 00322 int32_t count); 00323 00332 virtual const double* getLimits(int32_t& count) const; 00333 00342 virtual const UBool* getClosures(int32_t& count) const; 00343 00352 virtual const UnicodeString* getFormats(int32_t& count) const; 00353 00354 00355 using NumberFormat::format; 00356 00368 virtual UnicodeString& format(double number, 00369 UnicodeString& appendTo, 00370 FieldPosition& pos) const; 00382 virtual UnicodeString& format(int32_t number, 00383 UnicodeString& appendTo, 00384 FieldPosition& pos) const; 00385 00397 virtual UnicodeString& format(int64_t number, 00398 UnicodeString& appendTo, 00399 FieldPosition& pos) const; 00400 00415 virtual UnicodeString& format(const Formattable* objs, 00416 int32_t cnt, 00417 UnicodeString& appendTo, 00418 FieldPosition& pos, 00419 UErrorCode& success) const; 00434 virtual UnicodeString& format(const Formattable& obj, 00435 UnicodeString& appendTo, 00436 FieldPosition& pos, 00437 UErrorCode& status) const; 00438 00450 UnicodeString& format(const Formattable& obj, 00451 UnicodeString& appendTo, 00452 UErrorCode& status) const; 00453 00465 UnicodeString& format( double number, 00466 UnicodeString& appendTo) const; 00467 00479 UnicodeString& format( int32_t number, 00480 UnicodeString& appendTo) const; 00481 00496 virtual void parse(const UnicodeString& text, 00497 Formattable& result, 00498 ParsePosition& parsePosition) const; 00499 00512 virtual void parse(const UnicodeString& text, 00513 Formattable& result, 00514 UErrorCode& status) const; 00515 00524 virtual UClassID getDynamicClassID(void) const; 00525 00537 static UClassID U_EXPORT2 getStaticClassID(void); 00538 00539 private: 00546 static UnicodeString& dtos(double value, UnicodeString& string); 00547 00548 ChoiceFormat(); // default constructor not implemented 00549 00561 ChoiceFormat(const UnicodeString& newPattern, 00562 UParseError& parseError, 00563 UErrorCode& status); 00564 00565 friend class MessageFormat; 00566 00567 virtual void setChoices(const double* limits, 00568 const UBool* closures, 00569 const UnicodeString* formats, 00570 int32_t count, 00571 UErrorCode &errorCode); 00572 00580 static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number); 00581 00582 static double parseArgument( 00583 const MessagePattern &pattern, int32_t partIndex, 00584 const UnicodeString &source, ParsePosition &pos); 00585 00594 static int32_t matchStringUntilLimitPart( 00595 const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex, 00596 const UnicodeString &source, int32_t sourceOffset); 00597 00604 UErrorCode constructorErrorCode; 00605 00613 MessagePattern msgPattern; 00614 00654 // double* fChoiceLimits; 00655 // UBool* fClosures; 00656 // UnicodeString* fChoiceFormats; 00657 // int32_t fCount; 00658 }; 00659 00660 inline UnicodeString& 00661 ChoiceFormat::format(const Formattable& obj, 00662 UnicodeString& appendTo, 00663 UErrorCode& status) const { 00664 // Don't use Format:: - use immediate base class only, 00665 // in case immediate base modifies behavior later. 00666 return NumberFormat::format(obj, appendTo, status); 00667 } 00668 00669 inline UnicodeString& 00670 ChoiceFormat::format(double number, 00671 UnicodeString& appendTo) const { 00672 return NumberFormat::format(number, appendTo); 00673 } 00674 00675 inline UnicodeString& 00676 ChoiceFormat::format(int32_t number, 00677 UnicodeString& appendTo) const { 00678 return NumberFormat::format(number, appendTo); 00679 } 00680 U_NAMESPACE_END 00681 00682 #endif /* #if !UCONFIG_NO_FORMATTING */ 00683 00684 #endif // _CHOICFMT 00685 //eof