ICU 60.2 60.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

simpleformatter.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ******************************************************************************
5 * Copyright (C) 2014-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
8 * simpleformatter.h
9 */
10
11 #ifndef __SIMPLEFORMATTER_H__
12 #define __SIMPLEFORMATTER_H__
13
19 #include "unicode/utypes.h"
20 #include "unicode/unistr.h"
21
22 U_NAMESPACE_BEGIN
23
24 // Forward declaration:
25 namespace number {
26 namespace impl {
27 class SimpleModifier;
28 }
29 }
30
59 class U_COMMON_API SimpleFormatter U_FINAL : public UMemory {
60 public:
65 SimpleFormatter() : compiledPattern((char16_t)0) {}
66
76 SimpleFormatter(const UnicodeString& pattern, UErrorCode &errorCode) {
77 applyPattern(pattern, errorCode);
78 }
79
94 SimpleFormatter(const UnicodeString& pattern, int32_t min, int32_t max,
95 UErrorCode &errorCode) {
96 applyPatternMinMaxArguments(pattern, min, max, errorCode);
97 }
98
103 SimpleFormatter(const SimpleFormatter& other)
104 : compiledPattern(other.compiledPattern) {}
105
110 SimpleFormatter &operator=(const SimpleFormatter& other);
111
116 ~SimpleFormatter();
117
128 UBool applyPattern(const UnicodeString &pattern, UErrorCode &errorCode) {
129 return applyPatternMinMaxArguments(pattern, 0, INT32_MAX, errorCode);
130 }
131
147 UBool applyPatternMinMaxArguments(const UnicodeString &pattern,
148 int32_t min, int32_t max, UErrorCode &errorCode);
149
154 int32_t getArgumentLimit() const {
155 return getArgumentLimit(compiledPattern.getBuffer(), compiledPattern.length());
156 }
157
170 UnicodeString &format(
171 const UnicodeString &value0,
172 UnicodeString &appendTo, UErrorCode &errorCode) const;
173
187 UnicodeString &format(
188 const UnicodeString &value0,
189 const UnicodeString &value1,
190 UnicodeString &appendTo, UErrorCode &errorCode) const;
191
206 UnicodeString &format(
207 const UnicodeString &value0,
208 const UnicodeString &value1,
209 const UnicodeString &value2,
210 UnicodeString &appendTo, UErrorCode &errorCode) const;
211
231 UnicodeString &formatAndAppend(
232 const UnicodeString *const *values, int32_t valuesLength,
233 UnicodeString &appendTo,
234 int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const;
235
257 UnicodeString &formatAndReplace(
258 const UnicodeString *const *values, int32_t valuesLength,
259 UnicodeString &result,
260 int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const;
261
267 UnicodeString getTextWithNoArguments() const {
268 return getTextWithNoArguments(compiledPattern.getBuffer(), compiledPattern.length());
269 }
270
271 private:
281 UnicodeString compiledPattern;
282
283 static inline int32_t getArgumentLimit(const char16_t *compiledPattern,
284 int32_t compiledPatternLength) {
285 return compiledPatternLength == 0 ? 0 : compiledPattern[0];
286 }
287
288 static UnicodeString getTextWithNoArguments(const char16_t *compiledPattern, int32_t compiledPatternLength);
289
290 static UnicodeString &format(
291 const char16_t *compiledPattern, int32_t compiledPatternLength,
292 const UnicodeString *const *values,
293 UnicodeString &result, const UnicodeString *resultCopy, UBool forbidResultAsValue,
294 int32_t *offsets, int32_t offsetsLength,
295 UErrorCode &errorCode);
296
297 // Give access to internals to SimpleModifier for number formatting
298 friend class number::impl::SimpleModifier;
299 };
300
301 U_NAMESPACE_END
302
303 #endif // __SIMPLEFORMATTER_H__
icu::SimpleFormatter::SimpleFormatter
SimpleFormatter(const UnicodeString &pattern, UErrorCode &errorCode)
Constructs a formatter from the pattern string.
Definition: simpleformatter.h:76
icu::SimpleFormatter::SimpleFormatter
SimpleFormatter()
Default constructor.
Definition: simpleformatter.h:65
unistr.h
C++ API: Unicode String.
icu::SimpleFormatter
Formats simple patterns like "{1} was born in {0}".
Definition: simpleformatter.h:59
icu::SimpleFormatter::SimpleFormatter
SimpleFormatter(const UnicodeString &pattern, int32_t min, int32_t max, UErrorCode &errorCode)
Constructs a formatter from the pattern string.
Definition: simpleformatter.h:94
icu::SimpleFormatter::applyPattern
UBool applyPattern(const UnicodeString &pattern, UErrorCode &errorCode)
Changes this object according to the new pattern.
Definition: simpleformatter.h:128
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::SimpleFormatter::getTextWithNoArguments
UnicodeString getTextWithNoArguments() const
Returns the pattern text with none of the arguments.
Definition: simpleformatter.h:267
icu::SimpleFormatter::SimpleFormatter
SimpleFormatter(const SimpleFormatter &other)
Copy constructor.
Definition: simpleformatter.h:103
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
INT32_MAX
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition: umachine.h:182
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:359
icu::SimpleFormatter::getArgumentLimit
int32_t getArgumentLimit() const
Definition: simpleformatter.h:154
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:112
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236