]> granicus.if.org Git - icu/commitdiff
Little fixes to unitconverter.cpp
authorHugo van der Merwe <17109322+hugovdm@users.noreply.github.com>
Thu, 19 Mar 2020 20:38:20 +0000 (21:38 +0100)
committerHugo van der Merwe <17109322+hugovdm@users.noreply.github.com>
Thu, 19 Mar 2020 20:38:20 +0000 (21:38 +0100)
icu4c/source/i18n/unitconverter.cpp

index 169c48b36bc589bd1d8997abfa96eec0c70e6fb7..aaf129c69f927112452a8da0e0d844bea8185dd1 100644 (file)
@@ -68,19 +68,17 @@ double strToDouble(StringPiece strNum) {
     // StringToDoubleConverter.
     StringToDoubleConverter converter(0, 0, 0, "", "");
     int32_t count;
-    return converter.StringToDouble(reinterpret_cast<const uint16_t *>(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);