Tk Library Source Code

View Ticket
Login
Ticket UUID: 1407811
Title: read2* incorrect for multi-line data
Type: Patch Version: None
Submitter: hobbs Created on: 2006-01-17 01:13:25
Subsystem: csv Assigned To: andreas_kupries
Priority: 7 High Severity:
Status: Closed Last Modified: 2006-01-17 10:51:42
Resolution: Accepted Closed By: andreas_kupries
    Closed on: 2006-01-17 03:51:42
Description:
This patch applies to read2matrix, but each API that
reads from a channel needs to account for multiline CSV
data.

Index: csv.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/csv/csv.tcl,v
retrieving revision 1.22
diff -u -r1.22 csv.tcl
--- csv.tcl     30 Sep 2005 23:03:20 -0000      1.22
+++ csv.tcl     17 Jan 2006 01:10:58 -0000
@@ -166,10 +166,19 @@
        }
     }

+    set data ""
     while {![eof $chan]} {
        if {[gets $chan line] < 0} {continue}
-       if {$line == {}} {continue}
-       Split2matrix $alternate $m $line $sepChar $expand
+       # Why skip empty lines?  They may be in data.
+       #if {$line == {}} {continue}
+       append data $line
+       if {[regexp -all \" $data] % 2} {
+           # Odd number of quotes - must have embedded
newline
+           append data \n
+           continue
+       }
+       Split2matrix $alternate $m $data $sepChar $expand
+       set data ""
     }
     return
 }
User Comments: andreas_kupries added on 2006-01-17 10:51:42:
Logged In: YES 
user_id=75003

Applied to head.