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 #include "unicode/ulistformatter.h"
00030
00031 U_NAMESPACE_BEGIN
00032
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 Locale locale;
00054
00055 ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end,
00056 const Locale& loc) :
00057 twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end), locale(loc) {}
00058 };
00068 #if !UCONFIG_NO_FORMATTING
00069
00085 class U_I18N_API FormattedList : public UMemory, public FormattedValue {
00086 public:
00091 FormattedList() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
00092
00097 FormattedList(FormattedList&& src) U_NOEXCEPT;
00098
00103 virtual ~FormattedList() U_OVERRIDE;
00104
00106 FormattedList(const FormattedList&) = delete;
00107
00109 FormattedList& operator=(const FormattedList&) = delete;
00110
00115 FormattedList& operator=(FormattedList&& src) U_NOEXCEPT;
00116
00118 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
00119
00121 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
00122
00124 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
00125
00127 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
00128
00129 private:
00130 FormattedListData *fData;
00131 UErrorCode fErrorCode;
00132 explicit FormattedList(FormattedListData *results)
00133 : fData(results), fErrorCode(U_ZERO_ERROR) {}
00134 explicit FormattedList(UErrorCode errorCode)
00135 : fData(nullptr), fErrorCode(errorCode) {}
00136 friend class ListFormatter;
00137 };
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_DRAFT_API
00189 #if !UCONFIG_NO_FORMATTING
00190
00200 static ListFormatter* createInstance(
00201 const Locale& locale, UListFormatterType type, UListFormatterWidth width, UErrorCode& errorCode);
00202 #endif
00203 #endif
00204
00205 #ifndef U_HIDE_INTERNAL_API
00206
00218 static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
00219 #endif
00220
00226 virtual ~ListFormatter();
00227
00228
00239 UnicodeString& format(const UnicodeString items[], int32_t n_items,
00240 UnicodeString& appendTo, UErrorCode& errorCode) const;
00241
00242 #if !UCONFIG_NO_FORMATTING
00243
00254 FormattedList formatStringsToValue(
00255 const UnicodeString items[],
00256 int32_t n_items,
00257 UErrorCode& errorCode) const;
00258 #endif // !UCONFIG_NO_FORMATTING
00259
00260 #ifndef U_HIDE_INTERNAL_API
00261
00264 UnicodeString& format(
00265 const UnicodeString items[],
00266 int32_t n_items,
00267 UnicodeString& appendTo,
00268 int32_t index,
00269 int32_t &offset,
00270 UErrorCode& errorCode) const;
00274 ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
00278 ListFormatter(const ListFormatInternal* listFormatterInternal);
00279 #endif
00280
00281 private:
00282 static void initializeHash(UErrorCode& errorCode);
00283 static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
00284 struct ListPatternsSink;
00285 static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
00286
00287 UnicodeString& format_(
00288 const UnicodeString items[], int32_t n_items, UnicodeString& appendTo,
00289 int32_t index, int32_t &offset, FieldPositionHandler* handler, UErrorCode& errorCode) const;
00290
00291 ListFormatter();
00292
00293 ListFormatInternal* owned;
00294 const ListFormatInternal* data;
00295 };
00296
00297 U_NAMESPACE_END
00298
00299 #endif
00300
00301 #endif // __LISTFORMATTER_H__