mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Parse localized weight units
We have the wonderful Qt string functions. Let's use them to make the code simpler and easier to read. Suggested-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
a30a0910b4
commit
32d26b751a
1 changed files with 6 additions and 4 deletions
|
@ -468,12 +468,14 @@ double string_to_grams(char *str)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
double value = strtod_flags(str, &end, 0);
|
double value = strtod_flags(str, &end, 0);
|
||||||
|
QString rest = QString(end).trimmed();
|
||||||
|
QString local_kg = WeightModel::tr("kg");
|
||||||
|
QString local_lbs = WeightModel::tr("lbs");
|
||||||
|
|
||||||
while (isspace(*end))
|
if (rest.startsWith("kg") || rest.startsWith(local_kg))
|
||||||
end++;
|
|
||||||
if (!strncmp(end, "kg", 2))
|
|
||||||
goto kg;
|
goto kg;
|
||||||
if (!strncmp(end, "lbs", 3))
|
// using just "lb" instead of "lbs" is intentional - some people might enter the singular
|
||||||
|
if (rest.startsWith("lb") || rest.startsWith(local_lbs))
|
||||||
goto lbs;
|
goto lbs;
|
||||||
if (prefs.units.weight == prefs.units.LBS)
|
if (prefs.units.weight == prefs.units.LBS)
|
||||||
goto lbs;
|
goto lbs;
|
||||||
|
|
Loading…
Add table
Reference in a new issue