diff options
author | mcheshkov <mcheshkov@yandex-team.ru> | 2022-02-10 16:46:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:15 +0300 |
commit | e9d19cec64684c9c1e6b0c98297e5b895cf904fe (patch) | |
tree | 2768b1223e96a8a0610a93d18425d9647c1123c8 /contrib/libs/icu/i18n/nfsubs.cpp | |
parent | 60040c91ffe701a84689b2c6310ff845e65cff42 (diff) | |
download | ydb-e9d19cec64684c9c1e6b0c98297e5b895cf904fe.tar.gz |
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/icu/i18n/nfsubs.cpp')
-rw-r--r-- | contrib/libs/icu/i18n/nfsubs.cpp | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/contrib/libs/icu/i18n/nfsubs.cpp b/contrib/libs/icu/i18n/nfsubs.cpp index 208543d1ac..95f00fbe38 100644 --- a/contrib/libs/icu/i18n/nfsubs.cpp +++ b/contrib/libs/icu/i18n/nfsubs.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: nfsubs.cpp -* encoding: UTF-8 +* encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * @@ -19,9 +19,9 @@ #include "utypeinfo.h" // for 'typeid' to work #include "nfsubs.h" -#include "fmtableimp.h" -#include "putilimp.h" -#include "number_decimalquantity.h" +#include "fmtableimp.h" +#include "putilimp.h" +#include "number_decimalquantity.h" #if U_HAVE_RBNF @@ -48,8 +48,8 @@ static const UChar gGreaterGreaterThan[] = U_NAMESPACE_BEGIN -using number::impl::DecimalQuantity; - +using number::impl::DecimalQuantity; + class SameValueSubstitution : public NFSubstitution { public: SameValueSubstitution(int32_t pos, @@ -72,15 +72,15 @@ public: SameValueSubstitution::~SameValueSubstitution() {} class MultiplierSubstitution : public NFSubstitution { - int64_t divisor; + int64_t divisor; public: MultiplierSubstitution(int32_t _pos, - const NFRule *rule, + const NFRule *rule, const NFRuleSet* _ruleSet, const UnicodeString& description, UErrorCode& status) - : NFSubstitution(_pos, _ruleSet, description, status), divisor(rule->getDivisor()) + : NFSubstitution(_pos, _ruleSet, description, status), divisor(rule->getDivisor()) { if (divisor == 0) { status = U_PARSE_ERROR; @@ -88,8 +88,8 @@ public: } virtual ~MultiplierSubstitution(); - virtual void setDivisor(int32_t radix, int16_t exponent, UErrorCode& status) { - divisor = util64_pow(radix, exponent); + virtual void setDivisor(int32_t radix, int16_t exponent, UErrorCode& status) { + divisor = util64_pow(radix, exponent); if(divisor == 0) { status = U_PARSE_ERROR; @@ -99,14 +99,14 @@ public: virtual UBool operator==(const NFSubstitution& rhs) const; virtual int64_t transformNumber(int64_t number) const { - return number / divisor; + return number / divisor; } virtual double transformNumber(double number) const { if (getRuleSet()) { return uprv_floor(number / divisor); } else { - return number / divisor; + return number / divisor; } } @@ -114,7 +114,7 @@ public: return newRuleValue * divisor; } - virtual double calcUpperBound(double /*oldUpperBound*/) const { return static_cast<double>(divisor); } + virtual double calcUpperBound(double /*oldUpperBound*/) const { return static_cast<double>(divisor); } virtual UChar tokenChar() const { return (UChar)0x003c; } // '<' @@ -126,19 +126,19 @@ public: MultiplierSubstitution::~MultiplierSubstitution() {} class ModulusSubstitution : public NFSubstitution { - int64_t divisor; + int64_t divisor; const NFRule* ruleToUse; public: ModulusSubstitution(int32_t pos, - const NFRule* rule, + const NFRule* rule, const NFRule* rulePredecessor, const NFRuleSet* ruleSet, const UnicodeString& description, UErrorCode& status); virtual ~ModulusSubstitution(); - virtual void setDivisor(int32_t radix, int16_t exponent, UErrorCode& status) { - divisor = util64_pow(radix, exponent); + virtual void setDivisor(int32_t radix, int16_t exponent, UErrorCode& status) { + divisor = util64_pow(radix, exponent); if (divisor == 0) { status = U_PARSE_ERROR; @@ -150,22 +150,22 @@ public: virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const; virtual void doSubstitution(double number, UnicodeString& toInsertInto, int32_t pos, int32_t recursionCount, UErrorCode& status) const; - virtual int64_t transformNumber(int64_t number) const { return number % divisor; } - virtual double transformNumber(double number) const { return uprv_fmod(number, static_cast<double>(divisor)); } + virtual int64_t transformNumber(int64_t number) const { return number % divisor; } + virtual double transformNumber(double number) const { return uprv_fmod(number, static_cast<double>(divisor)); } virtual UBool doParse(const UnicodeString& text, ParsePosition& parsePosition, double baseValue, double upperBound, UBool lenientParse, - uint32_t nonNumericalExecutedRuleMask, + uint32_t nonNumericalExecutedRuleMask, Formattable& result) const; virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { - return oldRuleValue - uprv_fmod(oldRuleValue, static_cast<double>(divisor)) + newRuleValue; + return oldRuleValue - uprv_fmod(oldRuleValue, static_cast<double>(divisor)) + newRuleValue; } - virtual double calcUpperBound(double /*oldUpperBound*/) const { return static_cast<double>(divisor); } + virtual double calcUpperBound(double /*oldUpperBound*/) const { return static_cast<double>(divisor); } virtual UBool isModulusSubstitution() const { return TRUE; } @@ -225,7 +225,7 @@ public: double baseValue, double upperBound, UBool lenientParse, - uint32_t nonNumericalExecutedRuleMask, + uint32_t nonNumericalExecutedRuleMask, Formattable& result) const; virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue + oldRuleValue; } @@ -297,7 +297,7 @@ public: double baseValue, double upperBound, UBool /*lenientParse*/, - uint32_t nonNumericalExecutedRuleMask, + uint32_t nonNumericalExecutedRuleMask, Formattable& result) const; virtual double composeRuleValue(double newRuleValue, double oldRuleValue) const { return newRuleValue / oldRuleValue; } @@ -355,7 +355,7 @@ NFSubstitution::makeSubstitution(int32_t pos, // otherwise, return a MultiplierSubstitution else { - return new MultiplierSubstitution(pos, rule, ruleSet, + return new MultiplierSubstitution(pos, rule, ruleSet, description, status); } @@ -385,7 +385,7 @@ NFSubstitution::makeSubstitution(int32_t pos, // otherwise, return a ModulusSubstitution else { - return new ModulusSubstitution(pos, rule, predecessor, + return new ModulusSubstitution(pos, rule, predecessor, ruleSet, description, status); } @@ -493,7 +493,7 @@ NFSubstitution::~NFSubstitution() * @param exponent The exponent of the divisor */ void -NFSubstitution::setDivisor(int32_t /*radix*/, int16_t /*exponent*/, UErrorCode& /*status*/) { +NFSubstitution::setDivisor(int32_t /*radix*/, int16_t /*exponent*/, UErrorCode& /*status*/) { // a no-op for all substitutions except multiplier and modulus substitutions } @@ -574,38 +574,38 @@ void NFSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t _pos, int32_t recursionCount, UErrorCode& status) const { if (ruleSet != NULL) { - // Perform a transformation on the number that is dependent + // Perform a transformation on the number that is dependent // on the type of substitution this is, then just call its // rule set's format() method to format the result ruleSet->format(transformNumber(number), toInsertInto, _pos + this->pos, recursionCount, status); } else if (numberFormat != NULL) { - if (number <= MAX_INT64_IN_DOUBLE) { - // or perform the transformation on the number (preserving - // the result's fractional part if the formatter it set - // to show it), then use that formatter's format() method - // to format the result - double numberToFormat = transformNumber((double)number); - if (numberFormat->getMaximumFractionDigits() == 0) { - numberToFormat = uprv_floor(numberToFormat); - } - - UnicodeString temp; - numberFormat->format(numberToFormat, temp, status); - toInsertInto.insert(_pos + this->pos, temp); - } - else { - // We have gone beyond double precision. Something has to give. - // We're favoring accuracy of the large number over potential rules - // that round like a CompactDecimalFormat, which is not a common use case. - // - // Perform a transformation on the number that is dependent - // on the type of substitution this is, then just call its - // rule set's format() method to format the result - int64_t numberToFormat = transformNumber(number); - UnicodeString temp; - numberFormat->format(numberToFormat, temp, status); - toInsertInto.insert(_pos + this->pos, temp); - } + if (number <= MAX_INT64_IN_DOUBLE) { + // or perform the transformation on the number (preserving + // the result's fractional part if the formatter it set + // to show it), then use that formatter's format() method + // to format the result + double numberToFormat = transformNumber((double)number); + if (numberFormat->getMaximumFractionDigits() == 0) { + numberToFormat = uprv_floor(numberToFormat); + } + + UnicodeString temp; + numberFormat->format(numberToFormat, temp, status); + toInsertInto.insert(_pos + this->pos, temp); + } + else { + // We have gone beyond double precision. Something has to give. + // We're favoring accuracy of the large number over potential rules + // that round like a CompactDecimalFormat, which is not a common use case. + // + // Perform a transformation on the number that is dependent + // on the type of substitution this is, then just call its + // rule set's format() method to format the result + int64_t numberToFormat = transformNumber(number); + UnicodeString temp; + numberFormat->format(numberToFormat, temp, status); + toInsertInto.insert(_pos + this->pos, temp); + } } } @@ -695,7 +695,7 @@ NFSubstitution::doParse(const UnicodeString& text, double baseValue, double upperBound, UBool lenientParse, - uint32_t nonNumericalExecutedRuleMask, + uint32_t nonNumericalExecutedRuleMask, Formattable& result) const { #ifdef RBNF_DEBUG @@ -716,7 +716,7 @@ NFSubstitution::doParse(const UnicodeString& text, // on), then also try parsing the text using a default- // constructed NumberFormat if (ruleSet != NULL) { - ruleSet->parse(text, parsePosition, upperBound, nonNumericalExecutedRuleMask, result); + ruleSet->parse(text, parsePosition, upperBound, nonNumericalExecutedRuleMask, result); if (lenientParse && !ruleSet->isFractionRuleSet() && parsePosition.getIndex() == 0) { UErrorCode status = U_ZERO_ERROR; NumberFormat* fmt = NumberFormat::createInstance(status); @@ -827,20 +827,20 @@ UBool MultiplierSubstitution::operator==(const NFSubstitution& rhs) const * regular rule. */ ModulusSubstitution::ModulusSubstitution(int32_t _pos, - const NFRule* rule, + const NFRule* rule, const NFRule* predecessor, const NFRuleSet* _ruleSet, const UnicodeString& description, UErrorCode& status) : NFSubstitution(_pos, _ruleSet, description, status) - , divisor(rule->getDivisor()) + , divisor(rule->getDivisor()) , ruleToUse(NULL) { // the owning rule's divisor controls the behavior of this // substitution: rather than keeping a backpointer to the rule, // we keep a copy of the divisor - if (divisor == 0) { + if (divisor == 0) { status = U_PARSE_ERROR; } @@ -938,19 +938,19 @@ ModulusSubstitution::doParse(const UnicodeString& text, double baseValue, double upperBound, UBool lenientParse, - uint32_t nonNumericalExecutedRuleMask, + uint32_t nonNumericalExecutedRuleMask, Formattable& result) const { // if this isn't a >>> substitution, we can just use the // inherited parse() routine to do the parsing if (ruleToUse == NULL) { - return NFSubstitution::doParse(text, parsePosition, baseValue, upperBound, lenientParse, nonNumericalExecutedRuleMask, result); + return NFSubstitution::doParse(text, parsePosition, baseValue, upperBound, lenientParse, nonNumericalExecutedRuleMask, result); // but if it IS a >>> substitution, we have to do it here: we // use the specific rule's doParse() method, and then we have to // do some of the other work of NFRuleSet.parse() } else { - ruleToUse->doParse(text, parsePosition, FALSE, upperBound, nonNumericalExecutedRuleMask, result); + ruleToUse->doParse(text, parsePosition, FALSE, upperBound, nonNumericalExecutedRuleMask, result); if (parsePosition.getIndex() != 0) { UErrorCode status = U_ZERO_ERROR; @@ -1072,12 +1072,12 @@ FractionalPartSubstitution::doSubstitution(double number, UnicodeString& toInser // numberToFormat /= 10; // } - DecimalQuantity dl; - dl.setToDouble(number); - dl.roundToMagnitude(-20, UNUM_ROUND_HALFEVEN, status); // round to 20 fraction digits. + DecimalQuantity dl; + dl.setToDouble(number); + dl.roundToMagnitude(-20, UNUM_ROUND_HALFEVEN, status); // round to 20 fraction digits. UBool pad = FALSE; - for (int32_t didx = dl.getLowerDisplayMagnitude(); didx<0; didx++) { + for (int32_t didx = dl.getLowerDisplayMagnitude(); didx<0; didx++) { // Loop iterates over fraction digits, starting with the LSD. // include both real digits from the number, and zeros // to the left of the MSD but to the right of the decimal point. @@ -1086,7 +1086,7 @@ FractionalPartSubstitution::doSubstitution(double number, UnicodeString& toInser } else { pad = TRUE; } - int64_t digit = dl.getDigit(didx); + int64_t digit = dl.getDigit(didx); getRuleSet()->format(digit, toInsertInto, _pos + getPos(), recursionCount, status); } @@ -1125,13 +1125,13 @@ FractionalPartSubstitution::doParse(const UnicodeString& text, double baseValue, double /*upperBound*/, UBool lenientParse, - uint32_t nonNumericalExecutedRuleMask, + uint32_t nonNumericalExecutedRuleMask, Formattable& resVal) const { // if we're not in byDigits mode, we can just use the inherited // doParse() if (!byDigits) { - return NFSubstitution::doParse(text, parsePosition, baseValue, 0, lenientParse, nonNumericalExecutedRuleMask, resVal); + return NFSubstitution::doParse(text, parsePosition, baseValue, 0, lenientParse, nonNumericalExecutedRuleMask, resVal); // if we ARE in byDigits mode, parse the text one digit at a time // using this substitution's owning rule set (we do this by setting @@ -1144,13 +1144,13 @@ FractionalPartSubstitution::doParse(const UnicodeString& text, int32_t digit; // double p10 = 0.1; - DecimalQuantity dl; - int32_t totalDigits = 0; + DecimalQuantity dl; + int32_t totalDigits = 0; NumberFormat* fmt = NULL; while (workText.length() > 0 && workPos.getIndex() != 0) { workPos.setIndex(0); Formattable temp; - getRuleSet()->parse(workText, workPos, 10, nonNumericalExecutedRuleMask, temp); + getRuleSet()->parse(workText, workPos, 10, nonNumericalExecutedRuleMask, temp); UErrorCode status = U_ZERO_ERROR; digit = temp.getLong(status); // digit = temp.getType() == Formattable::kLong ? @@ -1173,8 +1173,8 @@ FractionalPartSubstitution::doParse(const UnicodeString& text, } if (workPos.getIndex() != 0) { - dl.appendDigit(static_cast<int8_t>(digit), 0, true); - totalDigits++; + dl.appendDigit(static_cast<int8_t>(digit), 0, true); + totalDigits++; // result += digit * p10; // p10 /= 10; parsePosition.setIndex(parsePosition.getIndex() + workPos.getIndex()); @@ -1187,8 +1187,8 @@ FractionalPartSubstitution::doParse(const UnicodeString& text, } delete fmt; - dl.adjustMagnitude(-totalDigits); - result = dl.toDouble(); + dl.adjustMagnitude(-totalDigits); + result = dl.toDouble(); result = composeRuleValue(result, baseValue); resVal.setDouble(result); return TRUE; @@ -1260,7 +1260,7 @@ NumeratorSubstitution::doParse(const UnicodeString& text, double baseValue, double upperBound, UBool /*lenientParse*/, - uint32_t nonNumericalExecutedRuleMask, + uint32_t nonNumericalExecutedRuleMask, Formattable& result) const { // we don't have to do anything special to do the parsing here, @@ -1279,7 +1279,7 @@ NumeratorSubstitution::doParse(const UnicodeString& text, while (workText.length() > 0 && workPos.getIndex() != 0) { workPos.setIndex(0); - getRuleSet()->parse(workText, workPos, 1, nonNumericalExecutedRuleMask, temp); // parse zero or nothing at all + getRuleSet()->parse(workText, workPos, 1, nonNumericalExecutedRuleMask, temp); // parse zero or nothing at all if (workPos.getIndex() == 0) { // we failed, either there were no more zeros, or the number was formatted with digits // either way, we're done @@ -1301,7 +1301,7 @@ NumeratorSubstitution::doParse(const UnicodeString& text, } // we've parsed off the zeros, now let's parse the rest from our current position - NFSubstitution::doParse(workText, parsePosition, withZeros ? 1 : baseValue, upperBound, FALSE, nonNumericalExecutedRuleMask, result); + NFSubstitution::doParse(workText, parsePosition, withZeros ? 1 : baseValue, upperBound, FALSE, nonNumericalExecutedRuleMask, result); if (withZeros) { // any base value will do in this case. is there a way to |