1: proc wrap {string maxlen {html ""}} { 2: set splitstring {} 3: foreach line [split $string "\n"] { 4: lappend splitstring [wrapline $line $maxlen $html] 5: } 6: if {$html == "-html"} { 7: return [join $splitstring "<br>"] 8: } else { 9: return [join $splitstring "\n"] 10: } 11: } 12: 13: proc wrapline {line maxlen {html ""}} { 14: set string [split $line " "] 15: set newline [list [lindex $string 0]] 16: foreach word [lrange $string 1 end] { 17: if {[string length $newline]+[string length $word] > $maxlen} { 18: lappend lines [join $newline " "] 19: set newline {} 20: } 21: lappend newline $word 22: } 23: lappend lines [join $newline " "] 24: if {$html == "-html"} { 25: return [join $lines <br>] 26: } else { 27: return [join $lines "\n"] 28: } 29: } |