From 32d26b751ae15faca812437d002c0275dcf7e7e3 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 3 Jan 2014 11:22:37 -0800 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/models.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index ab501a2bd..aa9db450b 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -468,12 +468,14 @@ double string_to_grams(char *str) { char *end; 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)) - end++; - if (!strncmp(end, "kg", 2)) + if (rest.startsWith("kg") || rest.startsWith(local_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; if (prefs.units.weight == prefs.units.LBS) goto lbs; -- cgit v1.2.3-70-g09d2