summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-12-13 16:02:21 -0500
committerKohei Yoshida <kyoshida@novell.com>2010-12-14 12:21:32 -0500
commitc1fe450afdc7234c549de3dfac61a620ff213169 (patch)
treeb80ec7247278c67c22eb2dd4e39245d2a236d98a
parentd81a90edf1c9e17eaaff77cb00d49051a5a7d151 (diff)
Remove trailing spaces too when parsing csv's simple numbers.feature/helppack
-rw-r--r--sc/inc/stringutil.hxx2
-rw-r--r--sc/source/core/tool/stringutil.cxx16
2 files changed, 15 insertions, 3 deletions
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index dcf6d57df..e9a60a567 100644
--- a/sc/inc/stringutil.hxx
+++ b/sc/inc/stringutil.hxx
@@ -77,6 +77,8 @@ public:
* don't do any elaborate parsing here; we only check for the simplest
* case of decimal number format.
*
+ * Note that preceding and trailing spaces are ignored during parsing.
+ *
* @param rStr string to parse
* @param dsep decimal separator
* @param gsep group separator (aka thousands separator)
diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 83e31f791..1953aaedf 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -58,13 +58,14 @@ bool ScStringUtil::parseSimpleNumber(
gsep = 0x0020;
OUStringBuffer aBuf;
+
+ sal_Int32 i = 0;
sal_Int32 n = rStr.getLength();
const sal_Unicode* p = rStr.getStr();
+ const sal_Unicode* pLast = p + (n-1);
sal_Int32 nPosDSep = -1, nPosGSep = -1;
sal_uInt32 nDigitCount = 0;
- sal_Int32 i = 0;
-
// Skip preceding spaces.
for (i = 0; i < n; ++i, ++p)
{
@@ -78,7 +79,16 @@ bool ScStringUtil::parseSimpleNumber(
// the whole string is space. Fail.
return false;
- n -= i; // Subtract the length of preceding space.
+ n -= i; // Subtract the length of the preceding spaces.
+
+ // Determine the last non-space character.
+ for (; p != pLast; --pLast, --n)
+ {
+ sal_Unicode c = *pLast;
+ if (c != 0x0020 && c != 0x00A0)
+ // Non space character. Exit.
+ break;
+ }
for (i = 0; i < n; ++i, ++p)
{