00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __SIMPLEFORMATTER_H__
00012 #define __SIMPLEFORMATTER_H__
00013
00019 #include "unicode/utypes.h"
00020 #include "unicode/unistr.h"
00021
00022 U_NAMESPACE_BEGIN
00023
00024
00025 namespace number {
00026 namespace impl {
00027 class SimpleModifier;
00028 }
00029 }
00030
00059 class U_COMMON_API SimpleFormatter U_FINAL : public UMemory {
00060 public:
00065 SimpleFormatter() : compiledPattern((char16_t)0) {}
00066
00076 SimpleFormatter(const UnicodeString& pattern, UErrorCode &errorCode) {
00077 applyPattern(pattern, errorCode);
00078 }
00079
00094 SimpleFormatter(const UnicodeString& pattern, int32_t min, int32_t max,
00095 UErrorCode &errorCode) {
00096 applyPatternMinMaxArguments(pattern, min, max, errorCode);
00097 }
00098
00103 SimpleFormatter(const SimpleFormatter& other)
00104 : compiledPattern(other.compiledPattern) {}
00105
00110 SimpleFormatter &operator=(const SimpleFormatter& other);
00111
00116 ~SimpleFormatter();
00117
00128 UBool applyPattern(const UnicodeString &pattern, UErrorCode &errorCode) {
00129 return applyPatternMinMaxArguments(pattern, 0, INT32_MAX, errorCode);
00130 }
00131
00147 UBool applyPatternMinMaxArguments(const UnicodeString &pattern,
00148 int32_t min, int32_t max, UErrorCode &errorCode);
00149
00154 int32_t getArgumentLimit() const {
00155 return getArgumentLimit(compiledPattern.getBuffer(), compiledPattern.length());
00156 }
00157
00170 UnicodeString &format(
00171 const UnicodeString &value0,
00172 UnicodeString &appendTo, UErrorCode &errorCode) const;
00173
00187 UnicodeString &format(
00188 const UnicodeString &value0,
00189 const UnicodeString &value1,
00190 UnicodeString &appendTo, UErrorCode &errorCode) const;
00191
00206 UnicodeString &format(
00207 const UnicodeString &value0,
00208 const UnicodeString &value1,
00209 const UnicodeString &value2,
00210 UnicodeString &appendTo, UErrorCode &errorCode) const;
00211
00231 UnicodeString &formatAndAppend(
00232 const UnicodeString *const *values, int32_t valuesLength,
00233 UnicodeString &appendTo,
00234 int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const;
00235
00257 UnicodeString &formatAndReplace(
00258 const UnicodeString *const *values, int32_t valuesLength,
00259 UnicodeString &result,
00260 int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const;
00261
00267 UnicodeString getTextWithNoArguments() const {
00268 return getTextWithNoArguments(
00269 compiledPattern.getBuffer(),
00270 compiledPattern.length(),
00271 nullptr,
00272 0);
00273 }
00274
00275 #ifndef U_HIDE_INTERNAL_API
00276
00291 UnicodeString getTextWithNoArguments(int32_t *offsets, int32_t offsetsLength) const {
00292 return getTextWithNoArguments(
00293 compiledPattern.getBuffer(),
00294 compiledPattern.length(),
00295 offsets,
00296 offsetsLength);
00297 }
00298 #endif // U_HIDE_INTERNAL_API
00299
00300 private:
00310 UnicodeString compiledPattern;
00311
00312 static inline int32_t getArgumentLimit(const char16_t *compiledPattern,
00313 int32_t compiledPatternLength) {
00314 return compiledPatternLength == 0 ? 0 : compiledPattern[0];
00315 }
00316
00317 static UnicodeString getTextWithNoArguments(
00318 const char16_t *compiledPattern,
00319 int32_t compiledPatternLength,
00320 int32_t *offsets,
00321 int32_t offsetsLength);
00322
00323 static UnicodeString &format(
00324 const char16_t *compiledPattern, int32_t compiledPatternLength,
00325 const UnicodeString *const *values,
00326 UnicodeString &result, const UnicodeString *resultCopy, UBool forbidResultAsValue,
00327 int32_t *offsets, int32_t offsetsLength,
00328 UErrorCode &errorCode);
00329
00330
00331 friend class number::impl::SimpleModifier;
00332 };
00333
00334 U_NAMESPACE_END
00335
00336 #endif // __SIMPLEFORMATTER_H__