File indexing completed on 2026-01-04 10:00:25
0001
0002
0003
0004 #ifndef __SIMPLENUMBERFORMATTERH__
0005 #define __SIMPLENUMBERFORMATTERH__
0006
0007 #include "unicode/utypes.h"
0008
0009 #if U_SHOW_CPLUSPLUS_API
0010
0011 #if !UCONFIG_NO_FORMATTING
0012
0013 #include "unicode/dcfmtsym.h"
0014 #include "unicode/usimplenumberformatter.h"
0015 #include "unicode/formattednumber.h"
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 U_NAMESPACE_BEGIN
0032
0033
0034 class SimpleDateFormat;
0035
0036 namespace number {
0037
0038
0039 namespace impl {
0040 class UFormattedNumberData;
0041 struct SimpleMicroProps;
0042 class AdoptingSignumModifierStore;
0043 }
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 class U_I18N_API SimpleNumber : public UMemory {
0054 public:
0055
0056
0057
0058
0059
0060 static SimpleNumber forInt64(int64_t value, UErrorCode& status);
0061
0062
0063
0064
0065
0066
0067
0068
0069 void multiplyByPowerOfTen(int32_t power, UErrorCode& status);
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079 void roundTo(int32_t power, UNumberFormatRoundingMode roundingMode, UErrorCode& status);
0080
0081 #ifndef U_HIDE_DRAFT_API
0082
0083
0084
0085
0086
0087 void setMaximumIntegerDigits(uint32_t maximumIntegerDigits, UErrorCode& status);
0088 #endif
0089
0090
0091
0092
0093
0094
0095 void setMinimumIntegerDigits(uint32_t minimumIntegerDigits, UErrorCode& status);
0096
0097
0098
0099
0100
0101
0102 void setMinimumFractionDigits(uint32_t minimumFractionDigits, UErrorCode& status);
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 void setSign(USimpleNumberSign sign, UErrorCode& status);
0114
0115
0116
0117
0118
0119
0120
0121
0122 SimpleNumber() = default;
0123
0124
0125
0126
0127
0128
0129 ~SimpleNumber() {
0130 cleanup();
0131 }
0132
0133
0134
0135
0136
0137
0138 SimpleNumber(SimpleNumber&& other) noexcept {
0139 fData = other.fData;
0140 fSign = other.fSign;
0141 other.fData = nullptr;
0142 }
0143
0144
0145
0146
0147
0148
0149 SimpleNumber& operator=(SimpleNumber&& other) noexcept {
0150 cleanup();
0151 fData = other.fData;
0152 fSign = other.fSign;
0153 other.fData = nullptr;
0154 return *this;
0155 }
0156
0157 private:
0158 SimpleNumber(impl::UFormattedNumberData* data, UErrorCode& status);
0159 SimpleNumber(const SimpleNumber&) = delete;
0160 SimpleNumber& operator=(const SimpleNumber&) = delete;
0161
0162 void cleanup();
0163
0164 impl::UFormattedNumberData* fData = nullptr;
0165 USimpleNumberSign fSign = UNUM_SIMPLE_NUMBER_NO_SIGN;
0166
0167 friend class SimpleNumberFormatter;
0168
0169
0170 friend class icu::SimpleDateFormat;
0171 };
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184 class U_I18N_API SimpleNumberFormatter : public UMemory {
0185 public:
0186
0187
0188
0189
0190
0191 static SimpleNumberFormatter forLocale(
0192 const icu::Locale &locale,
0193 UErrorCode &status);
0194
0195
0196
0197
0198
0199
0200 static SimpleNumberFormatter forLocaleAndGroupingStrategy(
0201 const icu::Locale &locale,
0202 UNumberGroupingStrategy groupingStrategy,
0203 UErrorCode &status);
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 static SimpleNumberFormatter forLocaleAndSymbolsAndGroupingStrategy(
0214 const icu::Locale &locale,
0215 const DecimalFormatSymbols &symbols,
0216 UNumberGroupingStrategy groupingStrategy,
0217 UErrorCode &status);
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227 FormattedNumber format(SimpleNumber value, UErrorCode &status) const;
0228
0229
0230
0231
0232
0233
0234
0235
0236 FormattedNumber formatInt64(int64_t value, UErrorCode &status) const {
0237 return format(SimpleNumber::forInt64(value, status), status);
0238 }
0239
0240 #ifndef U_HIDE_INTERNAL_API
0241
0242
0243
0244
0245 void formatImpl(impl::UFormattedNumberData* data, USimpleNumberSign sign, UErrorCode& status) const;
0246 #endif
0247
0248
0249
0250
0251
0252
0253 ~SimpleNumberFormatter() {
0254 cleanup();
0255 }
0256
0257
0258
0259
0260
0261
0262 SimpleNumberFormatter() = default;
0263
0264
0265
0266
0267
0268
0269 SimpleNumberFormatter(SimpleNumberFormatter&& other) noexcept {
0270 fGroupingStrategy = other.fGroupingStrategy;
0271 fOwnedSymbols = other.fOwnedSymbols;
0272 fMicros = other.fMicros;
0273 fPatternModifier = other.fPatternModifier;
0274 other.fOwnedSymbols = nullptr;
0275 other.fMicros = nullptr;
0276 other.fPatternModifier = nullptr;
0277 }
0278
0279
0280
0281
0282
0283
0284 SimpleNumberFormatter& operator=(SimpleNumberFormatter&& other) noexcept {
0285 cleanup();
0286 fGroupingStrategy = other.fGroupingStrategy;
0287 fOwnedSymbols = other.fOwnedSymbols;
0288 fMicros = other.fMicros;
0289 fPatternModifier = other.fPatternModifier;
0290 other.fOwnedSymbols = nullptr;
0291 other.fMicros = nullptr;
0292 other.fPatternModifier = nullptr;
0293 return *this;
0294 }
0295
0296 private:
0297 void initialize(
0298 const icu::Locale &locale,
0299 const DecimalFormatSymbols &symbols,
0300 UNumberGroupingStrategy groupingStrategy,
0301 UErrorCode &status);
0302
0303 void cleanup();
0304
0305 SimpleNumberFormatter(const SimpleNumberFormatter&) = delete;
0306
0307 SimpleNumberFormatter& operator=(const SimpleNumberFormatter&) = delete;
0308
0309 UNumberGroupingStrategy fGroupingStrategy = UNUM_GROUPING_AUTO;
0310
0311
0312 DecimalFormatSymbols* fOwnedSymbols = nullptr;
0313 impl::SimpleMicroProps* fMicros = nullptr;
0314 impl::AdoptingSignumModifierStore* fPatternModifier = nullptr;
0315 };
0316
0317
0318 }
0319 U_NAMESPACE_END
0320
0321 #endif
0322
0323 #endif
0324
0325 #endif
0326