intl/icu/source/common/unicode/listformatter.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 2012-2013, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 *******************************************************************************
michael@0 8 * file name: listformatter.h
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 20120426
michael@0 14 * created by: Umesh P. Nair
michael@0 15 */
michael@0 16
michael@0 17 #ifndef __LISTFORMATTER_H__
michael@0 18 #define __LISTFORMATTER_H__
michael@0 19
michael@0 20 #include "unicode/utypes.h"
michael@0 21
michael@0 22 #ifndef U_HIDE_DRAFT_API
michael@0 23
michael@0 24 #include "unicode/unistr.h"
michael@0 25 #include "unicode/locid.h"
michael@0 26
michael@0 27 U_NAMESPACE_BEGIN
michael@0 28
michael@0 29 /** @internal */
michael@0 30 class Hashtable;
michael@0 31
michael@0 32 #ifndef U_HIDE_INTERNAL_API
michael@0 33 /** @internal */
michael@0 34 struct ListFormatData : public UMemory {
michael@0 35 UnicodeString twoPattern;
michael@0 36 UnicodeString startPattern;
michael@0 37 UnicodeString middlePattern;
michael@0 38 UnicodeString endPattern;
michael@0 39
michael@0 40 ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
michael@0 41 twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
michael@0 42 };
michael@0 43 #endif /* U_HIDE_INTERNAL_API */
michael@0 44
michael@0 45
michael@0 46 /**
michael@0 47 * \file
michael@0 48 * \brief C++ API: API for formatting a list.
michael@0 49 */
michael@0 50
michael@0 51
michael@0 52 /**
michael@0 53 * An immutable class for formatting a list, using data from CLDR (or supplied
michael@0 54 * separately).
michael@0 55 *
michael@0 56 * Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted
michael@0 57 * as "Alice, Bob, Charlie and Delta" in English.
michael@0 58 *
michael@0 59 * The ListFormatter class is not intended for public subclassing.
michael@0 60 * @draft ICU 50
michael@0 61 */
michael@0 62 class U_COMMON_API ListFormatter : public UObject{
michael@0 63
michael@0 64 public:
michael@0 65
michael@0 66 /**
michael@0 67 * Copy constructor.
michael@0 68 * @draft ICU 52
michael@0 69 */
michael@0 70 ListFormatter(const ListFormatter&);
michael@0 71
michael@0 72 /**
michael@0 73 * Assignment operator.
michael@0 74 * @draft ICU 52
michael@0 75 */
michael@0 76 ListFormatter& operator=(const ListFormatter& other);
michael@0 77
michael@0 78 /**
michael@0 79 * Creates a ListFormatter appropriate for the default locale.
michael@0 80 *
michael@0 81 * @param errorCode ICU error code, set if no data available for default locale.
michael@0 82 * @return Pointer to a ListFormatter object for the default locale,
michael@0 83 * created from internal data derived from CLDR data.
michael@0 84 * @draft ICU 50
michael@0 85 */
michael@0 86 static ListFormatter* createInstance(UErrorCode& errorCode);
michael@0 87
michael@0 88 /**
michael@0 89 * Creates a ListFormatter appropriate for a locale.
michael@0 90 *
michael@0 91 * @param locale The locale.
michael@0 92 * @param errorCode ICU error code, set if no data available for the given locale.
michael@0 93 * @return A ListFormatter object created from internal data derived from
michael@0 94 * CLDR data.
michael@0 95 * @draft ICU 50
michael@0 96 */
michael@0 97 static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
michael@0 98
michael@0 99 #ifndef U_HIDE_INTERNAL_API
michael@0 100 /**
michael@0 101 * Creates a ListFormatter appropriate for a locale and style.
michael@0 102 *
michael@0 103 * @param locale The locale.
michael@0 104 * @param style the style, either "standard", "duration", or "duration-short"
michael@0 105 * @param errorCode ICU error code, set if no data available for the given locale.
michael@0 106 * @return A ListFormatter object created from internal data derived from
michael@0 107 * CLDR data.
michael@0 108 * @internal
michael@0 109 */
michael@0 110 static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
michael@0 111 #endif /* U_HIDE_INTERNAL_API */
michael@0 112
michael@0 113 /**
michael@0 114 * Destructor.
michael@0 115 *
michael@0 116 * @draft ICU 50
michael@0 117 */
michael@0 118 virtual ~ListFormatter();
michael@0 119
michael@0 120
michael@0 121 /**
michael@0 122 * Formats a list of strings.
michael@0 123 *
michael@0 124 * @param items An array of strings to be combined and formatted.
michael@0 125 * @param n_items Length of the array items.
michael@0 126 * @param appendTo The string to which the result should be appended to.
michael@0 127 * @param errorCode ICU error code, set if there is an error.
michael@0 128 * @return Formatted string combining the elements of items, appended to appendTo.
michael@0 129 * @draft ICU 50
michael@0 130 */
michael@0 131 UnicodeString& format(const UnicodeString items[], int32_t n_items,
michael@0 132 UnicodeString& appendTo, UErrorCode& errorCode) const;
michael@0 133
michael@0 134 #ifndef U_HIDE_INTERNAL_API
michael@0 135 /**
michael@0 136 * @internal constructor made public for testing.
michael@0 137 */
michael@0 138 ListFormatter(const ListFormatData* listFormatterData);
michael@0 139 #endif /* U_HIDE_INTERNAL_API */
michael@0 140
michael@0 141 private:
michael@0 142 static void initializeHash(UErrorCode& errorCode);
michael@0 143 static const ListFormatData* getListFormatData(const Locale& locale, const char *style, UErrorCode& errorCode);
michael@0 144
michael@0 145 ListFormatter();
michael@0 146 void addNewString(const UnicodeString& pattern, UnicodeString& originalString,
michael@0 147 const UnicodeString& newString, UErrorCode& errorCode) const;
michael@0 148
michael@0 149 const ListFormatData* data;
michael@0 150 };
michael@0 151
michael@0 152 U_NAMESPACE_END
michael@0 153
michael@0 154 #endif /* U_HIDE_DRAFT_API */
michael@0 155 #endif

mercurial