From beccce4d3cf01dc8bd1a094ff42eb908267d2cc1 Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Wed, 14 May 2025 10:24:02 +0200 Subject: [PATCH] Base: revert to using ASCII chararacters for imperial lengths The new unit schema management is using U+2032 and U+2033 characters for feet and inches while parser is expecting only ' and ", while U+2032 and U+2033 are used for arcminute and arcsecond. While this is not an ideal solution and parser should deal with both, revert back to ASCII for now. Fixes: 1155f0d75281 ("Base: simplify UnitsSchemas management") --- src/Base/UnitsSchema.cpp | 13 +++++++------ src/Base/UnitsSchemasData.h | 12 ++++++------ tests/src/Base/SchemaTests.cpp | 18 ++++++++++-------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Base/UnitsSchema.cpp b/src/Base/UnitsSchema.cpp index c576d65919..68662e8971 100644 --- a/src/Base/UnitsSchema.cpp +++ b/src/Base/UnitsSchema.cpp @@ -103,12 +103,13 @@ UnitsSchema::toLocale(const Quantity& quant, const double factor, const std::str std::string valueString = Lc.toString((quant.getValue() / factor), format.toFormat(), format.precision).toStdString(); - return fmt::format( - "{}{}{}", - valueString, - unitString.empty() || unitString == "°" || unitString == "″" || unitString == "′" ? "" - : " ", - unitString); + return fmt::format("{}{}{}", + valueString, + unitString.empty() || unitString == "°" || unitString == "″" + || unitString == "′" || unitString == "\"" || unitString == "'" + ? "" + : " ", + unitString); } bool UnitsSchema::isMultiUnitLength() const diff --git a/src/Base/UnitsSchemasData.h b/src/Base/UnitsSchemasData.h index d50e1c6b75..c37260f3ab 100644 --- a/src/Base/UnitsSchemasData.h +++ b/src/Base/UnitsSchemasData.h @@ -581,8 +581,8 @@ inline const UnitsSchemaSpec s7 { "Length", { { 0.00000254 , "in" , 25.4 }, { 2.54 , "thou" , 0.0254 }, - { 304.8 , "″" , 25.4 }, - { 914.4 , "′" , 304.8 }, + { 304.8 , "\"" , 25.4 }, + { 914.4 , "'" , 304.8 }, { 1'609'344.0 , "yd" , 914.4 }, { 1'609'344'000.0 , "mi" , 1'609'344.0 }, { 0 , "in" , 25.4 }} @@ -649,7 +649,7 @@ inline std::size_t greatestCommonDenominator(const std::size_t a, const std::siz } /** - * double -> [feet′][inches[-fraction]″], e.g.: 3′4-1/4″ + * double -> [feet'][inches[-fraction]"], e.g.: 3'4-1/4" */ inline std::string toFractional(const double value) { @@ -676,19 +676,19 @@ inline std::string toFractional(const double value) if (inches > 0) { resultParts.push_back(fmt::format("{}", inches)); if (numerator == 0) { - resultParts.emplace_back("″"); + resultParts.emplace_back("\""); } } if (numerator > 0) { if (inches > 0) { resultParts.emplace_back("-"); } - resultParts.push_back(fmt::format("{}/{}″", numerator, denominator)); + resultParts.push_back(fmt::format("{}/{}\"", numerator, denominator)); } return fmt::format("{}{}{}", value < 0 ? "-" : "", - feet > 0 ? fmt::format("{}′", feet) : "", + feet > 0 ? fmt::format("{}'", feet) : "", fmt::join(resultParts, "")); } diff --git a/tests/src/Base/SchemaTests.cpp b/tests/src/Base/SchemaTests.cpp index 8cfc3644c3..59aa242054 100644 --- a/tests/src/Base/SchemaTests.cpp +++ b/tests/src/Base/SchemaTests.cpp @@ -21,6 +21,7 @@ #include #include "Base/Exception.h" +#include "Base/Tools.h" #include "Base/Unit.h" #include "Base/Quantity.h" #include "Base/UnitsApi.h" @@ -33,6 +34,7 @@ using Base::Quantity; using Base::QuantityFormat; using Base::RuntimeError; +using Base::Tools; using Base::Unit; using Base::UnitsApi; using Base::UnitsSchema; @@ -263,7 +265,7 @@ TEST_F(SchemaTest, imperial_safe_user_str_same) { constexpr auto val {304.8}; const auto result = set("Imperial", Unit::Length, val); - const auto expect {"1.00′"}; + const auto expect = Tools::escapeQuotesFromString("1.00'"); EXPECT_EQ(result, expect); } @@ -272,7 +274,7 @@ TEST_F(SchemaTest, imperial_safe_user_str_more) { constexpr auto val {310.0}; const auto result = set("Imperial", Unit::Length, val); - const auto expect {"1.02′"}; + const auto expect = Tools::escapeQuotesFromString("1.02'"); EXPECT_EQ(result, expect); } @@ -281,7 +283,7 @@ TEST_F(SchemaTest, imperial_safe_user_str_less) { constexpr auto val {300.0}; const auto result = set("Imperial", Unit::Length, val); - const auto expect {"11.81″"}; + const auto expect = Tools::escapeQuotesFromString("11.81\""); EXPECT_EQ(result, expect); } @@ -290,7 +292,7 @@ TEST_F(SchemaTest, imperial_safe_user_str_one_inch) { constexpr auto val {25.4}; const auto result = set("Imperial", Unit::Length, val); - const auto expect {"1.00″"}; + const auto expect = Tools::escapeQuotesFromString("1.00\""); EXPECT_EQ(result, expect); } @@ -299,7 +301,7 @@ TEST_F(SchemaTest, imperial_building_special_function_length_inch) { constexpr auto val {25.4}; const auto result = set("ImperialBuilding", Unit::Length, val); - const auto expect {"1″"}; + const auto expect = Tools::escapeQuotesFromString("1\""); EXPECT_EQ(result, expect); } @@ -308,7 +310,7 @@ TEST_F(SchemaTest, imperial_building_special_function_length_foot) { constexpr auto val {25.4 * 12}; const auto result = set("ImperialBuilding", Unit::Length, val); - const auto expect {"1′"}; + const auto expect = Tools::escapeQuotesFromString("1'"); EXPECT_EQ(result, expect); } @@ -317,7 +319,7 @@ TEST_F(SchemaTest, imperial_building_special_function_length) { constexpr auto val {360.6}; const auto result = set("ImperialBuilding", Unit::Length, val); - const auto expect {"1′2-1/4″"}; + const auto expect = Tools::escapeQuotesFromString("1'2-1/4\""); EXPECT_EQ(result, expect); } @@ -326,7 +328,7 @@ TEST_F(SchemaTest, imperial_building_special_function_length_neg) { constexpr auto val {-360.6}; const auto result = set("ImperialBuilding", Unit::Length, val); - const auto expect {"-1′2-1/4″"}; + const auto expect = Tools::escapeQuotesFromString("-1'2-1/4\""); EXPECT_EQ(result, expect); }