ICU 50.1.2  50.1.2
choicfmt.h
Go to the documentation of this file.
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
6 *
7 * File CHOICFMT.H
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 02/19/97 aliu Converted from java.
13 * 03/20/97 helena Finished first cut of implementation and got rid
14 * of nextDouble/previousDouble and replaced with
15 * boolean array.
16 * 4/10/97 aliu Clean up. Modified to work on AIX.
17 * 8/6/97 nos Removed overloaded constructor, member var 'buffer'.
18 * 07/22/98 stephen Removed operator!= (implemented in Format)
19 ********************************************************************************
20 */
21 
22 #ifndef CHOICFMT_H
23 #define CHOICFMT_H
24 
25 #include "unicode/utypes.h"
26 
32 #if !UCONFIG_NO_FORMATTING
33 #ifndef U_HIDE_DEPRECATED_API
34 
35 #include "unicode/fieldpos.h"
36 #include "unicode/format.h"
37 #include "unicode/messagepattern.h"
38 #include "unicode/numfmt.h"
39 #include "unicode/unistr.h"
40 
42 
43 class MessageFormat;
44 
172 public:
181  ChoiceFormat(const UnicodeString& pattern,
182  UErrorCode& status);
183 
184 
197  ChoiceFormat(const double* limits,
198  const UnicodeString* formats,
199  int32_t count );
200 
215  ChoiceFormat(const double* limits,
216  const UBool* closures,
217  const UnicodeString* formats,
218  int32_t count);
219 
226  ChoiceFormat(const ChoiceFormat& that);
227 
234  const ChoiceFormat& operator=(const ChoiceFormat& that);
235 
240  virtual ~ChoiceFormat();
241 
249  virtual Format* clone(void) const;
250 
259  virtual UBool operator==(const Format& other) const;
260 
269  virtual void applyPattern(const UnicodeString& pattern,
270  UErrorCode& status);
271 
282  virtual void applyPattern(const UnicodeString& pattern,
283  UParseError& parseError,
284  UErrorCode& status);
293  virtual UnicodeString& toPattern(UnicodeString &pattern) const;
294 
308  virtual void setChoices(const double* limitsToCopy,
309  const UnicodeString* formatsToCopy,
310  int32_t count );
311 
322  virtual void setChoices(const double* limits,
323  const UBool* closures,
324  const UnicodeString* formats,
325  int32_t count);
326 
335  virtual const double* getLimits(int32_t& count) const;
336 
345  virtual const UBool* getClosures(int32_t& count) const;
346 
355  virtual const UnicodeString* getFormats(int32_t& count) const;
356 
357 
358  using NumberFormat::format;
359 
371  virtual UnicodeString& format(double number,
372  UnicodeString& appendTo,
373  FieldPosition& pos) const;
385  virtual UnicodeString& format(int32_t number,
386  UnicodeString& appendTo,
387  FieldPosition& pos) const;
388 
400  virtual UnicodeString& format(int64_t number,
401  UnicodeString& appendTo,
402  FieldPosition& pos) const;
403 
418  virtual UnicodeString& format(const Formattable* objs,
419  int32_t cnt,
420  UnicodeString& appendTo,
421  FieldPosition& pos,
422  UErrorCode& success) const;
437  virtual UnicodeString& format(const Formattable& obj,
438  UnicodeString& appendTo,
439  FieldPosition& pos,
440  UErrorCode& status) const;
441 
453  UnicodeString& format(const Formattable& obj,
454  UnicodeString& appendTo,
455  UErrorCode& status) const;
456 
468  UnicodeString& format( double number,
469  UnicodeString& appendTo) const;
470 
482  UnicodeString& format( int32_t number,
483  UnicodeString& appendTo) const;
484 
499  virtual void parse(const UnicodeString& text,
500  Formattable& result,
501  ParsePosition& parsePosition) const;
502 
515  virtual void parse(const UnicodeString& text,
516  Formattable& result,
517  UErrorCode& status) const;
518 
527  virtual UClassID getDynamicClassID(void) const;
528 
540  static UClassID U_EXPORT2 getStaticClassID(void);
541 
542 private:
549  static UnicodeString& dtos(double value, UnicodeString& string);
550 
551  ChoiceFormat(); // default constructor not implemented
552 
563  ChoiceFormat(const UnicodeString& newPattern,
564  UParseError& parseError,
565  UErrorCode& status);
566 
567  friend class MessageFormat;
568 
569  virtual void setChoices(const double* limits,
570  const UBool* closures,
571  const UnicodeString* formats,
572  int32_t count,
573  UErrorCode &errorCode);
574 
582  static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
583 
584  static double parseArgument(
585  const MessagePattern &pattern, int32_t partIndex,
586  const UnicodeString &source, ParsePosition &pos);
587 
596  static int32_t matchStringUntilLimitPart(
597  const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
598  const UnicodeString &source, int32_t sourceOffset);
599 
606  UErrorCode constructorErrorCode;
607 
615  MessagePattern msgPattern;
616 
656  // double* fChoiceLimits;
657  // UBool* fClosures;
658  // UnicodeString* fChoiceFormats;
659  // int32_t fCount;
660 };
661 
662 inline UnicodeString&
663 ChoiceFormat::format(const Formattable& obj,
664  UnicodeString& appendTo,
665  UErrorCode& status) const {
666  // Don't use Format:: - use immediate base class only,
667  // in case immediate base modifies behavior later.
668  return NumberFormat::format(obj, appendTo, status);
669 }
670 
671 inline UnicodeString&
672 ChoiceFormat::format(double number,
673  UnicodeString& appendTo) const {
674  return NumberFormat::format(number, appendTo);
675 }
676 
677 inline UnicodeString&
678 ChoiceFormat::format(int32_t number,
679  UnicodeString& appendTo) const {
680  return NumberFormat::format(number, appendTo);
681 }
683 
684 #endif // U_HIDE_DEPRECATED_API
685 #endif /* #if !UCONFIG_NO_FORMATTING */
686 
687 #endif // CHOICFMT_H
688 //eof
Base class for all formats.
Definition: format.h:94
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
Abstract base class for all number formats.
Definition: numfmt.h:166
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
virtual Format * clone() const =0
Clone this object polymorphically.
C++ API: Base class for all formats.
Parses and represents ICU MessageFormat patterns.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
C++ API: FieldPosition identifies the fields in a formatted output.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
static UClassID getStaticClassID(void)
Return the class ID for this class.
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
ChoiceFormat converts between ranges of numeric values and strings for those ranges.
Definition: choicfmt.h:171
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
C++ API: Abstract base class for all number formats.
NumberFormat & operator=(const NumberFormat &)
Assignment operator.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200