1textutil::trim(n) Text and string utilities, macro processingtextutil::trim(n)
2
3
4
5______________________________________________________________________________
6
8 textutil::trim - Procedures to trim strings
9
11 package require Tcl 8.2
12
13 package require textutil::trim ?0.7?
14
15 ::textutil::trim::trim string ?regexp?
16
17 ::textutil::trim::trimleft string ?regexp?
18
19 ::textutil::trim::trimright string ?regexp?
20
21 ::textutil::trim::trimPrefix string prefix
22
23 ::textutil::trim::trimEmptyHeading string
24
25_________________________________________________________________
26
28 The package textutil::trim provides commands that trim strings using
29 arbitrary regular expressions.
30
31 The complete set of procedures is described below.
32
33 ::textutil::trim::trim string ?regexp?
34 Remove in string any leading and trailing substring according to
35 the regular expression regexp and return the result as a new
36 string. This is done for all lines in the string, that is any
37 substring between 2 newline chars, or between the beginning of
38 the string and a newline, or between a newline and the end of
39 the string, or, if the string contain no newline, between the
40 beginning and the end of the string. The regular expression
41 regexp defaults to "[ \\t]+".
42
43 ::textutil::trim::trimleft string ?regexp?
44 Remove in string any leading substring according to the regular
45 expression regexp and return the result as a new string. This
46 apply on any line in the string, that is any substring between 2
47 newline chars, or between the beginning of the string and a new‐
48 line, or between a newline and the end of the string, or, if the
49 string contain no newline, between the beginning and the end of
50 the string. The regular expression regexp defaults to "[
51 \\t]+".
52
53 ::textutil::trim::trimright string ?regexp?
54 Remove in string any trailing substring according to the regular
55 expression regexp and return the result as a new string. This
56 apply on any line in the string, that is any substring between 2
57 newline chars, or between the beginning of the string and a new‐
58 line, or between a newline and the end of the string, or, if the
59 string contain no newline, between the beginning and the end of
60 the string. The regular expression regexp defaults to "[
61 \\t]+".
62
63 ::textutil::trim::trimPrefix string prefix
64 Removes the prefix from the beginning of string and returns the
65 result. The string is left unchanged if it doesn't have prefix
66 at its beginning.
67
68 ::textutil::trim::trimEmptyHeading string
69 Looks for empty lines (including lines consisting of only white‐
70 space) at the beginning of the string and removes it. The modi‐
71 fied string is returned as the result of the command.
72
74 This document, and the package it describes, will undoubtedly contain
75 bugs and other problems. Please report such in the category textutil
76 of the Tcllib SF Trackers [http://source‐
77 forge.net/tracker/?group_id=12883]. Please also report any ideas for
78 enhancements you may have for either package and/or documentation.
79
81 regexp(n), split(n), string(n)
82
84 prefix, regular expression, string, trimming
85
86
87
88textutil 0.7 textutil::trim(n)