ICU 65.1 65.1

formattedvalue.h
Go to the documentation of this file.
1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #ifndef __FORMATTEDVALUE_H__
5 #define __FORMATTEDVALUE_H__
6
7 #include "unicode/utypes.h"
8
9 #if U_SHOW_CPLUSPLUS_API
10
11 #if !UCONFIG_NO_FORMATTING
12
13 #include "unicode/appendable.h"
14 #include "unicode/fpositer.h"
15 #include "unicode/unistr.h"
16 #include "unicode/uformattedvalue.h"
17
18 U_NAMESPACE_BEGIN
19
29 // The following cannot have #ifndef U_HIDE_DRAFT_API because
30 // class FormattedValue depends on it, and FormattedValue cannot be
31 // hidden becauseclass FormattedNumber (stable ICU 60) depends on it.
32 #ifndef U_FORCE_HIDE_DRAFT_API
33
46 class U_I18N_API ConstrainedFieldPosition : public UMemory {
47 public:
48
56 ConstrainedFieldPosition();
57
59 ~ConstrainedFieldPosition();
60
61 #ifndef U_HIDE_DRAFT_API
62
70 void reset();
71
94 void constrainCategory(int32_t category);
95
119 void constrainField(int32_t category, int32_t field);
120
130 inline int32_t getCategory() const {
131 return fCategory;
132 }
133
143 inline int32_t getField() const {
144 return fField;
145 }
146
155 inline int32_t getStart() const {
156 return fStart;
157 }
158
167 inline int32_t getLimit() const {
168 return fLimit;
169 }
170
175
186 inline int64_t getInt64IterationContext() const {
187 return fContext;
188 }
189
198 void setInt64IterationContext(int64_t context);
199
210 UBool matchesField(int32_t category, int32_t field) const;
211
226 void setState(
227 int32_t category,
228 int32_t field,
229 int32_t start,
230 int32_t limit);
231 #endif /* U_HIDE_DRAFT_API */
232
233 private:
234 int64_t fContext = 0LL;
235 int32_t fField = 0;
236 int32_t fStart = 0;
237 int32_t fLimit = 0;
238 #ifndef U_HIDE_DRAFT_API
239 int32_t fCategory = UFIELD_CATEGORY_UNDEFINED;
240 #else /* U_HIDE_DRAFT_API */
241 int32_t fCategory = 0;
242 #endif /* U_HIDE_DRAFT_API */
243 int8_t fConstraint = 0;
244 };
245
246 // The following cannot have #ifndef U_HIDE_DRAFT_API because
247 // class FormattedNumber (stable ICU 60) depends on it.
254 class U_I18N_API FormattedValue /* not : public UObject because this is an interface/mixin class */ {
255 public:
257 virtual ~FormattedValue();
258
269 virtual UnicodeString toString(UErrorCode& status) const = 0;
270
285 virtual UnicodeString toTempString(UErrorCode& status) const = 0;
286
298 virtual Appendable& appendTo(Appendable& appendable, UErrorCode& status) const = 0;
299
322 virtual UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const = 0;
323 };
324 #endif // U_FORCE_HIDE_DRAFT_API
325
326 U_NAMESPACE_END
327
328 #endif /* #if !UCONFIG_NO_FORMATTING */
329
330 #endif /* U_SHOW_CPLUSPLUS_API */
331
332 #endif // __FORMATTEDVALUE_H__
icu::ConstrainedFieldPosition::getCategory
int32_t getCategory() const
Gets the field category for the current position.
Definition: formattedvalue.h:130
uformattedvalue.h
C API: Abstract operations for localized strings.
icu::ConstrainedFieldPosition::getField
int32_t getField() const
Gets the field for the current position.
Definition: formattedvalue.h:143
fpositer.h
C++ API: FieldPosition Iterator.
unistr.h
C++ API: Unicode String.
appendable.h
C++ API: Appendable class: Sink for Unicode code points and 16-bit code units (char16_ts).
icu::FormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: formattedvalue.h:254
UFIELD_CATEGORY_UNDEFINED
For an undefined field category.
Definition: uformattedvalue.h:42
icu::ConstrainedFieldPosition::getStart
int32_t getStart() const
Gets the INCLUSIVE start index for the current position.
Definition: formattedvalue.h:155
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
icu::ConstrainedFieldPosition::getInt64IterationContext
int64_t getInt64IterationContext() const
Gets an int64 that FormattedValue implementations may use for storage.
Definition: formattedvalue.h:186
icu::ConstrainedFieldPosition
Represents a span of a string containing a given field.
Definition: formattedvalue.h:46
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
icu::Appendable
Base class for objects to which Unicode characters and strings can be appended.
Definition: appendable.h:54
icu::ConstrainedFieldPosition::getLimit
int32_t getLimit() const
Gets the EXCLUSIVE end index stored for the current position.
Definition: formattedvalue.h:167