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: 1155f0d752 ("Base: simplify UnitsSchemas management")
This commit is contained in:
Ladislav Michl
2025-05-14 10:24:02 +02:00
parent a075bf8c34
commit beccce4d3c
3 changed files with 23 additions and 20 deletions

View File

@@ -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

View File

@@ -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.: 34-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, ""));
}