Hi there, I'd like to port a patch to the libreoffice-3-3 branch to ignore preceding and trailing spaces in cells during csv import. The change is already committed on master, and the attached is the total difference against the current libreoffice-3-3 branch. The change on master consists of several commits.
With this change, a csv file such as this 30, 40, 50 or 30 , 40, 50 will be imported as three number cells. Currently, Calc imports number cells as strings in presence of spaces before or after the number. This change is only applicable when the user leaves the "Detect special number" option *un*-checked, which is off by default. Patch reviews are appreciated. Kohei -- Kohei Yoshida, LibreOffice hacker, Calc <kyosh...@novell.com>
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 ae73746..1953aae 100644 --- a/sc/source/core/tool/stringutil.cxx +++ b/sc/source/core/tool/stringutil.cxx @@ -58,14 +58,41 @@ 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; - for (sal_Int32 i = 0; i < n; ++i) + // 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; + } + + if (i == n) + // the whole string is space. Fail. + return false; + + 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) { - sal_Unicode c = p[i]; + sal_Unicode c = *p; if (c == 0x00A0) // unicode space to ascii space c = 0x0020;
_______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice