Tk Library Source Code

Artifact [b8185cff4d]
Login

Artifact b8185cff4d93f14e798251b052afe5806bfedff7:

Attachment "csv.diff" to ticket [3575707fff] added by gahr 2012-10-09 17:33:33.
--- modules/csv/csv.tcl.orig	2012-10-09 12:02:21.000000000 +0200
+++ modules/csv/csv.tcl	2012-10-09 12:25:08.000000000 +0200
@@ -11,7 +11,7 @@
 # RCS: @(#) $Id: csv.tcl,v 1.28 2011/11/23 02:22:10 andreas_kupries Exp $
 
 package require Tcl 8.3
-package provide csv 0.7.3
+package provide csv 0.7.4
 
 namespace eval ::csv {
     namespace export join joinlist read2matrix read2queue report 
@@ -25,15 +25,17 @@
 # Arguments:
 #	values		A list of the values to join
 #	sepChar		The separator character, defaults to comma
+#	delChar		The delimiter character, defaults to quote
+#	forceDel	If set, values are always surrounded by delChar
 #
 # Results:
 #	A string containing the values in CSV format.
 
-proc ::csv::join {values {sepChar ,} {delChar \"}} {
+proc ::csv::join {values {sepChar ,} {delChar \"} {forceDel {}}} {
     set out ""
     set sep {}
     foreach val $values {
-	if {[string match "*\[${delChar}$sepChar\r\n\]*" $val]} {
+	if {$forceDel ne {} || [string match "*\[${delChar}$sepChar\r\n\]*" $val]} {
 	    append out $sep${delChar}[string map [list $delChar ${delChar}${delChar}] $val]${delChar}
 	} else {
 	    append out $sep${val}
@@ -53,16 +55,18 @@
 # Arguments:
 #	values		A list of the lists of the values to join
 #	sepChar		The separator character, defaults to comma
+#	delChar		The delimiter character, defaults to quote
+#	forceDel	If set, values are always surrounded by delChar
 #
 # Results:
 #	A string containing the values in CSV format, the records
 #	separated by newlines.
 
-proc ::csv::joinlist {values {sepChar ,} {delChar \"}} {
+proc ::csv::joinlist {values {sepChar ,} {delChar \"} {forceDel {}}} {
     set out ""
     foreach record $values {
 	# note that this is ::csv::join
-	append out "[join $record $sepChar $delChar]\n"
+	append out "[join $record $sepChar $delChar $forceDel]\n"
     }
     return $out
 }
@@ -77,13 +81,15 @@
 # Arguments:
 #	matrix		Matrix object command.
 #	sepChar		The separator character, defaults to comma
+#	delChar		The delimiter character, defaults to quote
+#	forceDel	If set, values are always surrounded by delChar
 #
 # Results:
 #	A string containing the values in CSV format, the records
 #	separated by newlines.
 
-proc ::csv::joinmatrix {matrix {sepChar ,} {delChar \"}} {
-    return [joinlist [$matrix get rect 0 0 end end] $sepChar $delChar]
+proc ::csv::joinmatrix {matrix {sepChar ,} {delChar \"} {forceDel {}}} {
+    return [joinlist [$matrix get rect 0 0 end end] $sepChar $delChar $forceDel]
 }
 
 # ::csv::iscomplete --
--- modules/csv/csv.man.orig	2012-10-09 12:19:59.000000000 +0200
+++ modules/csv/csv.man	2012-10-09 12:24:52.000000000 +0200
@@ -1,11 +1,11 @@
 [comment {-*- tcl -*-}]
-[manpage_begin csv n 0.7.3]
+[manpage_begin csv n 0.7.4]
 [copyright {2002-2011 Andreas Kupries <[email protected]>}]
 [moddesc   {CSV processing}]
 [titledesc {Procedures to handle CSV data.}]
 [category  {Text processing}]
 [require Tcl 8.3]
-[require csv [opt 0.7.3]]
+[require csv [opt 0.7.4]]
 [description]
 
 [para]
@@ -26,33 +26,37 @@
 record. The result is a boolean flag indicating the completeness of
 the data. The result is true if the data is complete.
 
-[call [cmd ::csv::join] [arg values] "{[arg sepChar] ,}" "{[arg delChar] \"}"]
+[call [cmd ::csv::join] [arg values] "{[arg sepChar] ,}" "{[arg delChar] \"}" "{[arg forceDel] {}}"]
 
 Takes a list of values and returns a string in CSV format containing
 these values. The separator character can be defined by the caller,
 but this is optional. The default is ",". The quoting character can
 be defined by the caller, but this is optional. The default is '"'.
+If forceDel is non-empty, values are always surrounded by delChar.
 
-[call [cmd ::csv::joinlist] [arg values] "{[arg sepChar] ,}" "{[arg delChar] \"}"]
+[call [cmd ::csv::joinlist] [arg values] "{[arg sepChar] ,}" "{[arg delChar] \"}" "{[arg forceDel] {}}"]
 
 Takes a list of lists of values and returns a string in CSV format
 containing these values. The separator character can be defined by the
 caller, but this is optional. The default is ",". The quoting character
 can be defined by the caller, but this is optional. The default is '"'.
+If forceDel is non-empty, values are always surrounded by delChar.
 Each element of the outer list is considered a record, these are
 separated by newlines in the result. The elements of each record are
 formatted as usual (via [cmd ::csv::join]).
 
-[call [cmd ::csv::joinmatrix] [arg matrix] "{[arg sepChar] ,}" "{[arg delChar] \"}"]
+
+[call [cmd ::csv::joinmatrix] [arg matrix] "{[arg sepChar] ,}" "{[arg delChar] \"}" "{[arg forceDel] {}}]
 
 Takes a [arg matrix] object following the API specified for the
 struct::matrix package and returns a string in CSV format containing
 these values. The separator character can be defined by the caller,
 but this is optional. The default is ",". The quoting character
 can be defined by the caller, but this is optional. The default is
-'"'. Each row of the matrix is considered a record, these are
-separated by newlines in the result. The elements of each record are
-formatted as usual (via [cmd ::csv::join]).
+'"'. If forceDel is non-empty, values are always surrounded by delChar.
+Each row of the matrix is considered a record, these are separated by
+newlines in the result. The elements of each record are formatted as
+usual (via [cmd ::csv::join]).
 
 [call [cmd ::csv::read2matrix] [opt [option -alternate]] [arg "chan m"] "{[arg sepChar] ,} {[arg expand] none}"]
 
--- modules/csv/csv.pcx.orig	2012-10-09 12:23:47.000000000 +0200
+++ modules/csv/csv.pcx	2012-10-09 12:23:26.000000000 +0200
@@ -21,19 +21,22 @@
 	checkWord
     }}
 pcx::check 0.7 std ::csv::join \
-    {checkSimpleArgs 1 3 {
+    {checkSimpleArgs 1 4 {
 	checkList
 	checkWord
+	checkWord
     checkWord
     }}
 pcx::check 0.7 std ::csv::joinlist \
-    {checkSimpleArgs 1 3 {
+    {checkSimpleArgs 1 4 {
 	checkList
 	checkWord
+	checkWord
     checkWord
     }}
 pcx::check 0.7 std ::csv::joinmatrix \
-    {checkSimpleArgs 1 3 {
+    {checkSimpleArgs 1 4 {
+	checkWord
 	checkWord
 	checkWord
     checkWord