[Libreoffice-commits] .: Branch 'libreoffice-3-3' - 5 commits - sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Tue Dec 14 09:26:58 PST 2010


 sc/inc/stringutil.hxx              |    2 ++
 sc/source/core/tool/stringutil.cxx |   31 +++++++++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

New commits:
commit c1fe450afdc7234c549de3dfac61a620ff213169
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)
     {
commit d81a90edf1c9e17eaaff77cb00d49051a5a7d151
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Dec 13 20:53:21 2010 +0000

    WaE, shadowed warning

diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index dbd9306..83e31f7 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -80,7 +80,7 @@ bool ScStringUtil::parseSimpleNumber(
 
     n -= i; // Subtract the length of preceding space.
 
-    for (sal_Int32 i = 0; i < n; ++i, ++p)
+    for (i = 0; i < n; ++i, ++p)
     {
         sal_Unicode c = *p;
         if (c == 0x00A0)
commit c2e6be18f38240106a3811445d993d35be12a790
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Mon Dec 13 15:37:45 2010 -0500

    We need to reset i to 0 after parsing spaces.

diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 136b0be..dbd9306 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -74,7 +74,13 @@ bool ScStringUtil::parseSimpleNumber(
             break;
     }
 
-    for (; i < n; ++i, ++p)
+    if (i == n)
+        // the whole string is space.  Fail.
+        return false;
+
+    n -= i; // Subtract the length of preceding space.
+
+    for (sal_Int32 i = 0; i < n; ++i, ++p)
     {
         sal_Unicode c = *p;
         if (c == 0x00A0)
commit 6a28e8397ae7a913dc7af1d2bcb3590ce975c1ac
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Mon Dec 13 15:17:30 2010 -0500

    The previous commit would skip *all* spaces.  This is the right fix.

diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 31efe6a..136b0be 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -63,17 +63,24 @@ bool ScStringUtil::parseSimpleNumber(
     sal_Int32 nPosDSep = -1, nPosGSep = -1;
     sal_uInt32 nDigitCount = 0;
 
-    for (sal_Int32 i = 0; i < n; ++i, ++p)
+    sal_Int32 i = 0;
+
+    // Skip preceding spaces.
+    for (i = 0; i < n; ++i, ++p)
+    {
+        sal_Unicode c = *p;
+        if (c != 0x0020 && c != 0x00A0)
+            // first non-space character.  Exit.
+            break;
+    }
+
+    for (; i < n; ++i, ++p)
     {
         sal_Unicode c = *p;
         if (c == 0x00A0)
             // unicode space to ascii space
             c = 0x0020;
 
-        if (c == 0x0020)
-            // Skip preceding spaces.
-            continue;
-
         if (sal_Unicode('0') <= c && c <= sal_Unicode('9'))
         {
             // this is a digit.
commit 15254fc821d2bbed205e814c689b19cafaf1eb8a
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Mon Dec 13 14:55:13 2010 -0500

    When parsing numbers, ignore preceding spaces.
    
    Also, increment the char pointer and use it directly, which is
    faster than accessing char via [] in each iteration.

diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index ae73746..31efe6a 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -63,13 +63,17 @@ bool ScStringUtil::parseSimpleNumber(
     sal_Int32 nPosDSep = -1, nPosGSep = -1;
     sal_uInt32 nDigitCount = 0;
 
-    for (sal_Int32 i = 0; i < n; ++i)
+    for (sal_Int32 i = 0; i < n; ++i, ++p)
     {
-        sal_Unicode c = p[i];
+        sal_Unicode c = *p;
         if (c == 0x00A0)
             // unicode space to ascii space
             c = 0x0020;
 
+        if (c == 0x0020)
+            // Skip preceding spaces.
+            continue;
+
         if (sal_Unicode('0') <= c && c <= sal_Unicode('9'))
         {
             // this is a digit.


More information about the Libreoffice-commits mailing list