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:
Dirk Hohndel 2014-01-03 11:22:37 -08:00
parent a30a0910b4
commit 32d26b751a

View file

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