[Libreoffice-commits] .: sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon Dec 13 13:06:17 PST 2010
sc/inc/stringutil.hxx | 2 ++
sc/source/core/tool/stringutil.cxx | 16 +++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
New commits:
commit fa5d7f2e034aa7d51200d70cd125b5095e845e34
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Mon Dec 13 16:02:21 2010 -0500
Remove trailing spaces too when parsing csv's simple numbers.
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index dcf6d57..e9a60a5 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 83e31f7..1953aae 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)
{
More information about the Libreoffice-commits
mailing list