ICU 74.2 74.2

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
38#include "unicode/fieldpos.h"
39#include "unicode/format.h"
40#include "unicode/messagepattern.h"
41#include "unicode/numfmt.h"
42#include "unicode/unistr.h"
43
44#ifndef U_HIDE_DEPRECATED_API
45
46U_NAMESPACE_BEGIN
47
48 class MessageFormat;
49
176 class U_I18N_API ChoiceFormat: public NumberFormat {
177 public:
186 ChoiceFormat(const UnicodeString& pattern,
187 UErrorCode& status);
188
189
202 ChoiceFormat(const double* limits,
203 const UnicodeString* formats,
204 int32_t count );
205
220 ChoiceFormat(const double* limits,
221 const UBool* closures,
222 const UnicodeString* formats,
223 int32_t count);
224
231 ChoiceFormat(const ChoiceFormat& that);
232
239 const ChoiceFormat& operator=(const ChoiceFormat& that);
240
245 virtual ~ChoiceFormat();
246
254 virtual ChoiceFormat* clone() const override;
255
264 virtual bool operator==(const Format& other) const override;
265
274 virtual void applyPattern(const UnicodeString& pattern,
275 UErrorCode& status);
276
287 virtual void applyPattern(const UnicodeString& pattern,
288 UParseError& parseError,
289 UErrorCode& status);
298 virtual UnicodeString& toPattern(UnicodeString &pattern) const;
299
313 virtual void setChoices(const double* limitsToCopy,
314 const UnicodeString* formatsToCopy,
315 int32_t count );
316
327 virtual void setChoices(const double* limits,
328 const UBool* closures,
329 const UnicodeString* formats,
330 int32_t count);
331
340 virtual const double* getLimits(int32_t& count) const;
341
350 virtual const UBool* getClosures(int32_t& count) const;
351
360 virtual const UnicodeString* getFormats(int32_t& count) const;
361
362
363 using NumberFormat::format;
364
376 virtual UnicodeString& format(double number,
377 UnicodeString& appendTo,
378 FieldPosition& pos) const override;
390 virtual UnicodeString& format(int32_t number,
391 UnicodeString& appendTo,
392 FieldPosition& pos) const override;
393
405 virtual UnicodeString& format(int64_t number,
406 UnicodeString& appendTo,
407 FieldPosition& pos) const override;
408
423 virtual UnicodeString& format(const Formattable* objs,
424 int32_t cnt,
425 UnicodeString& appendTo,
426 FieldPosition& pos,
427 UErrorCode& success) const;
428
429 using NumberFormat::parse;
430
445 virtual void parse(const UnicodeString& text,
446 Formattable& result,
447 ParsePosition& parsePosition) const override;
448
457 virtual UClassID getDynamicClassID(void) const override;
458
470 static UClassID U_EXPORT2 getStaticClassID(void);
471
472 private:
479 static UnicodeString& dtos(double value, UnicodeString& string);
480
481 ChoiceFormat() = delete; // default constructor not implemented
482
493 ChoiceFormat(const UnicodeString& newPattern,
494 UParseError& parseError,
495 UErrorCode& status);
496
497 friend class MessageFormat;
498
499 virtual void setChoices(const double* limits,
500 const UBool* closures,
501 const UnicodeString* formats,
502 int32_t count,
503 UErrorCode &errorCode);
504
512 static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
513
514 static double parseArgument(
515 const MessagePattern &pattern, int32_t partIndex,
516 const UnicodeString &source, ParsePosition &pos);
517
526 static int32_t matchStringUntilLimitPart(
527 const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
528 const UnicodeString &source, int32_t sourceOffset);
529
536 UErrorCode constructorErrorCode;
537
545 MessagePattern msgPattern;
546
586 // double* fChoiceLimits;
587 // UBool* fClosures;
588 // UnicodeString* fChoiceFormats;
589 // int32_t fCount;
590};
591
592
593U_NAMESPACE_END
594
595#endif // U_HIDE_DEPRECATED_API
596#endif /* #if !UCONFIG_NO_FORMATTING */
597
598#endif /* U_SHOW_CPLUSPLUS_API */
599
600#endif // CHOICFMT_H
601//eof
icu::ChoiceFormat
ChoiceFormat converts between ranges of numeric values and strings for those ranges.
Definition choicfmt.h:176
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::clone
virtual ChoiceFormat * clone() const override
Clones this Format object.
icu::ChoiceFormat::getStaticClassID
static UClassID getStaticClassID(void)
Returns the class ID for this class.
icu::ChoiceFormat::getLimits
virtual const double * getLimits(int32_t &count) const
Returns nullptr and 0.
icu::ChoiceFormat::ChoiceFormat
ChoiceFormat(const UnicodeString &pattern, UErrorCode &status)
Constructs a new ChoiceFormat from the pattern string.
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::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::ChoiceFormat::format
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPosition &pos) const override
Formats an int64_t number using this object's choices.
icu::ChoiceFormat::operator==
virtual bool operator==(const Format &other) const override
Returns true if the given Format objects are semantically equal.
icu::ChoiceFormat::ChoiceFormat
ChoiceFormat(const ChoiceFormat &that)
Copy constructor.
icu::ChoiceFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern, UParseError &parseError, UErrorCode &status)
Sets the pattern.
icu::ChoiceFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const override
Returns a unique class ID POLYMORPHICALLY.
icu::ChoiceFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the pattern.
icu::ChoiceFormat::format
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos) const override
Formats an int32_t number using this object's choices.
icu::ChoiceFormat::operator=
const ChoiceFormat & operator=(const ChoiceFormat &that)
Assignment operator.
icu::ChoiceFormat::~ChoiceFormat
virtual ~ChoiceFormat()
Destructor.
icu::ChoiceFormat::getClosures
virtual const UBool * getClosures(int32_t &count) const
Returns nullptr and 0.
icu::ChoiceFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const override
Looks for the longest match of any message string on the input text and, if there is a match,...
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::ChoiceFormat
ChoiceFormat(const double *limits, const UnicodeString *formats, int32_t count)
Constructs a new ChoiceFormat with the given limits and message strings.
icu::ChoiceFormat::toPattern
virtual UnicodeString & toPattern(UnicodeString &pattern) const
Gets the pattern.
icu::ChoiceFormat::getFormats
virtual const UnicodeString * getFormats(int32_t &count) const
Returns nullptr and 0.
icu::ChoiceFormat::format
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos) const override
Formats a double number using this object's choices.
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:110
icu::Format
Base class for all formats.
Definition format.h:98
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:64
icu::MessageFormat
Definition msgfmt.h:345
icu::MessagePattern
Parses and represents ICU MessageFormat patterns.
Definition messagepattern.h:362
icu::NumberFormat
Definition numfmt.h:175
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:52
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
fieldpos.h
C++ API: FieldPosition identifies the fields in a formatted output.
format.h
C++ API: Base class for all formats.
messagepattern.h
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
numfmt.h
C++ API: Compatibility APIs for number formatting.
UParseError
A UParseError struct is used to returned detailed information about parsing errors.
Definition parseerr.h:58
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
unistr.h
C++ API: Unicode String.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:415
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