Loading...
Searching...
No Matches
choicfmt.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
********************************************************************************
* Copyright (C) 1997-2013, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*
* File CHOICFMT.H
*
* Modification History:
*
* Date Name Description
* 02/19/97 aliu Converted from java.
* 03/20/97 helena Finished first cut of implementation and got rid
* of nextDouble/previousDouble and replaced with
* boolean array.
* 4/10/97 aliu Clean up. Modified to work on AIX.
* 8/6/97 nos Removed overloaded constructor, member var 'buffer'.
* 07/22/98 stephen Removed operator!= (implemented in Format)
********************************************************************************
*/
#ifndef CHOICFMT_H
#define CHOICFMT_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/fieldpos.h"
#include "unicode/format.h"
#include "unicode/messagepattern.h"
#include "unicode/numfmt.h"
#include "unicode/unistr.h"
#ifndef U_HIDE_DEPRECATED_API
U_NAMESPACE_BEGIN
class MessageFormat;
class U_I18N_API ChoiceFormat: public NumberFormat {
public:
ChoiceFormat(const UnicodeString& pattern,
UErrorCode& status);
ChoiceFormat(const double* limits,
const UnicodeString* formats,
int32_t count );
ChoiceFormat(const double* limits,
const UBool* closures,
const UnicodeString* formats,
int32_t count);
ChoiceFormat(const ChoiceFormat& that);
const ChoiceFormat& operator=(const ChoiceFormat& that);
virtual ~ChoiceFormat();
virtual ChoiceFormat* clone() const override;
virtual bool operator==(const Format& other) const override;
virtual void applyPattern(const UnicodeString& pattern,
UErrorCode& status);
virtual void applyPattern(const UnicodeString& pattern,
UParseError& parseError,
UErrorCode& status);
virtual UnicodeString& toPattern(UnicodeString &pattern) const;
virtual void setChoices(const double* limitsToCopy,
const UnicodeString* formatsToCopy,
int32_t count );
virtual void setChoices(const double* limits,
const UBool* closures,
const UnicodeString* formats,
int32_t count);
virtual const double* getLimits(int32_t& count) const;
virtual const UBool* getClosures(int32_t& count) const;
virtual const UnicodeString* getFormats(int32_t& count) const;
using NumberFormat::format;
virtual UnicodeString& format(double number,
UnicodeString& appendTo,
FieldPosition& pos) const override;
virtual UnicodeString& format(int32_t number,
UnicodeString& appendTo,
FieldPosition& pos) const override;
virtual UnicodeString& format(int64_t number,
UnicodeString& appendTo,
FieldPosition& pos) const override;
virtual UnicodeString& format(const Formattable* objs,
int32_t cnt,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& success) const;
using NumberFormat::parse;
virtual void parse(const UnicodeString& text,
Formattable& result,
ParsePosition& parsePosition) const override;
virtual UClassID getDynamicClassID() const override;
static UClassID U_EXPORT2 getStaticClassID();
private:
static UnicodeString& dtos(double value, UnicodeString& string);
ChoiceFormat() = delete; // default constructor not implemented
ChoiceFormat(const UnicodeString& newPattern,
UParseError& parseError,
UErrorCode& status);
friend class MessageFormat;
virtual void setChoices(const double* limits,
const UBool* closures,
const UnicodeString* formats,
int32_t count,
UErrorCode &errorCode);
static int32_t findSubMessage(const MessagePattern &pattern, int32_t partIndex, double number);
static double parseArgument(
const MessagePattern &pattern, int32_t partIndex,
const UnicodeString &source, ParsePosition &pos);
static int32_t matchStringUntilLimitPart(
const MessagePattern &pattern, int32_t partIndex, int32_t limitPartIndex,
const UnicodeString &source, int32_t sourceOffset);
UErrorCode constructorErrorCode;
MessagePattern msgPattern;
// double* fChoiceLimits;
// UBool* fClosures;
// UnicodeString* fChoiceFormats;
// int32_t fCount;
};
U_NAMESPACE_END
#endif // U_HIDE_DEPRECATED_API
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // CHOICFMT_H
//eof
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::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::getStaticClassID
static UClassID getStaticClassID()
Returns the class ID for this class.
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::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::ChoiceFormat::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
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:63
icu::MessagePattern
Parses and represents ICU MessageFormat patterns.
Definition messagepattern.h:362
icu::NumberFormat::NumberFormat
NumberFormat()
Default constructor for subclass use only.
icu::NumberFormat::parse
virtual void parse(const UnicodeString &text, Formattable &result, ParsePosition &parsePosition) const =0
Return a long if possible (e.g.
icu::NumberFormat::format
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
Format an object to produce a string.
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:303
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:269
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:509
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:316