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 #include "unicode/unistr.h"
00025 #include "unicode/locid.h"
00026 #include "unicode/formattedvalue.h"
00027
00028 U_NAMESPACE_BEGIN
00029
00030 class FieldPositionIterator;
00031 class FieldPositionHandler;
00032 class FormattedListData;
00033 class ListFormatter;
00034
00036 class Hashtable;
00037
00039 struct ListFormatInternal;
00040
00041
00046 struct ListFormatData : public UMemory {
00047 UnicodeString twoPattern;
00048 UnicodeString startPattern;
00049 UnicodeString middlePattern;
00050 UnicodeString endPattern;
00051
00052 ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
00053 twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
00054 };
00064 #if !UCONFIG_NO_FORMATTING
00065 #ifndef U_HIDE_DRAFT_API
00066
00082 class U_I18N_API FormattedList : public UMemory, public FormattedValue {
00083 public:
00088 FormattedList() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
00089
00094 FormattedList(FormattedList&& src) U_NOEXCEPT;
00095
00100 virtual ~FormattedList() U_OVERRIDE;
00101
00103 FormattedList(const FormattedList&) = delete;
00104
00106 FormattedList& operator=(const FormattedList&) = delete;
00107
00112 FormattedList& operator=(FormattedList&& src) U_NOEXCEPT;
00113
00115 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
00116
00118 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
00119
00121 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
00122
00124 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
00125
00126 private:
00127 FormattedListData *fData;
00128 UErrorCode fErrorCode;
00129 explicit FormattedList(FormattedListData *results)
00130 : fData(results), fErrorCode(U_ZERO_ERROR) {}
00131 explicit FormattedList(UErrorCode errorCode)
00132 : fData(nullptr), fErrorCode(errorCode) {}
00133 friend class ListFormatter;
00134 };
00135 #endif
00136 #endif // !UCONFIG_NO_FORMATTING
00137
00138
00149 class U_I18N_API ListFormatter : public UObject{
00150
00151 public:
00152
00157 ListFormatter(const ListFormatter&);
00158
00163 ListFormatter& operator=(const ListFormatter& other);
00164
00173 static ListFormatter* createInstance(UErrorCode& errorCode);
00174
00184 static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
00185
00186 #ifndef U_HIDE_INTERNAL_API
00187
00197 static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
00198 #endif
00199
00205 virtual ~ListFormatter();
00206
00207
00218 UnicodeString& format(const UnicodeString items[], int32_t n_items,
00219 UnicodeString& appendTo, UErrorCode& errorCode) const;
00220
00221 #ifndef U_HIDE_DRAFT_API
00222
00237 UnicodeString& format(const UnicodeString items[], int32_t n_items,
00238 UnicodeString & appendTo, FieldPositionIterator* posIter,
00239 UErrorCode& errorCode) const;
00240 #endif
00241
00242 #if !UCONFIG_NO_FORMATTING
00243 #ifndef U_HIDE_DRAFT_API
00244
00255 FormattedList formatStringsToValue(
00256 const UnicodeString items[],
00257 int32_t n_items,
00258 UErrorCode& errorCode) const;
00259 #endif
00260 #endif // !UCONFIG_NO_FORMATTING
00261
00262 #ifndef U_HIDE_INTERNAL_API
00263
00266 UnicodeString& format(
00267 const UnicodeString items[],
00268 int32_t n_items,
00269 UnicodeString& appendTo,
00270 int32_t index,
00271 int32_t &offset,
00272 UErrorCode& errorCode) const;
00276 ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
00280 ListFormatter(const ListFormatInternal* listFormatterInternal);
00281 #endif
00282
00283 private:
00284 static void initializeHash(UErrorCode& errorCode);
00285 static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
00286 struct ListPatternsSink;
00287 static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
00288
00289 UnicodeString& format_(
00290 const UnicodeString items[], int32_t n_items, UnicodeString& appendTo,
00291 int32_t index, int32_t &offset, FieldPositionHandler* handler, UErrorCode& errorCode) const;
00292
00293 ListFormatter();
00294
00295 ListFormatInternal* owned;
00296 const ListFormatInternal* data;
00297 };
00298
00299 U_NAMESPACE_END
00300
00301 #endif // __LISTFORMATTER_H__