summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-03-30 11:38:17 +0200
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-03-30 12:06:56 +0200
commitdcdafbcb132341bb22b6159f0f1dea1ef00f7c18 (patch)
tree29aca268024a8ae0d5a3aa8032e69690e264c428 /src/corelib/tools
parent5ef6ac6550f1692d66611e7918d85c7ebedda439 (diff)
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.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index db2fc26409..559ba81232 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;