Warning, file /include/unicode/listformatter.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef __LISTFORMATTER_H__
0020 #define __LISTFORMATTER_H__
0021
0022 #include "unicode/utypes.h"
0023
0024 #if U_SHOW_CPLUSPLUS_API
0025
0026 #if !UCONFIG_NO_FORMATTING
0027
0028 #include "unicode/unistr.h"
0029 #include "unicode/locid.h"
0030 #include "unicode/formattedvalue.h"
0031 #include "unicode/ulistformatter.h"
0032
0033 U_NAMESPACE_BEGIN
0034
0035 class FieldPositionHandler;
0036 class FormattedListData;
0037 class ListFormatter;
0038
0039
0040 class Hashtable;
0041
0042
0043 struct ListFormatInternal;
0044
0045
0046
0047
0048
0049
0050 struct ListFormatData : public UMemory {
0051 UnicodeString twoPattern;
0052 UnicodeString startPattern;
0053 UnicodeString middlePattern;
0054 UnicodeString endPattern;
0055 Locale locale;
0056
0057 ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end,
0058 const Locale& loc) :
0059 twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end), locale(loc) {}
0060 };
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 class U_I18N_API FormattedList : public UMemory, public FormattedValue {
0087 public:
0088
0089
0090
0091
0092 FormattedList() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
0093
0094
0095
0096
0097
0098 FormattedList(FormattedList&& src) noexcept;
0099
0100
0101
0102
0103
0104 virtual ~FormattedList() override;
0105
0106
0107 FormattedList(const FormattedList&) = delete;
0108
0109
0110 FormattedList& operator=(const FormattedList&) = delete;
0111
0112
0113
0114
0115
0116 FormattedList& operator=(FormattedList&& src) noexcept;
0117
0118
0119 UnicodeString toString(UErrorCode& status) const override;
0120
0121
0122 UnicodeString toTempString(UErrorCode& status) const override;
0123
0124
0125 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const override;
0126
0127
0128 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const override;
0129
0130 private:
0131 FormattedListData *fData;
0132 UErrorCode fErrorCode;
0133 explicit FormattedList(FormattedListData *results)
0134 : fData(results), fErrorCode(U_ZERO_ERROR) {}
0135 explicit FormattedList(UErrorCode errorCode)
0136 : fData(nullptr), fErrorCode(errorCode) {}
0137 friend class ListFormatter;
0138 };
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 class U_I18N_API ListFormatter : public UObject{
0152
0153 public:
0154
0155
0156
0157
0158
0159 ListFormatter(const ListFormatter&);
0160
0161
0162
0163
0164
0165 ListFormatter& operator=(const ListFormatter& other);
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 static ListFormatter* createInstance(UErrorCode& errorCode);
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186 static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198 static ListFormatter* createInstance(
0199 const Locale& locale, UListFormatterType type, UListFormatterWidth width, UErrorCode& errorCode);
0200
0201
0202
0203
0204
0205
0206 virtual ~ListFormatter();
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 UnicodeString& format(const UnicodeString items[], int32_t n_items,
0220 UnicodeString& appendTo, UErrorCode& errorCode) const;
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 FormattedList formatStringsToValue(
0234 const UnicodeString items[],
0235 int32_t n_items,
0236 UErrorCode& errorCode) const;
0237
0238 #ifndef U_HIDE_INTERNAL_API
0239
0240
0241
0242 UnicodeString& format(
0243 const UnicodeString items[],
0244 int32_t n_items,
0245 UnicodeString& appendTo,
0246 int32_t index,
0247 int32_t &offset,
0248 UErrorCode& errorCode) const;
0249
0250
0251
0252 ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
0253
0254
0255
0256 ListFormatter(const ListFormatInternal* listFormatterInternal);
0257 #endif
0258
0259 private:
0260
0261
0262
0263
0264
0265
0266
0267 static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
0268
0269 static void initializeHash(UErrorCode& errorCode);
0270 static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
0271 struct U_HIDDEN ListPatternsSink;
0272 static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
0273
0274 ListFormatter() = delete;
0275
0276 ListFormatInternal* owned;
0277 const ListFormatInternal* data;
0278 };
0279
0280 U_NAMESPACE_END
0281
0282 #endif
0283
0284 #endif
0285
0286 #endif