/*
******************************************************************************
-* Copyright (C) 1997-2008, International Business Machines
+* Copyright (C) 1997-2014, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* file name: nfrs.cpp
#include "unicode/uchar.h"
#include "nfrule.h"
#include "nfrlist.h"
+#include "patternprops.h"
#ifdef RBNF_DEBUG
#include "cmemory.h"
#endif
-#include "util.h"
-
U_NAMESPACE_BEGIN
#if 0
0x25, 0x25, 0
}; /* "%%" */
+static const UChar gNoparse[] =
+{
+ 0x40, 0x6E, 0x6F, 0x70, 0x61, 0x72, 0x73, 0x65, 0
+}; /* "@noparse" */
+
NFRuleSet::NFRuleSet(UnicodeString* descriptions, int32_t index, UErrorCode& status)
: name()
, rules(0)
, negativeNumberRule(NULL)
, fIsFractionRuleSet(FALSE)
, fIsPublic(FALSE)
+ , fIsParseable(TRUE)
, fRecursionCount(0)
{
for (int i = 0; i < 3; ++i) {
status = U_PARSE_ERROR;
} else {
name.setTo(description, 0, pos);
- while (pos < description.length() && uprv_isRuleWhiteSpace(description.charAt(++pos))) {
+ while (pos < description.length() && PatternProps::isWhiteSpace(description.charAt(++pos))) {
}
description.remove(0, pos);
}
status = U_PARSE_ERROR;
}
- fIsPublic = name.indexOf(gPercentPercent) != 0;
+ fIsPublic = name.indexOf(gPercentPercent, 2, 0) != 0;
+
+ if ( name.endsWith(gNoparse,8) ) {
+ fIsParseable = FALSE;
+ name.truncate(name.length()-8); // remove the @noparse from the name
+ }
// all of the other members of NFRuleSet are initialized
// by parseRules()
return;
}
+ // ensure we are starting with an empty rule list
+ rules.deleteAll();
+
// dlf - the original code kept a separate description array for no reason,
// so I got rid of it. The loop was too complex so I simplified it.
// if it's the negative-number rule, copy it into its own
// data member and delete it from the list
case NFRule::kNegativeNumberRule:
+ if (negativeNumberRule) {
+ delete negativeNumberRule;
+ }
negativeNumberRule = rules.remove(i);
break;
// if it's the improper fraction rule, copy it into the
// correct element of fractionRules
case NFRule::kImproperFractionRule:
+ if (fractionRules[0]) {
+ delete fractionRules[0];
+ }
fractionRules[0] = rules.remove(i);
break;
// if it's the proper fraction rule, copy it into the
// correct element of fractionRules
case NFRule::kProperFractionRule:
+ if (fractionRules[1]) {
+ delete fractionRules[1];
+ }
fractionRules[1] = rules.remove(i);
break;
// if it's the master rule, copy it into the
// correct element of fractionRules
case NFRule::kMasterRule:
+ if (fractionRules[2]) {
+ delete fractionRules[2];
+ }
fractionRules[2] = rules.remove(i);
break;
#define RECURSION_LIMIT 50
void
-NFRuleSet::format(int64_t number, UnicodeString& toAppendTo, int32_t pos) const
+NFRuleSet::format(int64_t number, UnicodeString& toAppendTo, int32_t pos, UErrorCode& status) const
{
NFRule *rule = findNormalRule(number);
if (rule) { // else error, but can't report it
// stop recursion
ncThis->fRecursionCount = 0;
} else {
- rule->doFormat(number, toAppendTo, pos);
+ rule->doFormat(number, toAppendTo, pos, status);
ncThis->fRecursionCount--;
}
}
}
void
-NFRuleSet::format(double number, UnicodeString& toAppendTo, int32_t pos) const
+NFRuleSet::format(double number, UnicodeString& toAppendTo, int32_t pos, UErrorCode& status) const
{
NFRule *rule = findDoubleRule(number);
if (rule) { // else error, but can't report it
// stop recursion
ncThis->fRecursionCount = 0;
} else {
- rule->doFormat(number, toAppendTo, pos);
+ rule->doFormat(number, toAppendTo, pos, status);
ncThis->fRecursionCount--;
}
}
}
// always use the last rule for infinity. It is likely that rule
- // will had a DecimalFormat that will do the right thing with infinity even
+ // has a DecimalFormat that will do the right thing with infinity even
// if the rule's base value is strange, i.e. something larger than what
// util64_fromDouble produces below.
if (uprv_isInfinite(number) && (rules.size() > 0)) {
// followed by the regular rules...
for (uint32_t i = 0; i < rules.size(); i++) {
- result.append(gFourSpaces);
+ result.append(gFourSpaces, 4);
rules[i]->_appendRuleText(result);
result.append(gLineFeed);
}
// followed by the special rules (if they exist)
if (negativeNumberRule) {
- result.append(gFourSpaces);
+ result.append(gFourSpaces, 4);
negativeNumberRule->_appendRuleText(result);
result.append(gLineFeed);
}
{
for (uint32_t i = 0; i < 3; ++i) {
if (fractionRules[i]) {
- result.append(gFourSpaces);
+ result.append(gFourSpaces, 4);
fractionRules[i]->_appendRuleText(result);
result.append(gLineFeed);
}