| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
#ifndef __SIMPLENUMBERFORMATTERH__ |
| 5 |
#define __SIMPLENUMBERFORMATTERH__ |
| 6 |
|
| 7 |
#include "unicode/utypes.h" |
| 8 |
|
| 9 |
#if U_SHOW_CPLUSPLUS_API |
| 10 |
|
| 11 |
#if !UCONFIG_NO_FORMATTING |
| 12 |
|
| 13 |
#include "unicode/dcfmtsym.h" |
| 14 |
#include "unicode/usimplenumberformatter.h" |
| 15 |
#include "unicode/formattednumber.h" |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
s)); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
U_NAMESPACE_BEGIN |
| 32 |
|
| 33 |
|
| 34 |
class SimpleDateFormat; |
| 35 |
|
| 36 |
namespace number { |
| 37 |
|
| 38 |
|
| 39 |
namespace impl { |
| 40 |
class UFormattedNumberData; |
| 41 |
struct SimpleMicroProps; |
| 42 |
class AdoptingSignumModifierStore; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
class U_I18N_API SimpleNumber : public UMemory { |
| 54 |
public: |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
static SimpleNumber forInt64(int64_t value, UErrorCode& status); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
void multiplyByPowerOfTen(int32_t power, UErrorCode& status); |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
void roundTo(int32_t power, UNumberFormatRoundingMode roundingMode, UErrorCode& status); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
void setMaximumIntegerDigits(uint32_t maximumIntegerDigits, UErrorCode& status); |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
void setMinimumIntegerDigits(uint32_t minimumIntegerDigits, UErrorCode& status); |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
void setMinimumFractionDigits(uint32_t minimumFractionDigits, UErrorCode& status); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
void setSign(USimpleNumberSign sign, UErrorCode& status); |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
SimpleNumber() = default; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
~SimpleNumber() { |
| 128 |
cleanup(); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
SimpleNumber(SimpleNumber&& other) noexcept { |
| 137 |
fData = other.fData; |
| 138 |
fSign = other.fSign; |
| 139 |
other.fData = nullptr; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
SimpleNumber& operator=(SimpleNumber&& other) noexcept { |
| 148 |
cleanup(); |
| 149 |
fData = other.fData; |
| 150 |
fSign = other.fSign; |
| 151 |
other.fData = nullptr; |
| 152 |
return *this; |
| 153 |
} |
| 154 |
|
| 155 |
private: |
| 156 |
SimpleNumber(impl::UFormattedNumberData* data, UErrorCode& status); |
| 157 |
SimpleNumber(const SimpleNumber&) = delete; |
| 158 |
SimpleNumber& operator=(const SimpleNumber&) = delete; |
| 159 |
|
| 160 |
void cleanup(); |
| 161 |
|
| 162 |
impl::UFormattedNumberData* fData = nullptr; |
| 163 |
USimpleNumberSign fSign = UNUM_SIMPLE_NUMBER_NO_SIGN; |
| 164 |
|
| 165 |
friend class SimpleNumberFormatter; |
| 166 |
|
| 167 |
|
| 168 |
friend class icu::SimpleDateFormat; |
| 169 |
}; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
class U_I18N_API SimpleNumberFormatter : public UMemory { |
| 183 |
public: |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
static SimpleNumberFormatter forLocale( |
| 190 |
const icu::Locale &locale, |
| 191 |
UErrorCode &status); |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
static SimpleNumberFormatter forLocaleAndGroupingStrategy( |
| 199 |
const icu::Locale &locale, |
| 200 |
UNumberGroupingStrategy groupingStrategy, |
| 201 |
UErrorCode &status); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
static SimpleNumberFormatter forLocaleAndSymbolsAndGroupingStrategy( |
| 212 |
const icu::Locale &locale, |
| 213 |
const DecimalFormatSymbols &symbols, |
| 214 |
UNumberGroupingStrategy groupingStrategy, |
| 215 |
UErrorCode &status); |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
FormattedNumber format(SimpleNumber value, UErrorCode &status) const; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
FormattedNumber formatInt64(int64_t value, UErrorCode &status) const { |
| 235 |
return format(SimpleNumber::forInt64(value, status), status); |
| 236 |
} |
| 237 |
|
| 238 |
#ifndef U_HIDE_INTERNAL_API |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
void formatImpl(impl::UFormattedNumberData* data, USimpleNumberSign sign, UErrorCode& status) const; |
| 244 |
#endif |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
~SimpleNumberFormatter() { |
| 252 |
cleanup(); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
SimpleNumberFormatter() = default; |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
SimpleNumberFormatter(SimpleNumberFormatter&& other) noexcept { |
| 268 |
fGroupingStrategy = other.fGroupingStrategy; |
| 269 |
fOwnedSymbols = other.fOwnedSymbols; |
| 270 |
fMicros = other.fMicros; |
| 271 |
fPatternModifier = other.fPatternModifier; |
| 272 |
other.fOwnedSymbols = nullptr; |
| 273 |
other.fMicros = nullptr; |
| 274 |
other.fPatternModifier = nullptr; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
SimpleNumberFormatter& operator=(SimpleNumberFormatter&& other) noexcept { |
| 283 |
cleanup(); |
| 284 |
fGroupingStrategy = other.fGroupingStrategy; |
| 285 |
fOwnedSymbols = other.fOwnedSymbols; |
| 286 |
fMicros = other.fMicros; |
| 287 |
fPatternModifier = other.fPatternModifier; |
| 288 |
other.fOwnedSymbols = nullptr; |
| 289 |
other.fMicros = nullptr; |
| 290 |
other.fPatternModifier = nullptr; |
| 291 |
return *this; |
| 292 |
} |
| 293 |
|
| 294 |
private: |
| 295 |
void initialize( |
| 296 |
const icu::Locale &locale, |
| 297 |
const DecimalFormatSymbols &symbols, |
| 298 |
UNumberGroupingStrategy groupingStrategy, |
| 299 |
UErrorCode &status); |
| 300 |
|
| 301 |
void cleanup(); |
| 302 |
|
| 303 |
SimpleNumberFormatter(const SimpleNumberFormatter&) = delete; |
| 304 |
|
| 305 |
SimpleNumberFormatter& operator=(const SimpleNumberFormatter&) = delete; |
| 306 |
|
| 307 |
UNumberGroupingStrategy fGroupingStrategy = UNUM_GROUPING_AUTO; |
| 308 |
|
| 309 |
|
| 310 |
DecimalFormatSymbols* fOwnedSymbols = nullptr; |
| 311 |
impl::SimpleMicroProps* fMicros = nullptr; |
| 312 |
impl::AdoptingSignumModifierStore* fPatternModifier = nullptr; |
| 313 |
}; |
| 314 |
|
| 315 |
|
| 316 |
} |
| 317 |
U_NAMESPACE_END |
| 318 |
|
| 319 |
#endif |
| 320 |
|
| 321 |
#endif |
| 322 |
|
| 323 |
#endif |
| 324 |
|