listformatter.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) 2012-2016, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: listformatter.h
* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
* created on: 20120426
* created by: Umesh P. Nair
*/
#ifndef __LISTFORMATTER_H__
#define __LISTFORMATTER_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/unistr.h"
#include "unicode/locid.h"
#include "unicode/formattedvalue.h"
#include "unicode/ulistformatter.h"
U_NAMESPACE_BEGIN
class FieldPositionHandler;
class FormattedListData;
class ListFormatter;
class Hashtable;
struct ListFormatInternal;
/* The following can't be #ifndef U_HIDE_INTERNAL_API, needed for other .h file declarations */
struct ListFormatData : public UMemory {
UnicodeString twoPattern;
UnicodeString startPattern;
UnicodeString middlePattern;
UnicodeString endPattern;
Locale locale;
ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end,
const Locale& loc) :
twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end), locale(loc) {}
};
class U_I18N_API FormattedList : public UMemory, public FormattedValue {
public:
FormattedList() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
FormattedList(FormattedList&& src) noexcept;
virtual ~FormattedList() override;
FormattedList(const FormattedList&) = delete;
FormattedList& operator=(const FormattedList&) = delete;
FormattedList& operator=(FormattedList&& src) noexcept;
UnicodeString toString(UErrorCode& status) const override;
UnicodeString toTempString(UErrorCode& status) const override;
Appendable &appendTo(Appendable& appendable, UErrorCode& status) const override;
UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const override;
private:
FormattedListData *fData;
UErrorCode fErrorCode;
explicit FormattedList(FormattedListData *results)
: fData(results), fErrorCode(U_ZERO_ERROR) {}
explicit FormattedList(UErrorCode errorCode)
: fData(nullptr), fErrorCode(errorCode) {}
friend class ListFormatter;
};
class U_I18N_API ListFormatter : public UObject{
public:
ListFormatter(const ListFormatter&);
ListFormatter& operator=(const ListFormatter& other);
static ListFormatter* createInstance(UErrorCode& errorCode);
static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
static ListFormatter* createInstance(
const Locale& locale, UListFormatterType type, UListFormatterWidth width, UErrorCode& errorCode);
virtual ~ListFormatter();
UnicodeString& format(const UnicodeString items[], int32_t n_items,
UnicodeString& appendTo, UErrorCode& errorCode) const;
FormattedList formatStringsToValue(
const UnicodeString items[],
int32_t n_items,
UErrorCode& errorCode) const;
#ifndef U_HIDE_INTERNAL_API
UnicodeString& format(
const UnicodeString items[],
int32_t n_items,
UnicodeString& appendTo,
int32_t index,
int32_t &offset,
UErrorCode& errorCode) const;
ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
ListFormatter(const ListFormatInternal* listFormatterInternal);
#endif /* U_HIDE_INTERNAL_API */
private:
static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
static void initializeHash(UErrorCode& errorCode);
static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
struct U_HIDDEN ListPatternsSink;
static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
ListFormatter() = delete;
ListFormatInternal* owned;
const ListFormatInternal* data;
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __LISTFORMATTER_H__
icu::Appendable
Base class for objects to which Unicode characters and strings can be appended.
Definition: appendable.h:54
icu::ConstrainedFieldPosition
Represents a span of a string containing a given field.
Definition: formattedvalue.h:41
icu::FormattedList
An immutable class containing the result of a list formatting operation.
Definition: listformatter.h:86
icu::FormattedList::FormattedList
FormattedList(const FormattedList &)=delete
Copying not supported; use move constructor instead.
icu::FormattedList::FormattedList
FormattedList(FormattedList &&src) noexcept
Move constructor: Leaves the source FormattedList in an undefined state.
icu::FormattedList::toTempString
UnicodeString toTempString(UErrorCode &status) const override
Returns the formatted string as a read-only alias to memory owned by the FormattedValue.
icu::FormattedList::toString
UnicodeString toString(UErrorCode &status) const override
Returns the formatted string as a self-contained UnicodeString.
icu::FormattedList::FormattedList
FormattedList()
Default constructor; makes an empty FormattedList.
Definition: listformatter.h:92
icu::FormattedList::nextPosition
UBool nextPosition(ConstrainedFieldPosition &cfpos, UErrorCode &status) const override
Iterates over field positions in the FormattedValue.
icu::FormattedList::operator=
FormattedList & operator=(const FormattedList &)=delete
Copying not supported; use move assignment instead.
icu::FormattedList::appendTo
Appendable & appendTo(Appendable &appendable, UErrorCode &status) const override
Appends the formatted string to an Appendable.
icu::FormattedList::~FormattedList
virtual ~FormattedList() override
Destruct an instance of FormattedList.
icu::FormattedList::operator=
FormattedList & operator=(FormattedList &&src) noexcept
Move assignment: Leaves the source FormattedList in an undefined state.
icu::FormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: formattedvalue.h:241
icu::ListFormatter
An immutable class for formatting a list, using data from CLDR (or supplied separately).
Definition: listformatter.h:151
icu::ListFormatter::createInstance
static ListFormatter * createInstance(UErrorCode &errorCode)
Creates a ListFormatter appropriate for the default locale.
icu::ListFormatter::createInstance
static ListFormatter * createInstance(const Locale &locale, UErrorCode &errorCode)
Creates a ListFormatter appropriate for a locale.
icu::ListFormatter::ListFormatter
ListFormatter(const ListFormatInternal *listFormatterInternal)
icu::ListFormatter::~ListFormatter
virtual ~ListFormatter()
Destructor.
icu::ListFormatter::createInstance
static ListFormatter * createInstance(const Locale &locale, UListFormatterType type, UListFormatterWidth width, UErrorCode &errorCode)
Creates a ListFormatter for the given locale, list type, and style.
icu::ListFormatter::formatStringsToValue
FormattedList formatStringsToValue(const UnicodeString items[], int32_t n_items, UErrorCode &errorCode) const
Formats a list of strings to a FormattedList, which exposes field position information.
icu::ListFormatter::ListFormatter
ListFormatter(const ListFormatter &)
Copy constructor.
icu::ListFormatter::ListFormatter
ListFormatter(const ListFormatData &data, UErrorCode &errorCode)
icu::ListFormatter::operator=
ListFormatter & operator=(const ListFormatter &other)
Assignment operator.
icu::ListFormatter::format
UnicodeString & format(const UnicodeString items[], int32_t n_items, UnicodeString &appendTo, int32_t index, int32_t &offset, UErrorCode &errorCode) const
icu::ListFormatter::format
UnicodeString & format(const UnicodeString items[], int32_t n_items, UnicodeString &appendTo, UErrorCode &errorCode) const
Formats a list of strings.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
formattedvalue.h
C++ API: Abstract operations for localized strings.
locid.h
C++ API: Locale ID object.
U_HIDDEN
#define U_HIDDEN
This is used to mark internal structs declared within external classes, to prevent the internal struc...
Definition: platform.h:843
ulistformatter.h
C API: Format a list in a locale-appropriate way.
UListFormatterWidth
UListFormatterWidth
Verbosity level of the list patterns.
Definition: ulistformatter.h:99
UListFormatterType
UListFormatterType
Type of meaning expressed by the list.
Definition: ulistformatter.h:70
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
unistr.h
C++ API: Unicode String.
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_INVALID_STATE_ERROR
@ U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition: utypes.h:478
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:449
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