1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMBER_UTILS_H__
8 #define __NUMBER_UTILS_H__
10 #include "unicode/numberformatter.h"
11 #include "number_types.h"
12 #include "number_decimalquantity.h"
13 #include "number_scientific.h"
14 #include "number_patternstring.h"
15 #include "number_modifiers.h"
16 #include "number_multiplier.h"
17 #include "number_roundingutils.h"
18 #include "decNumber.h"
26 enum CldrPatternStyle
{
27 CLDR_PATTERN_STYLE_DECIMAL
,
28 CLDR_PATTERN_STYLE_CURRENCY
,
29 CLDR_PATTERN_STYLE_ACCOUNTING
,
30 CLDR_PATTERN_STYLE_PERCENT
,
31 CLDR_PATTERN_STYLE_SCIENTIFIC
,
32 CLDR_PATTERN_STYLE_COUNT
,
35 // Namespace for naked functions
38 inline int32_t insertDigitFromSymbols(NumberStringBuilder
& output
, int32_t index
, int8_t digit
,
39 const DecimalFormatSymbols
& symbols
, Field field
,
41 if (symbols
.getCodePointZero() != -1) {
42 return output
.insertCodePoint(index
, symbols
.getCodePointZero() + digit
, field
, status
);
44 return output
.insert(index
, symbols
.getConstDigitSymbol(digit
), field
, status
);
47 inline bool unitIsCurrency(const MeasureUnit
& unit
) {
48 return uprv_strcmp("currency", unit
.getType()) == 0;
51 inline bool unitIsNoUnit(const MeasureUnit
& unit
) {
52 return uprv_strcmp("none", unit
.getType()) == 0;
55 inline bool unitIsPercent(const MeasureUnit
& unit
) {
56 return uprv_strcmp("percent", unit
.getSubtype()) == 0;
59 inline bool unitIsPermille(const MeasureUnit
& unit
) {
60 return uprv_strcmp("permille", unit
.getSubtype()) == 0;
63 // NOTE: In Java, this method is in NumberFormat.java
65 getPatternForStyle(const Locale
& locale
, const char* nsName
, CldrPatternStyle style
, UErrorCode
& status
);
68 * Computes the plural form for this number based on the specified set of rules.
70 * @param rules A {@link PluralRules} object representing the set of rules.
71 * @return The {@link StandardPlural} according to the PluralRules. If the plural form is not in
72 * the set of standard plurals, {@link StandardPlural#OTHER} is returned instead.
74 inline StandardPlural::Form
getStandardPlural(const PluralRules
*rules
,
75 const IFixedDecimal
&fdec
) {
76 if (rules
== nullptr) {
77 // Fail gracefully if the user didn't provide a PluralRules
78 return StandardPlural::Form::OTHER
;
80 UnicodeString ruleString
= rules
->select(fdec
);
81 return StandardPlural::orOtherFromString(ruleString
);
92 #endif //__NUMBER_UTILS_H__
94 #endif /* #if !UCONFIG_NO_FORMATTING */