+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
* Copyright (C) 1997-2015, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* file name: nfrs.cpp
-* encoding: US-ASCII
+* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
#include "nfrule.h"
#include "nfrlist.h"
#include "patternprops.h"
+#include "putilimp.h"
#ifdef RBNF_DEBUG
#include "cmemory.h"
// an explanation of the rollback rule). If we do, roll back
// one rule and return that one instead of the one we'd normally
// return
- if (result->shouldRollBack((double)number)) {
+ if (result->shouldRollBack(number)) {
if (hi == 1) { // bad rule set, no prior rule to rollback to from this base
return NULL;
}
#endif
UBool
-NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBound, Formattable& result, UBool lenient) const
+NFRuleSet::parse(const UnicodeString& text, ParsePosition& pos, double upperBound, uint32_t nonNumericalExecutedRuleMask, Formattable& result, UBool lenient) const
{
// try matching each rule in the rule set against the text being
// parsed. Whichever one matches the most characters is the one
#endif
// Try each of the negative rules, fraction rules, infinity rules and NaN rules
for (int i = 0; i < NON_NUMERICAL_RULE_LENGTH; i++) {
- if (nonNumericalRules[i]) {
+ if (nonNumericalRules[i] && ((nonNumericalExecutedRuleMask >> i) & 1) == 0) {
+ // Mark this rule as being executed so that we don't try to execute it again.
+ nonNumericalExecutedRuleMask |= 1 << i;
+
Formattable tempResult;
- UBool success = nonNumericalRules[i]->doParse(text, workingPos, 0, upperBound, tempResult, lenient || isDecimalFormatRuleParseable() );
+ UBool success = nonNumericalRules[i]->doParse(text, workingPos, 0, upperBound, nonNumericalExecutedRuleMask, tempResult, lenient || isDecimalFormatRuleParseable() );
if (success && (workingPos.getIndex() > highWaterMark.getIndex())) {
result = tempResult;
highWaterMark = workingPos;
continue;
}
Formattable tempResult;
- UBool success = rules[i]->doParse(text, workingPos, fIsFractionRuleSet, upperBound, tempResult);
+ UBool success = rules[i]->doParse(text, workingPos, fIsFractionRuleSet, upperBound, nonNumericalExecutedRuleMask, tempResult);
if (success && workingPos.getIndex() > highWaterMark.getIndex()) {
result = tempResult;
highWaterMark = workingPos;
return result;
}
-int64_t util64_pow(int32_t r, uint32_t e) {
- if (r == 0) {
+uint64_t util64_pow(uint32_t base, uint16_t exponent) {
+ if (base == 0) {
return 0;
- } else if (e == 0) {
- return 1;
- } else {
- int64_t n = r;
- while (--e > 0) {
- n *= r;
+ }
+ uint64_t result = 1;
+ uint64_t pow = base;
+ while (true) {
+ if ((exponent & 1) == 1) {
+ result *= pow;
}
- return n;
+ exponent >>= 1;
+ if (exponent == 0) {
+ break;
+ }
+ pow *= pow;
}
+ return result;
}
static const uint8_t asciiDigits[] = {
/* U_HAVE_RBNF */
#endif
-