ICU 63.1  63.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 
34 #if !UCONFIG_NO_FORMATTING
35 #ifndef U_HIDE_DEPRECATED_API
36 
37 #include "unicode/fieldpos.h"
38 #include "unicode/format.h"
39 #include "unicode/messagepattern.h"
40 #include "unicode/numfmt.h"
41 #include "unicode/unistr.h"
42 
44 
45 class MessageFormat;
46 
174 public:
183  ChoiceFormat(const UnicodeString& pattern,
184  UErrorCode& status);
185 
186 
199  ChoiceFormat(const double* limits,
200  const UnicodeString* formats,
201  int32_t count );
202 
217  ChoiceFormat(const double* limits,
218  const UBool* closures,
219  const UnicodeString* formats,
220  int32_t count);
221 
229 
236  const ChoiceFormat& operator=(const ChoiceFormat& that);
237 
242  virtual ~ChoiceFormat();
243 
251  virtual Format* clone(void) const;
252 
261  virtual UBool operator==(const Format& other) const;
262 
271  virtual void applyPattern(const UnicodeString& pattern,
272  UErrorCode& status);
273 
284  virtual void applyPattern(const UnicodeString& pattern,
285  UParseError& parseError,
286  UErrorCode& status);
295  virtual UnicodeString& toPattern(UnicodeString &pattern) const;
296 
310  virtual void setChoices(const double* limitsToCopy,
311  const UnicodeString* formatsToCopy,
312  int32_t count );
313 
324  virtual void setChoices(const double* limits,
325  const UBool* closures,
326  const UnicodeString* formats,
327  int32_t count);
328 
337  virtual const double* getLimits(int32_t& count) const;
338 
347  virtual const UBool* getClosures(int32_t& count) const;
348 
357  virtual const UnicodeString* getFormats(int32_t& count) const;
358 
359 
360  using NumberFormat::format;
361 
373  virtual UnicodeString& format(double number,
374  UnicodeString& appendTo,
375  FieldPosition& pos) const;
387  virtual UnicodeString& format(int32_t number,
388  UnicodeString& appendTo,
389  FieldPosition& pos) const;
390 
402  virtual UnicodeString& format(int64_t number,
403  UnicodeString& appendTo,
404  FieldPosition& pos) const;
405 
420  virtual UnicodeString& format(const Formattable* objs,
421  int32_t cnt,
422  UnicodeString& appendTo,
423  FieldPosition& pos,
424  UErrorCode& success) const;
425 
426  using NumberFormat::parse;
427 
442  virtual void parse(const UnicodeString& text,
443  Formattable& result,
444  ParsePosition& parsePosition) const;
445 
454  virtual UClassID getDynamicClassID(void) const;
455 
467  static UClassID U_EXPORT2 getStaticClassID(void);
468 
469 private:
476  static UnicodeString& dtos(double value, UnicodeString& string);
477 
478  ChoiceFormat(); // default constructor not implemented
479 
490  ChoiceFormat(const UnicodeString& newPattern,
491  UParseError& parseError,
492  UErrorCode& status);
493 
494  friend class MessageFormat;
495 
496  virtual void setChoices(const double* limits,
497  const UBool* closures,
498  const UnicodeString* formats,
499  int32_t count,
500  UErrorCode &errorCode);
501 
509  static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
510 
511  static double parseArgument(
512  const MessagePattern &pattern, int32_t partIndex,
513  const UnicodeString &source, ParsePosition &pos);
514 
523  static int32_t matchStringUntilLimitPart(
524  const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
525  const UnicodeString &source, int32_t sourceOffset);
526 
533  UErrorCode constructorErrorCode;
534 
542  MessagePattern msgPattern;
543 
583  // double* fChoiceLimits;
584  // UBool* fClosures;
585  // UnicodeString* fChoiceFormats;
586  // int32_t fCount;
587 };
588 
589 
591 
592 #endif // U_HIDE_DEPRECATED_API
593 #endif /* #if !UCONFIG_NO_FORMATTING */
594 
595 #endif // CHOICFMT_H
596 //eof
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
icu::ChoiceFormat::getLimits
virtual const double * getLimits(int32_t &count) const
Returns NULL and 0.
icu::NumberFormat
Definition: numfmt.h:173
icu::ChoiceFormat::ChoiceFormat
ChoiceFormat(const ChoiceFormat &that)
Copy constructor.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:62
format.h
C++ API: Base class for all formats.
icu::ChoiceFormat::operator==
virtual UBool operator==(const Format &other) const
Returns true if the given Format objects are semantically equal.
icu::ChoiceFormat::getStaticClassID
static UClassID getStaticClassID(void)
Returns the class ID for this class.
icu::ChoiceFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
icu::MessageFormat
Definition: msgfmt.h:328
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
icu::MessagePattern
Parses and represents ICU MessageFormat patterns.
Definition: messagepattern.h:360
icu::Format
Base class for all formats.
Definition: format.h:96
fieldpos.h
C++ API: FieldPosition identifies the fields in a formatted output.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:290
icu::ChoiceFormat::clone
virtual Format * clone(void) const
Clones this Format object.
icu::ChoiceFormat::format
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos) const
Formats a double number using this object's choices.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:90
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:401
icu::ChoiceFormat::ChoiceFormat
ChoiceFormat(const double *limits, const UnicodeString *formats, int32_t count)
Constructs a new ChoiceFormat with the given limits and message strings.
icu::ChoiceFormat::getClosures
virtual const UBool * getClosures(int32_t &count) const
Returns NULL and 0.
icu::ChoiceFormat::format
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos) const
Formats an int32_t number using this object's choices.
messagepattern.h
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
icu::ChoiceFormat::getFormats
virtual const UnicodeString * getFormats(int32_t &count) const
Returns NULL and 0.
icu::ChoiceFormat::format
virtual UnicodeString & format(const Formattable *objs, int32_t cnt, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &success) const
Formats an array of objects using this object's choices.
icu::ChoiceFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the pattern.
icu::ChoiceFormat::setChoices
virtual void setChoices(const double *limits, const UBool *closures, const UnicodeString *formats, int32_t count)
Sets the choices to be used in formatting.
icu::NumberFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
icu::ChoiceFormat::setChoices
virtual void setChoices(const double *limitsToCopy, const UnicodeString *formatsToCopy, int32_t count)
Sets the choices to be used in formatting.
icu::ChoiceFormat
ChoiceFormat converts between ranges of numeric values and strings for those ranges.
Definition: choicfmt.h:173
icu::ChoiceFormat::ChoiceFormat
ChoiceFormat(const UnicodeString &pattern, UErrorCode &status)
Constructs a new ChoiceFormat from the pattern string.
icu::ChoiceFormat::operator=
const ChoiceFormat & operator=(const ChoiceFormat &that)
Assignment operator.
icu::ChoiceFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern, UParseError &parseError, UErrorCode &status)
Sets the pattern.
numfmt.h
C++ API: Compatibility APIs for number formatting.
icu::ChoiceFormat::ChoiceFormat
ChoiceFormat(const double *limits, const UBool *closures, const UnicodeString *formats, int32_t count)
Constructs a new ChoiceFormat with the given limits, closure flags and message strings.
icu::ChoiceFormat::toPattern
virtual UnicodeString & toPattern(UnicodeString &pattern) const
Gets the pattern.
icu::ChoiceFormat::format
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPosition &pos) const
Formats an int64_t number using this object's choices.
icu::ChoiceFormat::~ChoiceFormat
virtual ~ChoiceFormat()
Destructor.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
unistr.h
C++ API: Unicode String.
icu::ChoiceFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const
Looks for the longest match of any message string on the input text and, if there is a match,...
icu::NumberFormat::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.