#include "nfrs.h"
#if U_HAVE_RBNF
#include "unicode/uchar.h"
#include "nfrule.h"
#include "nfrlist.h"
#include "patternprops.h"
#include "putilimp.h"
#ifdef RBNF_DEBUG
#include "cmemory.h"
#endif
enum { … };
U_NAMESPACE_BEGIN
#if 0
static int64_t
util_lcm(int64_t x, int64_t y)
{
x.abs();
y.abs();
if (x == 0 || y == 0) {
return 0;
} else {
do {
if (x < y) {
int64_t t = x; x = y; y = t;
}
x -= y * (x/y);
} while (x != 0);
return y;
}
}
#else
static int64_t
util_lcm(int64_t x, int64_t y)
{ … }
#endif
static const char16_t gPercent = …;
static const char16_t gColon = …;
static const char16_t gSemicolon = …;
static const char16_t gLineFeed = …;
static const char16_t gPercentPercent[] = …;
static const char16_t gNoparse[] = …;
NFRuleSet::NFRuleSet(RuleBasedNumberFormat *_owner, UnicodeString* descriptions, int32_t index, UErrorCode& status)
: … { … }
void
NFRuleSet::parseRules(UnicodeString& description, UErrorCode& status)
{ … }
void NFRuleSet::setNonNumericalRule(NFRule *rule) { … }
void NFRuleSet::setBestFractionRule(int32_t originalIndex, NFRule *newRule, UBool rememberRule) { … }
NFRuleSet::~NFRuleSet()
{ … }
static UBool
util_equalRules(const NFRule* rule1, const NFRule* rule2)
{ … }
bool
NFRuleSet::operator==(const NFRuleSet& rhs) const
{ … }
void
NFRuleSet::setDecimalFormatSymbols(const DecimalFormatSymbols &newSymbols, UErrorCode& status) { … }
#define RECURSION_LIMIT …
void
NFRuleSet::format(int64_t number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const
{ … }
void
NFRuleSet::format(double number, UnicodeString& toAppendTo, int32_t pos, int32_t recursionCount, UErrorCode& status) const
{ … }
const NFRule*
NFRuleSet::findDoubleRule(double number) const
{ … }
const NFRule *
NFRuleSet::findNormalRule(int64_t number) const
{ … }
const NFRule*
NFRuleSet::findFractionRuleSetRule(double number) const
{ … }
#ifdef RBNF_DEBUG
#include <stdio.h>
static void dumpUS(FILE* f, const UnicodeString& us) {
int len = us.length();
char* buf = (char *)uprv_malloc((len+1)*sizeof(char));
if (buf != nullptr) {
us.extract(0, len, buf);
buf[len] = 0;
fprintf(f, "%s", buf);
uprv_free(buf);
}
}
#endif
UBool
NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, Formattable& result) const
{ … }
void
NFRuleSet::appendRules(UnicodeString& result) const
{ … }
int64_t util64_fromDouble(double d) { … }
uint64_t util64_pow(uint32_t base, uint16_t exponent) { … }
static const uint8_t asciiDigits[] = …;
static const char16_t kUMinus = …;
#ifdef RBNF_DEBUG
static const char kMinus = '-';
static const uint8_t digitInfo[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0x80u, 0x81u, 0x82u, 0x83u, 0x84u, 0x85u, 0x86u, 0x87u,
0x88u, 0x89u, 0, 0, 0, 0, 0, 0,
0, 0x8au, 0x8bu, 0x8cu, 0x8du, 0x8eu, 0x8fu, 0x90u,
0x91u, 0x92u, 0x93u, 0x94u, 0x95u, 0x96u, 0x97u, 0x98u,
0x99u, 0x9au, 0x9bu, 0x9cu, 0x9du, 0x9eu, 0x9fu, 0xa0u,
0xa1u, 0xa2u, 0xa3u, 0, 0, 0, 0, 0,
0, 0x8au, 0x8bu, 0x8cu, 0x8du, 0x8eu, 0x8fu, 0x90u,
0x91u, 0x92u, 0x93u, 0x94u, 0x95u, 0x96u, 0x97u, 0x98u,
0x99u, 0x9au, 0x9bu, 0x9cu, 0x9du, 0x9eu, 0x9fu, 0xa0u,
0xa1u, 0xa2u, 0xa3u, 0, 0, 0, 0, 0,
};
int64_t util64_atoi(const char* str, uint32_t radix)
{
if (radix > 36) {
radix = 36;
} else if (radix < 2) {
radix = 2;
}
int64_t lradix = radix;
int neg = 0;
if (*str == kMinus) {
++str;
neg = 1;
}
int64_t result = 0;
uint8_t b;
while ((b = digitInfo[*str++]) && ((b &= 0x7f) < radix)) {
result *= lradix;
result += (int32_t)b;
}
if (neg) {
result = -result;
}
return result;
}
int64_t util64_utoi(const char16_t* str, uint32_t radix)
{
if (radix > 36) {
radix = 36;
} else if (radix < 2) {
radix = 2;
}
int64_t lradix = radix;
int neg = 0;
if (*str == kUMinus) {
++str;
neg = 1;
}
int64_t result = 0;
char16_t c;
uint8_t b;
while (((c = *str++) < 0x0080) && (b = digitInfo[c]) && ((b &= 0x7f) < radix)) {
result *= lradix;
result += (int32_t)b;
}
if (neg) {
result = -result;
}
return result;
}
uint32_t util64_toa(int64_t w, char* buf, uint32_t len, uint32_t radix, UBool raw)
{
if (radix > 36) {
radix = 36;
} else if (radix < 2) {
radix = 2;
}
int64_t base = radix;
char* p = buf;
if (len && (w < 0) && (radix == 10) && !raw) {
w = -w;
*p++ = kMinus;
--len;
} else if (len && (w == 0)) {
*p++ = (char)raw ? 0 : asciiDigits[0];
--len;
}
while (len && w != 0) {
int64_t n = w / base;
int64_t m = n * base;
int32_t d = (int32_t)(w-m);
*p++ = raw ? (char)d : asciiDigits[d];
w = n;
--len;
}
if (len) {
*p = 0;
}
len = p - buf;
if (*buf == kMinus) {
++buf;
}
while (--p > buf) {
char c = *p;
*p = *buf;
*buf = c;
++buf;
}
return len;
}
#endif
uint32_t util64_tou(int64_t w, char16_t* buf, uint32_t len, uint32_t radix, UBool raw)
{ … }
U_NAMESPACE_END
#endif