ICU 57.1 57.1
choicfmt.h
Go to the documentation of this file.
1/*
2********************************************************************************
3* Copyright (C) 1997-2013, 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"
38#include "unicode/numfmt.h"
39#include "unicode/unistr.h"
40
42
43class MessageFormat;
44
172public:
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
227
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
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;
423
425
440 virtual void parse(const UnicodeString& text,
441 Formattable& result,
442 ParsePosition& parsePosition) const;
443
452 virtual UClassID getDynamicClassID(void) const;
453
465 static UClassID U_EXPORT2 getStaticClassID(void);
466
467private:
474 static UnicodeString& dtos(double value, UnicodeString& string);
475
476 ChoiceFormat(); // default constructor not implemented
477
488 ChoiceFormat(const UnicodeString& newPattern,
489 UParseError& parseError,
490 UErrorCode& status);
491
492 friend class MessageFormat;
493
494 virtual void setChoices(const double* limits,
495 const UBool* closures,
496 const UnicodeString* formats,
497 int32_t count,
498 UErrorCode &errorCode);
499
507 static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
508
509 static double parseArgument(
510 const MessagePattern &pattern, int32_t partIndex,
511 const UnicodeString &source, ParsePosition &pos);
512
521 static int32_t matchStringUntilLimitPart(
522 const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
523 const UnicodeString &source, int32_t sourceOffset);
524
531 UErrorCode constructorErrorCode;
532
540 MessagePattern msgPattern;
541
581 // double* fChoiceLimits;
582 // UBool* fClosures;
583 // UnicodeString* fChoiceFormats;
584 // int32_t fCount;
585};
586
587
589
590#endif // U_HIDE_DEPRECATED_API
591#endif /* #if !UCONFIG_NO_FORMATTING */
592
593#endif // CHOICFMT_H
594//eof
ChoiceFormat converts between ranges of numeric values and strings for those ranges.
Definition: choicfmt.h:171
virtual void applyPattern(const UnicodeString &pattern, UParseError &parseError, UErrorCode &status)
Sets the pattern.
virtual Format * clone(void) const
Clones this Format object.
virtual ~ChoiceFormat()
Destructor.
virtual UnicodeString & format(int32_t number, UnicodeString &appendTo, FieldPosition &pos) const
Formats an int32_t number using this object's choices.
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.
const ChoiceFormat & operator=(const ChoiceFormat &that)
Assignment operator.
virtual void setChoices(const double *limitsToCopy, const UnicodeString *formatsToCopy, int32_t count)
Sets the choices to be used in formatting.
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.
ChoiceFormat(const double *limits, const UnicodeString *formats, int32_t count)
Constructs a new ChoiceFormat with the given limits and message strings.
virtual UnicodeString & toPattern(UnicodeString &pattern) const
Gets the pattern.
virtual void setChoices(const double *limits, const UBool *closures, const UnicodeString *formats, int32_t count)
Sets the choices to be used in formatting.
virtual const UnicodeString * getFormats(int32_t &count) const
Returns NULL and 0.
ChoiceFormat(const UnicodeString &pattern, UErrorCode &status)
Constructs a new ChoiceFormat from the pattern string.
virtual UBool operator==(const Format &other) const
Returns true if the given Format objects are semantically equal.
virtual const double * getLimits(int32_t &count) const
Returns NULL and 0.
virtual void applyPattern(const UnicodeString &pattern, UErrorCode &status)
Sets the pattern.
ChoiceFormat(const ChoiceFormat &that)
Copy constructor.
virtual UnicodeString & format(double number, UnicodeString &appendTo, FieldPosition &pos) const
Formats a double number using this object's choices.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
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,...
static UClassID getStaticClassID(void)
Returns the class ID for this class.
virtual const UBool * getClosures(int32_t &count) const
Returns NULL and 0.
virtual UnicodeString & format(int64_t number, UnicodeString &appendTo, FieldPosition &pos) const
Formats an int64_t number using this object's choices.
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
Base class for all formats.
Definition: format.h:94
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
Parses and represents ICU MessageFormat patterns.
Abstract base class for all number formats.
Definition: numfmt.h:167
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:47
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
C++ API: FieldPosition identifies the fields in a formatted output.
C++ API: Base class for all formats.
C++ API: MessagePattern class: Parses and represents ICU MessageFormat patterns.
C++ API: Abstract base class for all number formats.
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:56
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:91
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:476
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:358
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129