00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CHOICFMT_H
00023 #define CHOICFMT_H
00024
00025 #include "unicode/utypes.h"
00026
00032 #if !UCONFIG_NO_FORMATTING
00033 #ifndef U_HIDE_DEPRECATED_API
00034
00035 #include "unicode/fieldpos.h"
00036 #include "unicode/format.h"
00037 #include "unicode/messagepattern.h"
00038 #include "unicode/numfmt.h"
00039 #include "unicode/unistr.h"
00040
00041 U_NAMESPACE_BEGIN
00042
00043 class MessageFormat;
00044
00171 class U_I18N_API ChoiceFormat: public NumberFormat {
00172 public:
00181 ChoiceFormat(const UnicodeString& pattern,
00182 UErrorCode& status);
00183
00184
00197 ChoiceFormat(const double* limits,
00198 const UnicodeString* formats,
00199 int32_t count );
00200
00215 ChoiceFormat(const double* limits,
00216 const UBool* closures,
00217 const UnicodeString* formats,
00218 int32_t count);
00219
00226 ChoiceFormat(const ChoiceFormat& that);
00227
00234 const ChoiceFormat& operator=(const ChoiceFormat& that);
00235
00240 virtual ~ChoiceFormat();
00241
00249 virtual Format* clone(void) const;
00250
00259 virtual UBool operator==(const Format& other) const;
00260
00269 virtual void applyPattern(const UnicodeString& pattern,
00270 UErrorCode& status);
00271
00282 virtual void applyPattern(const UnicodeString& pattern,
00283 UParseError& parseError,
00284 UErrorCode& status);
00293 virtual UnicodeString& toPattern(UnicodeString &pattern) const;
00294
00308 virtual void setChoices(const double* limitsToCopy,
00309 const UnicodeString* formatsToCopy,
00310 int32_t count );
00311
00322 virtual void setChoices(const double* limits,
00323 const UBool* closures,
00324 const UnicodeString* formats,
00325 int32_t count);
00326
00335 virtual const double* getLimits(int32_t& count) const;
00336
00345 virtual const UBool* getClosures(int32_t& count) const;
00346
00355 virtual const UnicodeString* getFormats(int32_t& count) const;
00356
00357
00358 using NumberFormat::format;
00359
00371 virtual UnicodeString& format(double number,
00372 UnicodeString& appendTo,
00373 FieldPosition& pos) const;
00385 virtual UnicodeString& format(int32_t number,
00386 UnicodeString& appendTo,
00387 FieldPosition& pos) const;
00388
00400 virtual UnicodeString& format(int64_t number,
00401 UnicodeString& appendTo,
00402 FieldPosition& pos) const;
00403
00418 virtual UnicodeString& format(const Formattable* objs,
00419 int32_t cnt,
00420 UnicodeString& appendTo,
00421 FieldPosition& pos,
00422 UErrorCode& success) const;
00423
00424 using NumberFormat::parse;
00425
00440 virtual void parse(const UnicodeString& text,
00441 Formattable& result,
00442 ParsePosition& parsePosition) const;
00443
00452 virtual UClassID getDynamicClassID(void) const;
00453
00465 static UClassID U_EXPORT2 getStaticClassID(void);
00466
00467 private:
00474 static UnicodeString& dtos(double value, UnicodeString& string);
00475
00476 ChoiceFormat();
00477
00488 ChoiceFormat(const UnicodeString& newPattern,
00489 UParseError& parseError,
00490 UErrorCode& status);
00491
00492 friend class MessageFormat;
00493
00494 virtual void setChoices(const double* limits,
00495 const UBool* closures,
00496 const UnicodeString* formats,
00497 int32_t count,
00498 UErrorCode &errorCode);
00499
00507 static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
00508
00509 static double parseArgument(
00510 const MessagePattern &pattern, int32_t partIndex,
00511 const UnicodeString &source, ParsePosition &pos);
00512
00521 static int32_t matchStringUntilLimitPart(
00522 const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
00523 const UnicodeString &source, int32_t sourceOffset);
00524
00531 UErrorCode constructorErrorCode;
00532
00540 MessagePattern msgPattern;
00541
00581
00582
00583
00584
00585 };
00586
00587
00588 U_NAMESPACE_END
00589
00590 #endif // U_HIDE_DEPRECATED_API
00591 #endif
00592
00593 #endif // CHOICFMT_H
00594