From: Hugo van der Merwe <17109322+hugovdm@users.noreply.github.com> Date: Thu, 19 Mar 2020 20:38:20 +0000 (+0100) Subject: Little fixes to unitconverter.cpp X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=415956a2e3285b71f3af0f6993e762b81598b93b;p=icu Little fixes to unitconverter.cpp --- diff --git a/icu4c/source/i18n/unitconverter.cpp b/icu4c/source/i18n/unitconverter.cpp index 169c48b36bc..aaf129c69f9 100644 --- a/icu4c/source/i18n/unitconverter.cpp +++ b/icu4c/source/i18n/unitconverter.cpp @@ -68,19 +68,17 @@ double strToDouble(StringPiece strNum) { // StringToDoubleConverter. StringToDoubleConverter converter(0, 0, 0, "", ""); int32_t count; - return converter.StringToDouble(reinterpret_cast(strNum.length()), strNum.length(), - &count); + return converter.StringToDouble(strNum.data(), strNum.length(), &count); } // Returns `double` from a scientific number that could has a division sign (i.e. "1", "2.01", "3.09E+4" // or "2E+2/3") double strHasDivideSignToDouble(StringPiece strWithDivide, UErrorCode &status) { - CharString charNum(strWithDivide, status); if (U_FAILURE(status)) return 0.0; int divisionSignInd = -1; - for (int i = 0, n = charNum[i]; i < n; ++i) { - if (charNum[i] == '/') { + for (int i = 0; i < strWithDivide.length(); ++i) { + if (strWithDivide.data()[i] == '/') { divisionSignInd = i; break; } @@ -463,7 +461,11 @@ MeasureUnit extractTarget(MeasureUnit source, UErrorCode &status) { return result; } -UnitsCase checkUnitsCase(MeasureUnit source, MeasureUnit target, UErrorCode &status) { +// Checks whether conversion from source to target is possible by checking +// whether their conversion information pivots on the same base unit. If +// UnitsCase::RECIPROCAL is returned, it means one's base unit is the inverse of +// the other's. +UnitsCase checkUnitsCase(const MeasureUnit &source, const MeasureUnit &target, UErrorCode &status) { MeasureUnit sourceTargetUnit = extractTarget(source, status); MeasureUnit targetTargetUnit = extractTarget(target, status);