Loading...
Searching...
No Matches
simpleformatter.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
* Copyright (C) 2014-2016, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* simpleformatter.h
*/
#ifndef __SIMPLEFORMATTER_H__
#define __SIMPLEFORMATTER_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#include "unicode/unistr.h"
U_NAMESPACE_BEGIN
// Forward declaration:
namespace number::impl {
class SimpleModifier;
}
class U_COMMON_API SimpleFormatter final : public UMemory {
public:
SimpleFormatter() : compiledPattern(static_cast<char16_t>(0)) {}
SimpleFormatter(const UnicodeString& pattern, UErrorCode &errorCode) {
applyPattern(pattern, errorCode);
}
SimpleFormatter(const UnicodeString& pattern, int32_t min, int32_t max,
UErrorCode &errorCode) {
applyPatternMinMaxArguments(pattern, min, max, errorCode);
}
SimpleFormatter(const SimpleFormatter& other)
: compiledPattern(other.compiledPattern) {}
SimpleFormatter &operator=(const SimpleFormatter& other);
~SimpleFormatter();
UBool applyPattern(const UnicodeString &pattern, UErrorCode &errorCode) {
return applyPatternMinMaxArguments(pattern, 0, INT32_MAX, errorCode);
}
UBool applyPatternMinMaxArguments(const UnicodeString &pattern,
int32_t min, int32_t max, UErrorCode &errorCode);
int32_t getArgumentLimit() const {
return getArgumentLimit(compiledPattern.getBuffer(), compiledPattern.length());
}
UnicodeString &format(
const UnicodeString &value0,
UnicodeString &appendTo, UErrorCode &errorCode) const;
UnicodeString &format(
const UnicodeString &value0,
const UnicodeString &value1,
UnicodeString &appendTo, UErrorCode &errorCode) const;
UnicodeString &format(
const UnicodeString &value0,
const UnicodeString &value1,
const UnicodeString &value2,
UnicodeString &appendTo, UErrorCode &errorCode) const;
UnicodeString &formatAndAppend(
const UnicodeString *const *values, int32_t valuesLength,
UnicodeString &appendTo,
int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const;
UnicodeString &formatAndReplace(
const UnicodeString *const *values, int32_t valuesLength,
UnicodeString &result,
int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const;
UnicodeString getTextWithNoArguments() const {
return getTextWithNoArguments(
compiledPattern.getBuffer(),
compiledPattern.length(),
nullptr,
0);
}
#ifndef U_HIDE_INTERNAL_API
UnicodeString getTextWithNoArguments(int32_t *offsets, int32_t offsetsLength) const {
return getTextWithNoArguments(
compiledPattern.getBuffer(),
compiledPattern.length(),
offsets,
offsetsLength);
}
#endif // U_HIDE_INTERNAL_API
private:
UnicodeString compiledPattern;
static inline int32_t getArgumentLimit(const char16_t *compiledPattern,
int32_t compiledPatternLength) {
return compiledPatternLength == 0 ? 0 : compiledPattern[0];
}
static UnicodeString getTextWithNoArguments(
const char16_t *compiledPattern,
int32_t compiledPatternLength,
int32_t *offsets,
int32_t offsetsLength);
static UnicodeString &format(
const char16_t *compiledPattern, int32_t compiledPatternLength,
const UnicodeString *const *values,
UnicodeString &result, const UnicodeString *resultCopy, UBool forbidResultAsValue,
int32_t *offsets, int32_t offsetsLength,
UErrorCode &errorCode);
// Give access to internals to SimpleModifier for number formatting
friend class number::impl::SimpleModifier;
};
U_NAMESPACE_END
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __SIMPLEFORMATTER_H__
icu::SimpleFormatter::getTextWithNoArguments
UnicodeString getTextWithNoArguments() const
Returns the pattern text with none of the arguments.
Definition simpleformatter.h:268
icu::SimpleFormatter::format
UnicodeString & format(const UnicodeString &value0, UnicodeString &appendTo, UErrorCode &errorCode) const
Formats the given value, appending to the appendTo builder.
icu::SimpleFormatter::operator=
SimpleFormatter & operator=(const SimpleFormatter &other)
Assignment operator.
icu::SimpleFormatter::applyPatternMinMaxArguments
UBool applyPatternMinMaxArguments(const UnicodeString &pattern, int32_t min, int32_t max, UErrorCode &errorCode)
Changes this object according to the new pattern.
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:95
icu::SimpleFormatter::getArgumentLimit
int32_t getArgumentLimit() const
Definition simpleformatter.h:155
icu::SimpleFormatter::~SimpleFormatter
~SimpleFormatter()
Destructor.
icu::SimpleFormatter::SimpleFormatter
SimpleFormatter()
Default constructor.
Definition simpleformatter.h:66
icu::SimpleFormatter::formatAndAppend
UnicodeString & formatAndAppend(const UnicodeString *const *values, int32_t valuesLength, UnicodeString &appendTo, int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const
Formats the given values, appending to the appendTo string.
icu::SimpleFormatter::formatAndReplace
UnicodeString & formatAndReplace(const UnicodeString *const *values, int32_t valuesLength, UnicodeString &result, int32_t *offsets, int32_t offsetsLength, UErrorCode &errorCode) const
Formats the given values, replacing the contents of the result string.
icu::SimpleFormatter::format
UnicodeString & format(const UnicodeString &value0, const UnicodeString &value1, const UnicodeString &value2, UnicodeString &appendTo, UErrorCode &errorCode) const
Formats the given values, appending to the appendTo builder.
icu::SimpleFormatter::format
UnicodeString & format(const UnicodeString &value0, const UnicodeString &value1, UnicodeString &appendTo, UErrorCode &errorCode) const
Formats the given values, appending to the appendTo builder.
icu::SimpleFormatter::applyPattern
UBool applyPattern(const UnicodeString &pattern, UErrorCode &errorCode)
Changes this object according to the new pattern.
Definition simpleformatter.h:129
icu::SimpleFormatter::SimpleFormatter
SimpleFormatter(const SimpleFormatter &other)
Copy constructor.
Definition simpleformatter.h:104
icu::SimpleFormatter::SimpleFormatter
SimpleFormatter(const UnicodeString &pattern, UErrorCode &errorCode)
Constructs a formatter from the pattern string.
Definition simpleformatter.h:77
icu::SimpleFormatter::getTextWithNoArguments
UnicodeString getTextWithNoArguments(int32_t *offsets, int32_t offsetsLength) const
Returns the pattern text with none of the arguments.
Definition simpleformatter.h:292
icu::UMemory
UMemory is the common ICU base class.
Definition uobject.h:115
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
INT32_MAX
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition umachine.h:208
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
unistr.h
C++ API: Unicode String.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
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:315