Tk Library Source Code

Artifact [c18987f6d6]
Login

Artifact c18987f6d60d7218984cca084ec8517cbb1cbf32:

Attachment "base64-tcllib-1-10.patch" to ticket [1969078fff] added by andreas_kupries 2008-05-22 02:47:48.
--- base64/base64.tcl-orig	2008-05-21 20:18:48.000000000 +0200
+++ base64/base64.tcl	2008-05-21 20:55:24.000000000 +0200
@@ -85,19 +85,24 @@
 
 	set string [lindex $args end]
 	set result [::base64 -mode encode -- $string]
-	set result [string map [list \n ""] $result]
+	#
+	# The Trf-implementation of base64 uses maxlen 76 and wrapchar \n
+	#
+	if {$maxlen == 76 && $wrapchar eq "\n"} {
+	  # This is the fastest case. We are already done.
+	} else {
+	  # Remove the breaks from Trf
+	  set result [string map [list \n ""] $result]
 
-	if {$maxlen > 0} {
+	  if {$maxlen > 0} {
 	    set res ""
-	    set edge [expr {$maxlen - 1}]
-	    while {[string length $result] > $maxlen} {
-		append res [string range $result 0 $edge]$wrapchar
-		set result [string range $result $maxlen end]
-	    }
-	    if {[string length $result] > 0} {
-		append res $result
+	    set l [expr {[string length $result]-$maxlen}]
+	    for {set off 0} {$off < $l} {incr off $maxlen} {
+	      append res [string range $result $off [expr {$off+$maxlen-1}]] $wrapchar
 	    }
+	    append res [string range $result $off end]
 	    set result $res
+	  }
 	}
 
 	return $result