aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/i18n/nfrule.cpp
diff options
context:
space:
mode:
authormcheshkov <mcheshkov@yandex-team.ru>2022-02-10 16:46:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:15 +0300
commite9d19cec64684c9c1e6b0c98297e5b895cf904fe (patch)
tree2768b1223e96a8a0610a93d18425d9647c1123c8 /contrib/libs/icu/i18n/nfrule.cpp
parent60040c91ffe701a84689b2c6310ff845e65cff42 (diff)
downloadydb-e9d19cec64684c9c1e6b0c98297e5b895cf904fe.tar.gz
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/icu/i18n/nfrule.cpp')
-rw-r--r--contrib/libs/icu/i18n/nfrule.cpp144
1 files changed, 72 insertions, 72 deletions
diff --git a/contrib/libs/icu/i18n/nfrule.cpp b/contrib/libs/icu/i18n/nfrule.cpp
index 3ad0291649..f6dbd61bc5 100644
--- a/contrib/libs/icu/i18n/nfrule.cpp
+++ b/contrib/libs/icu/i18n/nfrule.cpp
@@ -1,4 +1,4 @@
-// © 2016 and later: Unicode, Inc. and others.
+// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
@@ -6,7 +6,7 @@
* Corporation and others. All Rights Reserved.
******************************************************************************
* file name: nfrule.cpp
-* encoding: UTF-8
+* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
@@ -30,7 +30,7 @@
#include "nfrlist.h"
#include "nfsubs.h"
#include "patternprops.h"
-#include "putilimp.h"
+#include "putilimp.h"
U_NAMESPACE_BEGIN
@@ -39,14 +39,14 @@ NFRule::NFRule(const RuleBasedNumberFormat* _rbnf, const UnicodeString &_ruleTex
, radix(10)
, exponent(0)
, decimalPoint(0)
- , fRuleText(_ruleText)
+ , fRuleText(_ruleText)
, sub1(NULL)
, sub2(NULL)
, formatter(_rbnf)
, rulePatternFormat(NULL)
{
- if (!fRuleText.isEmpty()) {
- parseRuleDescriptor(fRuleText, status);
+ if (!fRuleText.isEmpty()) {
+ parseRuleDescriptor(fRuleText, status);
}
}
@@ -122,7 +122,7 @@ NFRule::makeRules(UnicodeString& description,
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
- description = rule1->fRuleText;
+ description = rule1->fRuleText;
// check the description to see whether there's text enclosed
// in brackets
@@ -314,7 +314,7 @@ NFRule::parseRuleDescriptor(UnicodeString& description, UErrorCode& status)
if (c == gSlash) {
val = 0;
++p;
- ll_10 = 10;
+ ll_10 = 10;
while (p < descriptorLength) {
c = descriptor.charAt(p);
if (c >= gZero && c <= gNine) {
@@ -418,7 +418,7 @@ NFRule::extractSubstitutions(const NFRuleSet* ruleSet,
if (U_FAILURE(status)) {
return;
}
- fRuleText = ruleText;
+ fRuleText = ruleText;
sub1 = extractSubstitution(ruleSet, predecessor, status);
if (sub1 == NULL) {
// Small optimization. There is no need to create a redundant NullSubstitution.
@@ -427,15 +427,15 @@ NFRule::extractSubstitutions(const NFRuleSet* ruleSet,
else {
sub2 = extractSubstitution(ruleSet, predecessor, status);
}
- int32_t pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
- int32_t pluralRuleEnd = (pluralRuleStart >= 0 ? fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart) : -1);
+ int32_t pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
+ int32_t pluralRuleEnd = (pluralRuleStart >= 0 ? fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart) : -1);
if (pluralRuleEnd >= 0) {
- int32_t endType = fRuleText.indexOf(gComma, pluralRuleStart);
+ int32_t endType = fRuleText.indexOf(gComma, pluralRuleStart);
if (endType < 0) {
status = U_PARSE_ERROR;
return;
}
- UnicodeString type(fRuleText.tempSubString(pluralRuleStart + 2, endType - pluralRuleStart - 2));
+ UnicodeString type(fRuleText.tempSubString(pluralRuleStart + 2, endType - pluralRuleStart - 2));
UPluralType pluralType;
if (type.startsWith(UNICODE_STRING_SIMPLE("cardinal"))) {
pluralType = UPLURAL_TYPE_CARDINAL;
@@ -448,7 +448,7 @@ NFRule::extractSubstitutions(const NFRuleSet* ruleSet,
return;
}
rulePatternFormat = formatter->createPluralFormat(pluralType,
- fRuleText.tempSubString(endType + 1, pluralRuleEnd - endType - 1), status);
+ fRuleText.tempSubString(endType + 1, pluralRuleEnd - endType - 1), status);
}
}
@@ -484,16 +484,16 @@ NFRule::extractSubstitution(const NFRuleSet* ruleSet,
// special-case the ">>>" token, since searching for the > at the
// end will actually find the > in the middle
- if (fRuleText.indexOf(gGreaterGreaterGreater, 3, 0) == subStart) {
+ if (fRuleText.indexOf(gGreaterGreaterGreater, 3, 0) == subStart) {
subEnd = subStart + 2;
// otherwise the substitution token ends with the same character
// it began with
} else {
- UChar c = fRuleText.charAt(subStart);
- subEnd = fRuleText.indexOf(c, subStart + 1);
+ UChar c = fRuleText.charAt(subStart);
+ subEnd = fRuleText.indexOf(c, subStart + 1);
// special case for '<%foo<<'
- if (c == gLessThan && subEnd != -1 && subEnd < fRuleText.length() - 1 && fRuleText.charAt(subEnd+1) == c) {
+ if (c == gLessThan && subEnd != -1 && subEnd < fRuleText.length() - 1 && fRuleText.charAt(subEnd+1) == c) {
// ordinals use "=#,##0==%abbrev=" as their rule. Notice that the '==' in the middle
// occurs because of the juxtaposition of two different rules. The check for '<' is a hack
// to get around this. Having the duplicate at the front would cause problems with
@@ -513,12 +513,12 @@ NFRule::extractSubstitution(const NFRuleSet* ruleSet,
// some text bounded by substitution token characters). Use
// makeSubstitution() to create the right kind of substitution
UnicodeString subToken;
- subToken.setTo(fRuleText, subStart, subEnd + 1 - subStart);
+ subToken.setTo(fRuleText, subStart, subEnd + 1 - subStart);
result = NFSubstitution::makeSubstitution(subStart, this, predecessor, ruleSet,
this->formatter, subToken, status);
// remove the substitution from the rule text
- fRuleText.removeBetween(subStart, subEnd+1);
+ fRuleText.removeBetween(subStart, subEnd+1);
return result;
}
@@ -601,7 +601,7 @@ NFRule::indexOfAnyRulePrefix() const
{
int result = -1;
for (int i = 0; RULE_PREFIXES[i]; i++) {
- int32_t pos = fRuleText.indexOf(*RULE_PREFIXES[i]);
+ int32_t pos = fRuleText.indexOf(*RULE_PREFIXES[i]);
if (pos != -1 && (result == -1 || pos < result)) {
result = pos;
}
@@ -637,7 +637,7 @@ NFRule::operator==(const NFRule& rhs) const
return baseValue == rhs.baseValue
&& radix == rhs.radix
&& exponent == rhs.exponent
- && fRuleText == rhs.fRuleText
+ && fRuleText == rhs.fRuleText
&& util_equalSubstitutions(sub1, rhs.sub1)
&& util_equalSubstitutions(sub2, rhs.sub2);
}
@@ -690,14 +690,14 @@ NFRule::_appendRuleText(UnicodeString& result) const
// if the rule text begins with a space, write an apostrophe
// (whitespace after the rule descriptor is ignored; the
// apostrophe is used to make the whitespace significant)
- if (fRuleText.charAt(0) == gSpace && (sub1 == NULL || sub1->getPos() != 0)) {
+ if (fRuleText.charAt(0) == gSpace && (sub1 == NULL || sub1->getPos() != 0)) {
result.append(gTick);
}
// now, write the rule's rule text, inserting appropriate
// substitution tokens in the appropriate places
UnicodeString ruleTextCopy;
- ruleTextCopy.setTo(fRuleText);
+ ruleTextCopy.setTo(fRuleText);
UnicodeString temp;
if (sub2 != NULL) {
@@ -716,12 +716,12 @@ NFRule::_appendRuleText(UnicodeString& result) const
result.append(gSemicolon);
}
-int64_t NFRule::getDivisor() const
-{
- return util64_pow(radix, exponent);
-}
-
-
+int64_t NFRule::getDivisor() const
+{
+ return util64_pow(radix, exponent);
+}
+
+
//-----------------------------------------------------------------------
// formatting
//-----------------------------------------------------------------------
@@ -743,24 +743,24 @@ NFRule::doFormat(int64_t number, UnicodeString& toInsertInto, int32_t pos, int32
// into the right places in toInsertInto (notice we do the
// substitutions in reverse order so that the offsets don't get
// messed up)
- int32_t pluralRuleStart = fRuleText.length();
+ int32_t pluralRuleStart = fRuleText.length();
int32_t lengthOffset = 0;
if (!rulePatternFormat) {
- toInsertInto.insert(pos, fRuleText);
+ toInsertInto.insert(pos, fRuleText);
}
else {
- pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
- int pluralRuleEnd = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart);
+ pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
+ int pluralRuleEnd = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart);
int initialLength = toInsertInto.length();
- if (pluralRuleEnd < fRuleText.length() - 1) {
- toInsertInto.insert(pos, fRuleText.tempSubString(pluralRuleEnd + 2));
+ if (pluralRuleEnd < fRuleText.length() - 1) {
+ toInsertInto.insert(pos, fRuleText.tempSubString(pluralRuleEnd + 2));
}
toInsertInto.insert(pos,
- rulePatternFormat->format((int32_t)(number/util64_pow(radix, exponent)), status));
+ rulePatternFormat->format((int32_t)(number/util64_pow(radix, exponent)), status));
if (pluralRuleStart > 0) {
- toInsertInto.insert(pos, fRuleText.tempSubString(0, pluralRuleStart));
+ toInsertInto.insert(pos, fRuleText.tempSubString(0, pluralRuleStart));
}
- lengthOffset = fRuleText.length() - (toInsertInto.length() - initialLength);
+ lengthOffset = fRuleText.length() - (toInsertInto.length() - initialLength);
}
if (sub2 != NULL) {
@@ -789,32 +789,32 @@ NFRule::doFormat(double number, UnicodeString& toInsertInto, int32_t pos, int32_
// [again, we have two copies of this routine that do the same thing
// so that we don't sacrifice precision in a long by casting it
// to a double]
- int32_t pluralRuleStart = fRuleText.length();
+ int32_t pluralRuleStart = fRuleText.length();
int32_t lengthOffset = 0;
if (!rulePatternFormat) {
- toInsertInto.insert(pos, fRuleText);
+ toInsertInto.insert(pos, fRuleText);
}
else {
- pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
- int pluralRuleEnd = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart);
+ pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
+ int pluralRuleEnd = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart);
int initialLength = toInsertInto.length();
- if (pluralRuleEnd < fRuleText.length() - 1) {
- toInsertInto.insert(pos, fRuleText.tempSubString(pluralRuleEnd + 2));
+ if (pluralRuleEnd < fRuleText.length() - 1) {
+ toInsertInto.insert(pos, fRuleText.tempSubString(pluralRuleEnd + 2));
}
double pluralVal = number;
if (0 <= pluralVal && pluralVal < 1) {
// We're in a fractional rule, and we have to match the NumeratorSubstitution behavior.
// 2.3 can become 0.2999999999999998 for the fraction due to rounding errors.
- pluralVal = uprv_round(pluralVal * util64_pow(radix, exponent));
+ pluralVal = uprv_round(pluralVal * util64_pow(radix, exponent));
}
else {
- pluralVal = pluralVal / util64_pow(radix, exponent);
+ pluralVal = pluralVal / util64_pow(radix, exponent);
}
toInsertInto.insert(pos, rulePatternFormat->format((int32_t)(pluralVal), status));
if (pluralRuleStart > 0) {
- toInsertInto.insert(pos, fRuleText.tempSubString(0, pluralRuleStart));
+ toInsertInto.insert(pos, fRuleText.tempSubString(0, pluralRuleStart));
}
- lengthOffset = fRuleText.length() - (toInsertInto.length() - initialLength);
+ lengthOffset = fRuleText.length() - (toInsertInto.length() - initialLength);
}
if (sub2 != NULL) {
@@ -834,7 +834,7 @@ NFRule::doFormat(double number, UnicodeString& toInsertInto, int32_t pos, int32_
* this one in its list; false if it should use this rule
*/
UBool
-NFRule::shouldRollBack(int64_t number) const
+NFRule::shouldRollBack(int64_t number) const
{
// we roll back if the rule contains a modulus substitution,
// the number being formatted is an even multiple of the rule's
@@ -854,7 +854,7 @@ NFRule::shouldRollBack(int64_t number) const
// multiple of 100. This is called the "rollback rule."
if ((sub1 != NULL && sub1->isModulusSubstitution()) || (sub2 != NULL && sub2->isModulusSubstitution())) {
int64_t re = util64_pow(radix, exponent);
- return (number % re) == 0 && (baseValue % re) != 0;
+ return (number % re) == 0 && (baseValue % re) != 0;
}
return FALSE;
}
@@ -900,7 +900,7 @@ NFRule::doParse(const UnicodeString& text,
ParsePosition& parsePosition,
UBool isFractionRule,
double upperBound,
- uint32_t nonNumericalExecutedRuleMask,
+ uint32_t nonNumericalExecutedRuleMask,
Formattable& resVal) const
{
// internally we operate on a copy of the string being parsed
@@ -908,15 +908,15 @@ NFRule::doParse(const UnicodeString& text,
ParsePosition pp;
UnicodeString workText(text);
- int32_t sub1Pos = sub1 != NULL ? sub1->getPos() : fRuleText.length();
- int32_t sub2Pos = sub2 != NULL ? sub2->getPos() : fRuleText.length();
+ int32_t sub1Pos = sub1 != NULL ? sub1->getPos() : fRuleText.length();
+ int32_t sub2Pos = sub2 != NULL ? sub2->getPos() : fRuleText.length();
// check to see whether the text before the first substitution
// matches the text at the beginning of the string being
// parsed. If it does, strip that off the front of workText;
// otherwise, dump out with a mismatch
UnicodeString prefix;
- prefix.setTo(fRuleText, 0, sub1Pos);
+ prefix.setTo(fRuleText, 0, sub1Pos);
#ifdef RBNF_DEBUG
fprintf(stderr, "doParse %p ", this);
@@ -1000,10 +1000,10 @@ NFRule::doParse(const UnicodeString& text,
// the substitution, giving us a new partial parse result
pp.setIndex(0);
- temp.setTo(fRuleText, sub1Pos, sub2Pos - sub1Pos);
+ temp.setTo(fRuleText, sub1Pos, sub2Pos - sub1Pos);
double partialResult = matchToDelimiter(workText, start, tempBaseValue,
temp, pp, sub1,
- nonNumericalExecutedRuleMask,
+ nonNumericalExecutedRuleMask,
upperBound);
// if we got a successful match (or were trying to match a
@@ -1021,10 +1021,10 @@ NFRule::doParse(const UnicodeString& text,
// partial result with whatever it gets back from its
// substitution if there's a successful match, giving us
// a real result
- temp.setTo(fRuleText, sub2Pos, fRuleText.length() - sub2Pos);
+ temp.setTo(fRuleText, sub2Pos, fRuleText.length() - sub2Pos);
partialResult = matchToDelimiter(workText2, 0, partialResult,
temp, pp2, sub2,
- nonNumericalExecutedRuleMask,
+ nonNumericalExecutedRuleMask,
upperBound);
// if we got a successful match on this second
@@ -1039,18 +1039,18 @@ NFRule::doParse(const UnicodeString& text,
else {
// commented out because ParsePosition doesn't have error index in 1.1.x
// restored for ICU4C port
- int32_t i_temp = pp2.getErrorIndex() + sub1Pos + pp.getIndex();
- if (i_temp> parsePosition.getErrorIndex()) {
- parsePosition.setErrorIndex(i_temp);
+ int32_t i_temp = pp2.getErrorIndex() + sub1Pos + pp.getIndex();
+ if (i_temp> parsePosition.getErrorIndex()) {
+ parsePosition.setErrorIndex(i_temp);
}
}
}
else {
// commented out because ParsePosition doesn't have error index in 1.1.x
// restored for ICU4C port
- int32_t i_temp = sub1Pos + pp.getErrorIndex();
- if (i_temp > parsePosition.getErrorIndex()) {
- parsePosition.setErrorIndex(i_temp);
+ int32_t i_temp = sub1Pos + pp.getErrorIndex();
+ if (i_temp > parsePosition.getErrorIndex()) {
+ parsePosition.setErrorIndex(i_temp);
}
}
// keep trying to match things until the outer matchToDelimiter()
@@ -1161,7 +1161,7 @@ NFRule::matchToDelimiter(const UnicodeString& text,
const UnicodeString& delimiter,
ParsePosition& pp,
const NFSubstitution* sub,
- uint32_t nonNumericalExecutedRuleMask,
+ uint32_t nonNumericalExecutedRuleMask,
double upperBound) const
{
UErrorCode status = U_ZERO_ERROR;
@@ -1195,7 +1195,7 @@ NFRule::matchToDelimiter(const UnicodeString& text,
#else
formatter->isLenient(),
#endif
- nonNumericalExecutedRuleMask,
+ nonNumericalExecutedRuleMask,
result);
// if the substitution could match all the text up to
@@ -1249,7 +1249,7 @@ NFRule::matchToDelimiter(const UnicodeString& text,
#else
formatter->isLenient(),
#endif
- nonNumericalExecutedRuleMask,
+ nonNumericalExecutedRuleMask,
result);
if (success && (tempPP.getIndex() != 0)) {
// if there's a successful match (or it's a null
@@ -1483,11 +1483,11 @@ NFRule::findText(const UnicodeString& str,
rulePatternFormat->parseType(str, this, result, position);
int start = position.getBeginIndex();
if (start >= 0) {
- int32_t pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
- int32_t pluralRuleSuffix = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart) + 2;
+ int32_t pluralRuleStart = fRuleText.indexOf(gDollarOpenParenthesis, -1, 0);
+ int32_t pluralRuleSuffix = fRuleText.indexOf(gClosedParenthesisDollar, -1, pluralRuleStart) + 2;
int32_t matchLen = position.getEndIndex() - start;
- UnicodeString prefix(fRuleText.tempSubString(0, pluralRuleStart));
- UnicodeString suffix(fRuleText.tempSubString(pluralRuleSuffix));
+ UnicodeString prefix(fRuleText.tempSubString(0, pluralRuleStart));
+ UnicodeString suffix(fRuleText.tempSubString(pluralRuleSuffix));
if (str.compare(start - prefix.length(), prefix.length(), prefix, 0, prefix.length()) == 0
&& str.compare(start + matchLen, suffix.length(), suffix, 0, suffix.length()) == 0)
{