00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef CHOICFMT_H
00025 #define CHOICFMT_H
00026
00027 #include "unicode/utypes.h"
00028
00034 #if !UCONFIG_NO_FORMATTING
00035 #ifndef U_HIDE_DEPRECATED_API
00036
00037 #include "unicode/fieldpos.h"
00038 #include "unicode/format.h"
00039 #include "unicode/messagepattern.h"
00040 #include "unicode/numfmt.h"
00041 #include "unicode/unistr.h"
00042
00043 U_NAMESPACE_BEGIN
00044
00045 class MessageFormat;
00046
00173 class U_I18N_API ChoiceFormat: public NumberFormat {
00174 public:
00183 ChoiceFormat(const UnicodeString& pattern,
00184 UErrorCode& status);
00185
00186
00199 ChoiceFormat(const double* limits,
00200 const UnicodeString* formats,
00201 int32_t count );
00202
00217 ChoiceFormat(const double* limits,
00218 const UBool* closures,
00219 const UnicodeString* formats,
00220 int32_t count);
00221
00228 ChoiceFormat(const ChoiceFormat& that);
00229
00236 const ChoiceFormat& operator=(const ChoiceFormat& that);
00237
00242 virtual ~ChoiceFormat();
00243
00251 virtual Format* clone(void) const;
00252
00261 virtual UBool operator==(const Format& other) const;
00262
00271 virtual void applyPattern(const UnicodeString& pattern,
00272 UErrorCode& status);
00273
00284 virtual void applyPattern(const UnicodeString& pattern,
00285 UParseError& parseError,
00286 UErrorCode& status);
00295 virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00296
00310 virtual void setChoices(const double* limitsToCopy,
00311 const UnicodeString* formatsToCopy,
00312 int32_t count );
00313
00324 virtual void setChoices(const double* limits,
00325 const UBool* closures,
00326 const UnicodeString* formats,
00327 int32_t count);
00328
00337 virtual const double* getLimits(int32_t& count) const;
00338
00347 virtual const UBool* getClosures(int32_t& count) const;
00348
00357 virtual const UnicodeString* getFormats(int32_t& count) const;
00358
00359
00360 using NumberFormat::format;
00361
00373 virtual UnicodeString& format(double number,
00374 UnicodeString& appendTo,
00375 FieldPosition& pos) const;
00387 virtual UnicodeString& format(int32_t number,
00388 UnicodeString& appendTo,
00389 FieldPosition& pos) const;
00390
00402 virtual UnicodeString& format(int64_t number,
00403 UnicodeString& appendTo,
00404 FieldPosition& pos) const;
00405
00420 virtual UnicodeString& format(const Formattable* objs,
00421 int32_t cnt,
00422 UnicodeString& appendTo,
00423 FieldPosition& pos,
00424 UErrorCode& success) const;
00425
00426 using NumberFormat::parse;
00427
00442 virtual void parse(const UnicodeString& text,
00443 Formattable& result,
00444 ParsePosition& parsePosition) const;
00445
00454 virtual UClassID getDynamicClassID(void) const;
00455
00467 static UClassID U_EXPORT2 getStaticClassID(void);
00468
00469 private:
00476 static UnicodeString& dtos(double value, UnicodeString& string);
00477
00478 ChoiceFormat();
00479
00490 ChoiceFormat(const UnicodeString& newPattern,
00491 UParseError& parseError,
00492 UErrorCode& status);
00493
00494 friend class MessageFormat;
00495
00496 virtual void setChoices(const double* limits,
00497 const UBool* closures,
00498 const UnicodeString* formats,
00499 int32_t count,
00500 UErrorCode &errorCode);
00501
00509 static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
00510
00511 static double parseArgument(
00512 const MessagePattern &pattern, int32_t partIndex,
00513 const UnicodeString &source, ParsePosition &pos);
00514
00523 static int32_t matchStringUntilLimitPart(
00524 const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
00525 const UnicodeString &source, int32_t sourceOffset);
00526
00533 UErrorCode constructorErrorCode;
00534
00542 MessagePattern msgPattern;
00543
00583
00584
00585
00586
00587 };
00588
00589
00590 U_NAMESPACE_END
00591
00592 #endif // U_HIDE_DEPRECATED_API
00593 #endif
00594
00595 #endif // CHOICFMT_H
00596