1 # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3 # $Id: String.tcl,v 1.2 2002-09-07 05:21:42 mikeclarkson Exp $
5 ###### String.tcl ######
9 #-----------------------------------------------------------------
11 # trimSpace -- If a STRING contains no embedded newlines, then remove
12 # the surrounding whitespace, otherwise just remove trailing whitespace.
18 #----------------------------------------------------------------
20 proc trimSpace
{ ans
} {
21 if { ![regexp "\n" $ans] } {
22 set ans
[string trim
$ans "\n \t"]
23 } elseif
{ [regexp "^\[\n\t \](\[^\n\]+)\[\n\t \]\$" $ans junk item
] } {
24 set ans
[string trim
$ans "\n \t"]
26 # set ans [string range $ans 0 [expr {[string length $ans] - 2}]]
27 # try to make multiline things start with ans
28 set ans
\n[string trimleft
$ans \n]
32 if { [regexp "^\[\n\t \]*(\[^\n\]+)\[\n\t \]*\$" $ans junk item
] } {
33 set ans
[string trim
$ans "\n \t"]
34 } elseif
{ [regexp "\n" $ans] } {
35 set ans
[string trim
$ans "\n \t"]
38 set ans
[string trimright
$ans "\n \t"]
45 #-----------------------------------------------------------------
47 # genword -- make a string by copying STRING a total of COUNT times
53 #----------------------------------------------------------------
55 proc genword
{ string count
} {
57 while { [incr count
-1] >= 0 } { append ans
$string }
61 ## endsource string.tcl