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