[Libreoffice-commits] .: tools/source

Kohei Yoshida kohei at kemper.freedesktop.org
Tue Nov 9 21:44:32 PST 2010


 tools/source/stream/stream.cxx |   13 +++++++++++++
 1 file changed, 13 insertions(+)

New commits:
commit d0b78ac3509a52efc5ff5e268b35754c7e8e64ec
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Nov 10 00:41:49 2010 -0500

    Import mal-formed csv files gracefully.
    
    When importing a document with mal-formed rows, try our best to keep
    them from damaging, other, well-formed rows.  Previously calc would
    eat other well-formed rows occurring after the mal-formed row.
    (n#507322)

diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 0b13c3e..c0f78e2 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1108,6 +1108,9 @@ sal_Bool SvStream::ReadCsvLine( String& rStr, sal_Bool bEmbeddedLineBreak,
 
     if (bEmbeddedLineBreak)
     {
+        // See if the separator(s) include tab.
+        bool bTabSep = lcl_UnicodeStrChr(pSeps, '\t') != NULL;
+
         const sal_Unicode* pSeps = rFieldSeparators.GetBuffer();
         xub_StrLen nLastOffset = 0;
         xub_StrLen nQuotes = 0;
@@ -1121,6 +1124,16 @@ sal_Bool SvStream::ReadCsvLine( String& rStr, sal_Bool bEmbeddedLineBreak,
             {
                 if (nQuotes)
                 {
+                    if (bTabSep && *p == '\t')
+                    {
+                        // When tab-delimited, tab char ends quoted sequence
+                        // even if we haven't reached the end quote.  Doing
+                        // this helps keep mal-formed rows from damaging
+                        // other, well-formed rows.
+                        nQuotes = 0;
+                        break;
+                    }
+
                     if (*p == cFieldQuote && !bBackslashEscaped)
                         ++nQuotes;
                     else if (bAllowBackslashEscape)


More information about the Libreoffice-commits mailing list