number_skeletons.h [plain text]
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#ifndef __SOURCE_NUMBER_SKELETONS_H__
#define __SOURCE_NUMBER_SKELETONS_H__
#include "number_types.h"
#include "numparse_types.h"
#include "unicode/ucharstrie.h"
using icu::numparse::impl::StringSegment;
U_NAMESPACE_BEGIN namespace number {
namespace impl {
struct SeenMacroProps;
namespace skeleton {
enum ParseState {
STATE_NULL,
STATE_SCIENTIFIC,
STATE_FRACTION_PRECISION,
STATE_INCREMENT_PRECISION,
STATE_MEASURE_UNIT,
STATE_PER_MEASURE_UNIT,
STATE_CURRENCY_UNIT,
STATE_INTEGER_WIDTH,
STATE_NUMBERING_SYSTEM,
STATE_SCALE,
};
enum StemEnum {
STEM_COMPACT_SHORT,
STEM_COMPACT_LONG,
STEM_SCIENTIFIC,
STEM_ENGINEERING,
STEM_NOTATION_SIMPLE,
STEM_BASE_UNIT,
STEM_PERCENT,
STEM_PERMILLE,
STEM_PRECISION_INTEGER,
STEM_PRECISION_UNLIMITED,
STEM_PRECISION_CURRENCY_STANDARD,
STEM_PRECISION_CURRENCY_CASH,
STEM_ROUNDING_MODE_CEILING,
STEM_ROUNDING_MODE_FLOOR,
STEM_ROUNDING_MODE_DOWN,
STEM_ROUNDING_MODE_UP,
STEM_ROUNDING_MODE_HALF_EVEN,
STEM_ROUNDING_MODE_HALF_DOWN,
STEM_ROUNDING_MODE_HALF_UP,
STEM_ROUNDING_MODE_UNNECESSARY,
STEM_GROUP_OFF,
STEM_GROUP_MIN2,
STEM_GROUP_AUTO,
STEM_GROUP_ON_ALIGNED,
STEM_GROUP_THOUSANDS,
STEM_LATIN,
STEM_UNIT_WIDTH_NARROW,
STEM_UNIT_WIDTH_SHORT,
STEM_UNIT_WIDTH_FULL_NAME,
STEM_UNIT_WIDTH_ISO_CODE,
STEM_UNIT_WIDTH_HIDDEN,
STEM_SIGN_AUTO,
STEM_SIGN_ALWAYS,
STEM_SIGN_NEVER,
STEM_SIGN_ACCOUNTING,
STEM_SIGN_ACCOUNTING_ALWAYS,
STEM_SIGN_EXCEPT_ZERO,
STEM_SIGN_ACCOUNTING_EXCEPT_ZERO,
STEM_DECIMAL_AUTO,
STEM_DECIMAL_ALWAYS,
STEM_PRECISION_INCREMENT,
STEM_MEASURE_UNIT,
STEM_PER_MEASURE_UNIT,
STEM_CURRENCY,
STEM_INTEGER_WIDTH,
STEM_NUMBERING_SYSTEM,
STEM_SCALE,
};
UnlocalizedNumberFormatter create(const UnicodeString& skeletonString, UErrorCode& status);
UnicodeString generate(const MacroProps& macros, UErrorCode& status);
MacroProps parseSkeleton(const UnicodeString& skeletonString, UErrorCode& status);
ParseState parseStem(const StringSegment& segment, const UCharsTrie& stemTrie, SeenMacroProps& seen,
MacroProps& macros, UErrorCode& status);
ParseState
parseOption(ParseState stem, const StringSegment& segment, MacroProps& macros, UErrorCode& status);
}
namespace stem_to_object {
Notation notation(skeleton::StemEnum stem);
MeasureUnit unit(skeleton::StemEnum stem);
Precision precision(skeleton::StemEnum stem);
UNumberFormatRoundingMode roundingMode(skeleton::StemEnum stem);
UGroupingStrategy groupingStrategy(skeleton::StemEnum stem);
UNumberUnitWidth unitWidth(skeleton::StemEnum stem);
UNumberSignDisplay signDisplay(skeleton::StemEnum stem);
UNumberDecimalSeparatorDisplay decimalSeparatorDisplay(skeleton::StemEnum stem);
}
namespace enum_to_stem_string {
void roundingMode(UNumberFormatRoundingMode value, UnicodeString& sb);
void groupingStrategy(UGroupingStrategy value, UnicodeString& sb);
void unitWidth(UNumberUnitWidth value, UnicodeString& sb);
void signDisplay(UNumberSignDisplay value, UnicodeString& sb);
void decimalSeparatorDisplay(UNumberDecimalSeparatorDisplay value, UnicodeString& sb);
}
namespace blueprint_helpers {
bool parseExponentWidthOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void generateExponentWidthOption(int32_t minExponentDigits, UnicodeString& sb, UErrorCode& status);
bool parseExponentSignOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void parseCurrencyOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void generateCurrencyOption(const CurrencyUnit& currency, UnicodeString& sb, UErrorCode& status);
void parseMeasureUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void generateMeasureUnitOption(const MeasureUnit& measureUnit, UnicodeString& sb, UErrorCode& status);
void parseMeasurePerUnitOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void parseFractionStem(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void generateFractionStem(int32_t minFrac, int32_t maxFrac, UnicodeString& sb, UErrorCode& status);
void parseDigitsStem(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void generateDigitsStem(int32_t minSig, int32_t maxSig, UnicodeString& sb, UErrorCode& status);
bool parseFracSigOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void parseIncrementOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void
generateIncrementOption(double increment, int32_t trailingZeros, UnicodeString& sb, UErrorCode& status);
void parseIntegerWidthOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void generateIntegerWidthOption(int32_t minInt, int32_t maxInt, UnicodeString& sb, UErrorCode& status);
void parseNumberingSystemOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void generateNumberingSystemOption(const NumberingSystem& ns, UnicodeString& sb, UErrorCode& status);
void parseScaleOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status);
void generateScaleOption(int32_t magnitude, const DecNum* arbitrary, UnicodeString& sb,
UErrorCode& status);
}
class GeneratorHelpers {
public:
static void generateSkeleton(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
private:
static bool notation(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool unit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool perUnit(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool precision(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool roundingMode(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool grouping(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool integerWidth(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool symbols(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool unitWidth(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool sign(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool decimal(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
static bool scale(const MacroProps& macros, UnicodeString& sb, UErrorCode& status);
};
struct SeenMacroProps {
bool notation = false;
bool unit = false;
bool perUnit = false;
bool precision = false;
bool roundingMode = false;
bool grouper = false;
bool padder = false;
bool integerWidth = false;
bool symbols = false;
bool unitWidth = false;
bool sign = false;
bool decimal = false;
bool scale = false;
};
} } U_NAMESPACE_END
#endif //__SOURCE_NUMBER_SKELETONS_H__
#endif