summaryrefslogtreecommitdiffstats
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-09 09:27:24 +0800
commit8795be53ae69e8d92633eff7e4ac9afccbaf1148 (patch)
tree46ce250b6bf64ab4315a76b2c227e7799d42d9f3
parent6719e45704d8694d845bc4e8bc3970e21bdab23b (diff)
downloadsubsurface-8795be53ae69e8d92633eff7e4ac9afccbaf1148.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>
-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;