summaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-03 11:22:37 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-03 11:22:37 -0800
commit32d26b751ae15faca812437d002c0275dcf7e7e3 (patch)
tree05d07e6e4fcc025bfe8c5c720115d52bf0569a70 /qt-ui/models.cpp
parenta30a0910b485c10536130a627b836a0f5b784ce7 (diff)
downloadsubsurface-32d26b751ae15faca812437d002c0275dcf7e7e3.tar.gz
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>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp10
1 files 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;