00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __LISTFORMATTER_H__
00020 #define __LISTFORMATTER_H__
00021
00022 #include "unicode/utypes.h"
00023
00024 #if U_SHOW_CPLUSPLUS_API
00025
00026 #include "unicode/unistr.h"
00027 #include "unicode/locid.h"
00028 #include "unicode/formattedvalue.h"
00029
00030 U_NAMESPACE_BEGIN
00031
00032 class FieldPositionIterator;
00033 class FieldPositionHandler;
00034 class FormattedListData;
00035 class ListFormatter;
00036
00038 class Hashtable;
00039
00041 struct ListFormatInternal;
00042
00043
00048 struct ListFormatData : public UMemory {
00049 UnicodeString twoPattern;
00050 UnicodeString startPattern;
00051 UnicodeString middlePattern;
00052 UnicodeString endPattern;
00053
00054 ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
00055 twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
00056 };
00066 #if !UCONFIG_NO_FORMATTING
00067 #ifndef U_HIDE_DRAFT_API
00068
00084 class U_I18N_API FormattedList : public UMemory, public FormattedValue {
00085 public:
00090 FormattedList() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
00091
00096 FormattedList(FormattedList&& src) U_NOEXCEPT;
00097
00102 virtual ~FormattedList() U_OVERRIDE;
00103
00105 FormattedList(const FormattedList&) = delete;
00106
00108 FormattedList& operator=(const FormattedList&) = delete;
00109
00114 FormattedList& operator=(FormattedList&& src) U_NOEXCEPT;
00115
00117 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
00118
00120 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
00121
00123 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
00124
00126 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
00127
00128 private:
00129 FormattedListData *fData;
00130 UErrorCode fErrorCode;
00131 explicit FormattedList(FormattedListData *results)
00132 : fData(results), fErrorCode(U_ZERO_ERROR) {}
00133 explicit FormattedList(UErrorCode errorCode)
00134 : fData(nullptr), fErrorCode(errorCode) {}
00135 friend class ListFormatter;
00136 };
00137 #endif
00138 #endif // !UCONFIG_NO_FORMATTING
00139
00140
00151 class U_I18N_API ListFormatter : public UObject{
00152
00153 public:
00154
00159 ListFormatter(const ListFormatter&);
00160
00165 ListFormatter& operator=(const ListFormatter& other);
00166
00175 static ListFormatter* createInstance(UErrorCode& errorCode);
00176
00186 static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
00187
00188 #ifndef U_HIDE_INTERNAL_API
00189
00199 static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
00200 #endif
00201
00207 virtual ~ListFormatter();
00208
00209
00220 UnicodeString& format(const UnicodeString items[], int32_t n_items,
00221 UnicodeString& appendTo, UErrorCode& errorCode) const;
00222
00223 #ifndef U_HIDE_DRAFT_API
00224
00239 UnicodeString& format(const UnicodeString items[], int32_t n_items,
00240 UnicodeString & appendTo, FieldPositionIterator* posIter,
00241 UErrorCode& errorCode) const;
00242 #endif // U_HIDE_DRAFT_API
00243
00244 #if !UCONFIG_NO_FORMATTING
00245 #ifndef U_HIDE_DRAFT_API
00246
00257 FormattedList formatStringsToValue(
00258 const UnicodeString items[],
00259 int32_t n_items,
00260 UErrorCode& errorCode) const;
00261 #endif
00262 #endif // !UCONFIG_NO_FORMATTING
00263
00264 #ifndef U_HIDE_INTERNAL_API
00265
00268 UnicodeString& format(
00269 const UnicodeString items[],
00270 int32_t n_items,
00271 UnicodeString& appendTo,
00272 int32_t index,
00273 int32_t &offset,
00274 UErrorCode& errorCode) const;
00278 ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
00282 ListFormatter(const ListFormatInternal* listFormatterInternal);
00283 #endif
00284
00285 private:
00286 static void initializeHash(UErrorCode& errorCode);
00287 static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
00288 struct ListPatternsSink;
00289 static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
00290
00291 UnicodeString& format_(
00292 const UnicodeString items[], int32_t n_items, UnicodeString& appendTo,
00293 int32_t index, int32_t &offset, FieldPositionHandler* handler, UErrorCode& errorCode) const;
00294
00295 ListFormatter();
00296
00297 ListFormatInternal* owned;
00298 const ListFormatInternal* data;
00299 };
00300
00301 U_NAMESPACE_END
00302
00303 #endif
00304
00305 #endif // __LISTFORMATTER_H__