diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-03-30 09:38:17 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-03-30 10:06:56 (GMT) |
commit | dcdafbcb132341bb22b6159f0f1dea1ef00f7c18 (patch) | |
tree | 29aca268024a8ae0d5a3aa8032e69690e264c428 /src/corelib/tools | |
parent | 5ef6ac6550f1692d66611e7918d85c7ebedda439 (diff) | |
download | Qt-dcdafbcb132341bb22b6159f0f1dea1ef00f7c18.zip Qt-dcdafbcb132341bb22b6159f0f1dea1ef00f7c18.tar.gz Qt-dcdafbcb132341bb22b6159f0f1dea1ef00f7c18.tar.bz2 |
String-to-number conversion functions should ignore trailing whitespaces.
According to our documentation we should ignore leading and trailing
whitespaces when converting a string to number with QLocale::toInt and
similar functions. However that didn't work for some locales - for
those ones that declare groupseparator as 0xa0 (which looks similar to
space) since we provide a workaround to accept space as a group
separator for those locales. And since the workaround was there for a
long time it doesn't make sense to change the behavior and the fix is
to explicitely remove leading and trailing whitespaces before doing
any conversion.
Reviewed-by: mariusSO
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index db2fc26..559ba81 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -4399,7 +4399,8 @@ double QLocalePrivate::stringToDouble(const QString &number, bool *ok, GroupSeparatorMode group_sep_mode) const { CharBuff buff; - if (!numberToCLocale(number, group_sep_mode, &buff)) { + if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number, + group_sep_mode, &buff)) { if (ok != 0) *ok = false; return 0.0; @@ -4411,7 +4412,8 @@ qlonglong QLocalePrivate::stringToLongLong(const QString &number, int base, bool *ok, GroupSeparatorMode group_sep_mode) const { CharBuff buff; - if (!numberToCLocale(number, group_sep_mode, &buff)) { + if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number, + group_sep_mode, &buff)) { if (ok != 0) *ok = false; return 0; @@ -4424,7 +4426,8 @@ qulonglong QLocalePrivate::stringToUnsLongLong(const QString &number, int base, bool *ok, GroupSeparatorMode group_sep_mode) const { CharBuff buff; - if (!numberToCLocale(number, group_sep_mode, &buff)) { + if (!numberToCLocale(group().unicode() == 0xa0 ? number.trimmed() : number, + group_sep_mode, &buff)) { if (ok != 0) *ok = false; return 0; |