summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/i18n/number_types.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/icu-small/source/i18n/number_types.h')
-rw-r--r--deps/icu-small/source/i18n/number_types.h92
1 files changed, 44 insertions, 48 deletions
diff --git a/deps/icu-small/source/i18n/number_types.h b/deps/icu-small/source/i18n/number_types.h
index c01765e2ce..57da72f8aa 100644
--- a/deps/icu-small/source/i18n/number_types.h
+++ b/deps/icu-small/source/i18n/number_types.h
@@ -3,7 +3,7 @@
#include "unicode/utypes.h"
-#if !UCONFIG_NO_FORMATTING && !UPRV_INCOMPLETE_CPP11_SUPPORT
+#if !UCONFIG_NO_FORMATTING
#ifndef __NUMBER_TYPES_H__
#define __NUMBER_TYPES_H__
@@ -15,9 +15,9 @@
#include "unicode/utf16.h"
#include "uassert.h"
#include "unicode/platform.h"
+#include "unicode/uniset.h"
-U_NAMESPACE_BEGIN
-namespace number {
+U_NAMESPACE_BEGIN namespace number {
namespace impl {
// Typedef several enums for brevity and for easier comparison to Java.
@@ -39,9 +39,6 @@ static constexpr RoundingMode kDefaultMode = RoundingMode::UNUM_FOUND_HALFEVEN;
// ICU4J Equivalent: Padder.FALLBACK_PADDING_STRING
static constexpr char16_t kFallbackPaddingString[] = u" ";
-// ICU4J Equivalent: NumberFormatterImpl.DEFAULT_CURRENCY
-static constexpr char16_t kDefaultCurrency[] = u"XXX";
-
// Forward declarations:
class Modifier;
@@ -87,35 +84,10 @@ enum AffixPatternType {
};
enum CompactType {
- TYPE_DECIMAL,
- TYPE_CURRENCY
+ TYPE_DECIMAL, TYPE_CURRENCY
};
-// TODO: Should this be moved somewhere else, maybe where other ICU classes can use it?
-// Exported as U_I18N_API because it is a base class for other exported types
-class U_I18N_API CharSequence {
-public:
- virtual ~CharSequence() = default;
-
- virtual int32_t length() const = 0;
-
- virtual char16_t charAt(int32_t index) const = 0;
-
- virtual UChar32 codePointAt(int32_t index) const {
- // Default implementation; can be overridden with a more efficient version
- char16_t leading = charAt(index);
- if (U16_IS_LEAD(leading) && length() > index + 1) {
- char16_t trailing = charAt(index + 1);
- return U16_GET_SUPPLEMENTARY(leading, trailing);
- } else {
- return leading;
- }
- }
-
- virtual UnicodeString toUnicodeString() const = 0;
-};
-
class U_I18N_API AffixPatternProvider {
public:
static const int32_t AFFIX_PLURAL_MASK = 0xff;
@@ -123,12 +95,20 @@ class U_I18N_API AffixPatternProvider {
static const int32_t AFFIX_NEGATIVE_SUBPATTERN = 0x200;
static const int32_t AFFIX_PADDING = 0x400;
- virtual ~AffixPatternProvider() = default;
+ // Convenience compound flags
+ static const int32_t AFFIX_POS_PREFIX = AFFIX_PREFIX;
+ static const int32_t AFFIX_POS_SUFFIX = 0;
+ static const int32_t AFFIX_NEG_PREFIX = AFFIX_PREFIX | AFFIX_NEGATIVE_SUBPATTERN;
+ static const int32_t AFFIX_NEG_SUFFIX = AFFIX_NEGATIVE_SUBPATTERN;
+
+ virtual ~AffixPatternProvider();
virtual char16_t charAt(int flags, int i) const = 0;
virtual int length(int flags) const = 0;
+ virtual UnicodeString getString(int flags) const = 0;
+
virtual bool hasCurrencySign() const = 0;
virtual bool positiveHasPlusSign() const = 0;
@@ -137,7 +117,7 @@ class U_I18N_API AffixPatternProvider {
virtual bool negativeHasMinusSign() const = 0;
- virtual bool containsSymbolType(AffixPatternType, UErrorCode &) const = 0;
+ virtual bool containsSymbolType(AffixPatternType, UErrorCode&) const = 0;
/**
* True if the pattern has a number placeholder like "0" or "#,##0.00"; false if the pattern does not
@@ -159,7 +139,7 @@ class U_I18N_API AffixPatternProvider {
*/
class U_I18N_API Modifier {
public:
- virtual ~Modifier() = default;
+ virtual ~Modifier();
/**
* Apply this Modifier to the string builder.
@@ -173,8 +153,8 @@ class U_I18N_API Modifier {
* formatted.
* @return The number of characters (UTF-16 code units) that were added to the string builder.
*/
- virtual int32_t
- apply(NumberStringBuilder &output, int leftIndex, int rightIndex, UErrorCode &status) const = 0;
+ virtual int32_t apply(NumberStringBuilder& output, int leftIndex, int rightIndex,
+ UErrorCode& status) const = 0;
/**
* Gets the length of the prefix. This information can be used in combination with {@link #apply} to extract the
@@ -187,7 +167,7 @@ class U_I18N_API Modifier {
/**
* Returns the number of code points in the modifier, prefix plus suffix.
*/
- virtual int32_t getCodePointCount(UErrorCode &status) const = 0;
+ virtual int32_t getCodePointCount(UErrorCode& status) const = 0;
/**
* Whether this modifier is strong. If a modifier is strong, it should always be applied immediately and not allowed
@@ -219,7 +199,7 @@ class U_I18N_API Modifier {
*/
class U_I18N_API MicroPropsGenerator {
public:
- virtual ~MicroPropsGenerator() = default;
+ virtual ~MicroPropsGenerator();
/**
* Considers the given {@link DecimalQuantity}, optionally mutates it, and returns a {@link MicroProps}.
@@ -230,7 +210,8 @@ class U_I18N_API MicroPropsGenerator {
* The MicroProps instance to populate.
* @return A MicroProps instance resolved for the quantity.
*/
- virtual void processQuantity(DecimalQuantity& quantity, MicroProps& micros, UErrorCode& status) const = 0;
+ virtual void processQuantity(DecimalQuantity& quantity, MicroProps& micros,
+ UErrorCode& status) const = 0;
};
/**
@@ -238,7 +219,7 @@ class U_I18N_API MicroPropsGenerator {
*/
class MultiplierProducer {
public:
- virtual ~MultiplierProducer() = default;
+ virtual ~MultiplierProducer();
/**
* Maps a magnitude to a multiplier in powers of ten. For example, in compact notation in English, a magnitude of 5
@@ -255,24 +236,31 @@ class MultiplierProducer {
template<typename T>
class U_I18N_API NullableValue {
public:
- NullableValue() : fNull(true) {}
+ NullableValue()
+ : fNull(true) {}
- NullableValue(const NullableValue<T> &other) = default;
+ NullableValue(const NullableValue<T>& other) = default;
- explicit NullableValue(const T &other) {
+ explicit NullableValue(const T& other) {
fValue = other;
fNull = false;
}
- NullableValue<T> &operator=(const NullableValue<T> &other) = default;
+ NullableValue<T>& operator=(const NullableValue<T>& other) {
+ fNull = other.fNull;
+ if (!fNull) {
+ fValue = other.fValue;
+ }
+ return *this;
+ }
- NullableValue<T> &operator=(const T &other) {
+ NullableValue<T>& operator=(const T& other) {
fValue = other;
fNull = false;
return *this;
}
- bool operator==(const NullableValue &other) const {
+ bool operator==(const NullableValue& other) const {
// "fValue == other.fValue" returns UBool, not bool (causes compiler warnings)
return fNull ? other.fNull : (other.fNull ? false : static_cast<bool>(fValue == other.fValue));
}
@@ -286,13 +274,21 @@ class U_I18N_API NullableValue {
return fNull;
}
- T get(UErrorCode &status) const {
+ T get(UErrorCode& status) const {
if (fNull) {
status = U_UNDEFINED_VARIABLE;
}
return fValue;
}
+ T getNoError() const {
+ return fValue;
+ }
+
+ T getOrDefault(T defaultValue) const {
+ return fNull ? defaultValue : fValue;
+ }
+
private:
bool fNull;
T fValue;