ICU 65.1  65.1
choicfmt.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ********************************************************************************
5 * Copyright (C) 1997-2013, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
8 *
9 * File CHOICFMT.H
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 02/19/97 aliu Converted from java.
15 * 03/20/97 helena Finished first cut of implementation and got rid
16 * of nextDouble/previousDouble and replaced with
17 * boolean array.
18 * 4/10/97 aliu Clean up. Modified to work on AIX.
19 * 8/6/97 nos Removed overloaded constructor, member var 'buffer'.
20 * 07/22/98 stephen Removed operator!= (implemented in Format)
21 ********************************************************************************
22 */
23 
24 #ifndef CHOICFMT_H
25 #define CHOICFMT_H
26 
27 #include "unicode/utypes.h"
28 
29 #if U_SHOW_CPLUSPLUS_API
30 
36 #if !UCONFIG_NO_FORMATTING
37 #ifndef U_HIDE_DEPRECATED_API
38 
39 #include "unicode/fieldpos.h"
40 #include "unicode/format.h"
41 #include "unicode/messagepattern.h"
42 #include "unicode/numfmt.h"
43 #include "unicode/unistr.h"
44 
45 U_NAMESPACE_BEGIN
46 
47 class MessageFormat;
48 
176 public:
185  ChoiceFormat(const UnicodeString& pattern,
186  UErrorCode& status);
187 
188 
201  ChoiceFormat(const double* limits,
202  const UnicodeString* formats,
203  int32_t count );
204 
219  ChoiceFormat(const double* limits,
220  const UBool* closures,
221  const UnicodeString* formats,
222  int32_t count);
223 
230  ChoiceFormat(const ChoiceFormat& that);
231 
238  const ChoiceFormat& operator=(const ChoiceFormat& that);
239 
244  virtual ~ChoiceFormat();
245 
253  virtual ChoiceFormat* clone() const;
254 
263  virtual UBool operator==(const Format& other) const;
264 
273  virtual void applyPattern(const UnicodeString& pattern,
274  UErrorCode& status);
275 
286  virtual void applyPattern(const UnicodeString& pattern,
287  UParseError& parseError,
288  UErrorCode& status);
297  virtual UnicodeString& toPattern(UnicodeString &pattern) const;
298 
312  virtual void setChoices(const double* limitsToCopy,
313  const UnicodeString* formatsToCopy,
314  int32_t count );
315 
326  virtual void setChoices(const double* limits,
327  const UBool* closures,
328  const UnicodeString* formats,
329  int32_t count);
330 
339  virtual const double* getLimits(int32_t& count) const;
340 
349  virtual const UBool* getClosures(int32_t& count) const;
350 
359  virtual const UnicodeString* getFormats(int32_t& count) const;
360 
361 
362  using NumberFormat::format;
363 
375  virtual UnicodeString& format(double number,
376  UnicodeString& appendTo,
377  FieldPosition& pos) const;
389  virtual UnicodeString& format(int32_t number,
390  UnicodeString& appendTo,
391  FieldPosition& pos) const;
392 
404  virtual UnicodeString& format(int64_t number,
405  UnicodeString& appendTo,
406  FieldPosition& pos) const;
407 
422  virtual UnicodeString& format(const Formattable* objs,
423  int32_t cnt,
424  UnicodeString& appendTo,
425  FieldPosition& pos,
426  UErrorCode& success) const;
427 
428  using NumberFormat::parse;
429 
444  virtual void parse(const UnicodeString& text,
445  Formattable& result,
446  ParsePosition& parsePosition) const;
447 
456  virtual UClassID getDynamicClassID(void) const;
457 
469  static UClassID U_EXPORT2 getStaticClassID(void);
470 
471 private:
478  static UnicodeString& dtos(double value, UnicodeString& string);
479 
480  ChoiceFormat(); // default constructor not implemented
481 
492  ChoiceFormat(const UnicodeString& newPattern,
493  UParseError& parseError,
494  UErrorCode& status);
495 
496  friend class MessageFormat;
497 
498  virtual void setChoices(const double* limits,
499  const UBool* closures,
500  const UnicodeString* formats,
501  int32_t count,
502  UErrorCode &errorCode);
503 
511  static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
512 
513  static double parseArgument(
514  const MessagePattern &pattern, int32_t partIndex,
515  const UnicodeString &source, ParsePosition &pos);
516 
525  static int32_t matchStringUntilLimitPart(
526  const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
527  const UnicodeString &source, int32_t sourceOffset);
528 
535  UErrorCode constructorErrorCode;
536 
544  MessagePattern msgPattern;
545 
585  // double* fChoiceLimits;
586  // UBool* fClosures;
587  // UnicodeString* fChoiceFormats;
588  // int32_t fCount;
589 };
590 
591 
592 U_NAMESPACE_END
593 
594 #endif // U_HIDE_DEPRECATED_API
595 #endif /* #if !UCONFIG_NO_FORMATTING */
596 
597 #endif /* U_SHOW_CPLUSPLUS_API */
598 
599 #endif // CHOICFMT_H
600 //eof
Base class for all formats.
Definition: format.h:98
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
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
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:301
C++ API: FieldPosition identifies the fields in a formatted output.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
virtual NumberFormat * clone() const =0
Clones this object polymorphically.
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:110
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
ChoiceFormat converts between ranges of numeric values and strings for those ranges.
Definition: choicfmt.h:175
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
Basic definitions for ICU, for both C and C++ APIs.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
C++ API: Compatibility APIs for number formatting.
NumberFormat & operator=(const NumberFormat &)
Assignment operator.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:260