2017-09-27 00:25:20 +00:00
|
|
|
// © 2017 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
|
|
|
|
2017-10-04 22:51:06 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2018-04-23 23:02:26 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2017-09-27 05:31:57 +00:00
|
|
|
#ifndef __NUMBER_UTILS_H__
|
|
|
|
#define __NUMBER_UTILS_H__
|
2017-09-27 00:25:20 +00:00
|
|
|
|
|
|
|
#include "unicode/numberformatter.h"
|
|
|
|
#include "number_types.h"
|
|
|
|
#include "number_decimalquantity.h"
|
|
|
|
#include "number_scientific.h"
|
|
|
|
#include "number_patternstring.h"
|
|
|
|
#include "number_modifiers.h"
|
2018-03-15 10:08:26 +00:00
|
|
|
#include "number_multiplier.h"
|
2018-05-05 06:32:29 +00:00
|
|
|
#include "number_roundingutils.h"
|
2018-04-05 21:54:04 +00:00
|
|
|
#include "decNumber.h"
|
|
|
|
#include "charstr.h"
|
2017-09-27 00:25:20 +00:00
|
|
|
|
2018-05-25 07:27:56 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
namespace number {
|
2017-09-27 00:25:20 +00:00
|
|
|
namespace impl {
|
|
|
|
|
2018-04-14 08:10:45 +00:00
|
|
|
enum CldrPatternStyle {
|
|
|
|
CLDR_PATTERN_STYLE_DECIMAL,
|
|
|
|
CLDR_PATTERN_STYLE_CURRENCY,
|
|
|
|
CLDR_PATTERN_STYLE_ACCOUNTING,
|
|
|
|
CLDR_PATTERN_STYLE_PERCENT,
|
|
|
|
CLDR_PATTERN_STYLE_SCIENTIFIC,
|
|
|
|
CLDR_PATTERN_STYLE_COUNT,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Namespace for naked functions
|
|
|
|
namespace utils {
|
|
|
|
|
2018-02-08 08:49:50 +00:00
|
|
|
inline int32_t insertDigitFromSymbols(NumberStringBuilder& output, int32_t index, int8_t digit,
|
|
|
|
const DecimalFormatSymbols& symbols, Field field,
|
|
|
|
UErrorCode& status) {
|
|
|
|
if (symbols.getCodePointZero() != -1) {
|
|
|
|
return output.insertCodePoint(index, symbols.getCodePointZero() + digit, field, status);
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
2018-02-08 08:49:50 +00:00
|
|
|
return output.insert(index, symbols.getConstDigitSymbol(digit), field, status);
|
2017-09-27 00:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 07:51:52 +00:00
|
|
|
inline bool unitIsCurrency(const MeasureUnit& unit) {
|
|
|
|
return uprv_strcmp("currency", unit.getType()) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool unitIsNoUnit(const MeasureUnit& unit) {
|
|
|
|
return uprv_strcmp("none", unit.getType()) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool unitIsPercent(const MeasureUnit& unit) {
|
|
|
|
return uprv_strcmp("percent", unit.getSubtype()) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool unitIsPermille(const MeasureUnit& unit) {
|
|
|
|
return uprv_strcmp("permille", unit.getSubtype()) == 0;
|
|
|
|
}
|
|
|
|
|
2018-04-14 08:10:45 +00:00
|
|
|
// NOTE: In Java, this method is in NumberFormat.java
|
|
|
|
const char16_t*
|
|
|
|
getPatternForStyle(const Locale& locale, const char* nsName, CldrPatternStyle style, UErrorCode& status);
|
|
|
|
|
2018-05-25 17:57:30 +00:00
|
|
|
/**
|
|
|
|
* Computes the plural form for this number based on the specified set of rules.
|
|
|
|
*
|
|
|
|
* @param rules A {@link PluralRules} object representing the set of rules.
|
|
|
|
* @return The {@link StandardPlural} according to the PluralRules. If the plural form is not in
|
|
|
|
* the set of standard plurals, {@link StandardPlural#OTHER} is returned instead.
|
|
|
|
*/
|
|
|
|
inline StandardPlural::Form getStandardPlural(const PluralRules *rules,
|
|
|
|
const IFixedDecimal &fdec) {
|
|
|
|
if (rules == nullptr) {
|
|
|
|
// Fail gracefully if the user didn't provide a PluralRules
|
|
|
|
return StandardPlural::Form::OTHER;
|
|
|
|
} else {
|
|
|
|
UnicodeString ruleString = rules->select(fdec);
|
|
|
|
return StandardPlural::orOtherFromString(ruleString);
|
2018-04-05 21:54:04 +00:00
|
|
|
}
|
2018-05-25 17:57:30 +00:00
|
|
|
}
|
2018-04-05 21:54:04 +00:00
|
|
|
|
2018-05-25 17:57:30 +00:00
|
|
|
} // namespace utils
|
2018-04-05 21:54:04 +00:00
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
} // namespace impl
|
|
|
|
} // namespace number
|
2018-05-25 17:57:30 +00:00
|
|
|
|
2017-09-27 00:25:20 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2017-09-27 05:31:57 +00:00
|
|
|
#endif //__NUMBER_UTILS_H__
|
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|