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
00029 #if U_SHOW_CPLUSPLUS_API
00030
00036 #if !UCONFIG_NO_FORMATTING
00037
00038 #include "unicode/fieldpos.h"
00039 #include "unicode/format.h"
00040 #include "unicode/messagepattern.h"
00041 #include "unicode/numfmt.h"
00042 #include "unicode/unistr.h"
00043
00044 #ifndef U_HIDE_DEPRECATED_API
00045
00046 U_NAMESPACE_BEGIN
00047
00048 class MessageFormat;
00049
00176 class U_I18N_API ChoiceFormat: public NumberFormat {
00177 public:
00186 ChoiceFormat(const UnicodeString& pattern,
00187 UErrorCode& status);
00188
00189
00202 ChoiceFormat(const double* limits,
00203 const UnicodeString* formats,
00204 int32_t count );
00205
00220 ChoiceFormat(const double* limits,
00221 const UBool* closures,
00222 const UnicodeString* formats,
00223 int32_t count);
00224
00231 ChoiceFormat(const ChoiceFormat& that);
00232
00239 const ChoiceFormat& operator=(const ChoiceFormat& that);
00240
00245 virtual ~ChoiceFormat();
00246
00254 virtual ChoiceFormat* clone() const;
00255
00264 virtual UBool operator==(const Format& other) const;
00265
00274 virtual void applyPattern(const UnicodeString& pattern,
00275 UErrorCode& status);
00276
00287 virtual void applyPattern(const UnicodeString& pattern,
00288 UParseError& parseError,
00289 UErrorCode& status);
00298 virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00299
00313 virtual void setChoices(const double* limitsToCopy,
00314 const UnicodeString* formatsToCopy,
00315 int32_t count );
00316
00327 virtual void setChoices(const double* limits,
00328 const UBool* closures,
00329 const UnicodeString* formats,
00330 int32_t count);
00331
00340 virtual const double* getLimits(int32_t& count) const;
00341
00350 virtual const UBool* getClosures(int32_t& count) const;
00351
00360 virtual const UnicodeString* getFormats(int32_t& count) const;
00361
00362
00363 using NumberFormat::format;
00364
00376 virtual UnicodeString& format(double number,
00377 UnicodeString& appendTo,
00378 FieldPosition& pos) const;
00390 virtual UnicodeString& format(int32_t number,
00391 UnicodeString& appendTo,
00392 FieldPosition& pos) const;
00393
00405 virtual UnicodeString& format(int64_t number,
00406 UnicodeString& appendTo,
00407 FieldPosition& pos) const;
00408
00423 virtual UnicodeString& format(const Formattable* objs,
00424 int32_t cnt,
00425 UnicodeString& appendTo,
00426 FieldPosition& pos,
00427 UErrorCode& success) const;
00428
00429 using NumberFormat::parse;
00430
00445 virtual void parse(const UnicodeString& text,
00446 Formattable& result,
00447 ParsePosition& parsePosition) const;
00448
00457 virtual UClassID getDynamicClassID(void) const;
00458
00470 static UClassID U_EXPORT2 getStaticClassID(void);
00471
00472 private:
00479 static UnicodeString& dtos(double value, UnicodeString& string);
00480
00481 ChoiceFormat();
00482
00493 ChoiceFormat(const UnicodeString& newPattern,
00494 UParseError& parseError,
00495 UErrorCode& status);
00496
00497 friend class MessageFormat;
00498
00499 virtual void setChoices(const double* limits,
00500 const UBool* closures,
00501 const UnicodeString* formats,
00502 int32_t count,
00503 UErrorCode &errorCode);
00504
00512 static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
00513
00514 static double parseArgument(
00515 const MessagePattern &pattern, int32_t partIndex,
00516 const UnicodeString &source, ParsePosition &pos);
00517
00526 static int32_t matchStringUntilLimitPart(
00527 const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
00528 const UnicodeString &source, int32_t sourceOffset);
00529
00536 UErrorCode constructorErrorCode;
00537
00545 MessagePattern msgPattern;
00546
00586
00587
00588
00589
00590 };
00591
00592
00593 U_NAMESPACE_END
00594
00595 #endif // U_HIDE_DEPRECATED_API
00596 #endif
00597
00598 #endif
00599
00600 #endif // CHOICFMT_H
00601