1textutil(n)       Text and string utilities, macro processing      textutil(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       textutil - Procedures to manipulate texts and strings.
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require textutil  ?0.7.1?
14
15       ::textutil::adjust string args
16
17       ::textutil::adjust::readPatterns filename
18
19       ::textutil::adjust::listPredefined
20
21       ::textutil::adjust::getPredefined filename
22
23       ::textutil::indent string prefix ?skip?
24
25       ::textutil::undent string
26
27       ::textutil::splitn string ?len?
28
29       ::textutil::splitx string ?regexp?
30
31       ::textutil::tabify string ?num?
32
33       ::textutil::tabify2 string ?num?
34
35       ::textutil::trim string ?regexp?
36
37       ::textutil::trimleft string ?regexp?
38
39       ::textutil::trimright string ?regexp?
40
41       ::textutil::trimPrefix string prefix
42
43       ::textutil::trimEmptyHeading string
44
45       ::textutil::untabify string ?num?
46
47       ::textutil::untabify2 string ?num?
48
49       ::textutil::strRepeat text num
50
51       ::textutil::blank num
52
53       ::textutil::chop string
54
55       ::textutil::tail string
56
57       ::textutil::cap string
58
59       ::textutil::uncap string
60
61       ::textutil::longestCommonPrefixList list
62
63       ::textutil::longestCommonPrefix ?string...?
64
65_________________________________________________________________
66

DESCRIPTION

68       The textutil package provides commands that manipulate strings or texts
69       (a.k.a. long strings or string with embedded newlines or paragraphs).
70
71       The complete set of procedures is described below.
72
73       ::textutil::adjust string args
74              Do a justification on the string according to args.  The  string
75              is  taken as one big paragraph, ignoring any newlines.  Then the
76              line is formatted according to the options used, and the command
77              return  a new string with enough lines to contain all the print‐
78              able chars in the input string. A line is a set of chars between
79              the  beginning  of  the  string and a newline, or between 2 new‐
80              lines, or between a newline and the end of the  string.  If  the
81              input  string is small enough, the returned string won't contain
82              any newlines.
83
84              Together with ::textutil::indent it is possible to create  prop‐
85              erly wrapped paragraphs with arbitrary indentations.
86
87              By  default,  any  occurrence of spaces characters or tabulation
88              are replaced by a single space so each word in a line  is  sepa‐
89              rated  from  the  next  one  by exactly one space char, and this
90              forms a real line. Each real line is placed in a  logical  line,
91              which  have  exactly  a given length (see -length option below).
92              The real line may have a lesser length. Again  by  default,  any
93              trailing  spaces  are  ignored  before returning the string (see
94              -full option below). The following options may be used after the
95              string  parameter,  and  change the way the command place a real
96              line in a logical line.
97
98              -full boolean
99                     If set to false, any trailing  space  chars  are  deleted
100                     before returning the string. If set to true, any trailing
101                     space chars are left in the string. Default to false.
102
103              -hyphenate boolean
104                     if set to false, no hyphenation will be done. If  set  to
105                     true,  the last word of a line is tried to be hyphenated.
106                     Defaults to false. Note:  hyphenation  patterns  must  be
107                     loaded prior, using the command ::textutil::adjust::read‐
108                     Patterns.
109
110              -justify center|left|plain|right
111                     Set the justification of the returned string  to  center,
112                     left, plain or right. By default, it is set to left.  The
113                     justification means that any line in the returned  string
114                     but  the last one is build according to the value. If the
115                     justification is set to plain and the number of printable
116                     chars  in the last line is less than 90% of the length of
117                     a line (see -length), then this line  is  justified  with
118                     the  left value, avoiding the expansion of this line when
119                     it is too small. The meaning of each value is:
120
121                     center The real line is centered in the logical line.  If
122                            needed, a set of space characters are added at the
123                            beginning (half of the needed set) and at the  end
124                            (half  of  the needed set) of the line if required
125                            (see the option -full).
126
127                     left   The real line is set on the left  of  the  logical
128                            line.  It  means  that there are no space chars at
129                            the beginning  of  this  line.  If  required,  all
130                            needed  space  chars  are  added at the end of the
131                            line (see the option -full).
132
133                     plain  The real line is exactly set in the logical  line.
134                            It  means  that  there  are no leading or trailing
135                            space chars. All the needed space chars are  added
136                            in the real line, between 2 (or more) words.
137
138                     right  The  real  line is set on the right of the logical
139                            line. It means that there are no  space  chars  at
140                            the  end of this line, and there may be some space
141                            chars at  the  beginning,  despite  of  the  -full
142                            option.
143
144              -length integer
145                     Set the length of the logical line in the string to inte‐
146                     ger.  integer must be a positive integer value.  Defaults
147                     to 72.
148
149              -strictlength boolean
150                     If  set to false, a line can exceed the specified -length
151                     if a single word is longer than -length. If set to  true,
152                     words  that  are longer than -length are split so that no
153                     line exceeds the specified -length. Defaults to false.
154
155       ::textutil::adjust::readPatterns filename
156              Loads the internal storage for  hyphenation  patterns  with  the
157              contents  of  the  file  filename.  This has to be done prior to
158              calling command ::textutil::adjust with  "-hyphenate  true",  or
159              the hyphenation process will not work correctly.
160
161              The package comes with a number of predefined pattern files, and
162              the command ::textutil::adjust::listPredefined can  be  used  to
163              find out their names.
164
165       ::textutil::adjust::listPredefined
166              This  command returns a list containing the names of the hyphen‐
167              ation files coming with this package.
168
169       ::textutil::adjust::getPredefined filename
170              Use this command to query the package for the full path name  of
171              the  hyphenation file filename coming with the package. Only the
172              filenames   found   in   the   list   returned    by    ::textu‐
173              til::adjust::listPredefined  are  legal  arguments for this com‐
174              mand.
175
176       ::textutil::indent string prefix ?skip?
177              Each line in the string indented by adding the string prefix  at
178              its  beginning. The modified string is returned as the result of
179              the command.
180
181              If skip is specified the first skip lines  are  left  untouched.
182              The  default  for  skip  is  0,  causing the modification of all
183              lines. Negative values for skip are treated  like  0.  In  other
184              words, skip > 0 creates a hanging indentation.
185
186              Together  with ::textutil::adjust it is possible to create prop‐
187              erly wrapped paragraphs with arbitrary indentations.
188
189       ::textutil::undent string
190              The command computes the common prefix for all lines  in  string
191              consisting solely out of whitespace, removes this from each line
192              and returns the modified string.
193
194              Lines containing only whitespace  are  always  reduced  to  com‐
195              pletely  empty lines. They and empty lines are also ignored when
196              computing the prefix to remove.
197
198              Together with ::textutil::adjust it is possible to create  prop‐
199              erly wrapped paragraphs with arbitrary indentations.
200
201       ::textutil::splitn string ?len?
202              This  command splits the given string into chunks of len charac‐
203              ters and returns a list containing these  chunks.  The  argument
204              len defaults to 1 if none is specified. A negative length is not
205              allowed and will cause the command to throw an error.  Providing
206              an  empty  string  as  input  is  allowed, the command will then
207              return an empty list. If the length of  the  string  is  not  an
208              entire  multiple of the chunk length, then the last chunk in the
209              generated list will be shorter than len.
210
211       ::textutil::splitx string ?regexp?
212              Split the string and return a list. The string is split  accord‐
213              ing to the regular expression regexp instead of a simple list of
214              chars. Note that if you add parenthesis  into  the  regexp,  the
215              parentheses  part of separator would be added into list as addi‐
216              tional element. If the string is empty the result is  the  empty
217              list,  like for split. If regexp is empty the string is split at
218              every character, like split does.  The regular expression regexp
219              defaults to "[\\t \\r\\n]+".
220
221       ::textutil::tabify string ?num?
222              Tabify  the string by replacing any substring of num space chars
223              by a tabulation and return the  result  as  a  new  string.  num
224              defaults to 8.
225
226       ::textutil::tabify2 string ?num?
227              Similar  to  ::textutil::tabify this command tabifies the string
228              and returns the result as a new string. A different algorithm is
229              used  however.  Instead of replacing any substring of num spaces
230              this command works more like an editor. num defaults to 8.
231
232              Each line of the text in string is treated as if there are  tab‐
233              stops every num columns. Only sequences of space characters con‐
234              taining more than one  space  character  and  found  immediately
235              before a tabstop are replaced with tabs.
236
237       ::textutil::trim string ?regexp?
238              Remove in string any leading and trailing substring according to
239              the regular expression regexp and return the  result  as  a  new
240              string.   This apply on any line in the string, that is any sub‐
241              string between 2 newline chars, or between the beginning of  the
242              string  and  a  newline, or between a newline and the end of the
243              string, or, if the string contain no newline, between the begin‐
244              ning  and  the end of the string.  The regular expression regexp
245              defaults to "[ \\t]+".
246
247       ::textutil::trimleft string ?regexp?
248              Remove in string any leading substring according to the  regular
249              expression  regexp  and  return the result as a new string. This
250              apply on any line in the string, that is any substring between 2
251              newline chars, or between the beginning of the string and a new‐
252              line, or between a newline and the end of the string, or, if the
253              string  contain no newline, between the beginning and the end of
254              the string.   The  regular  expression  regexp  defaults  to  "[
255              \\t]+".
256
257       ::textutil::trimright string ?regexp?
258              Remove in string any trailing substring according to the regular
259              expression regexp and return the result as a  new  string.  This
260              apply on any line in the string, that is any substring between 2
261              newline chars, or between the beginning of the string and a new‐
262              line, or between a newline and the end of the string, or, if the
263              string contain no newline, between the beginning and the end  of
264              the  string.   The  regular  expression  regexp  defaults  to "[
265              \\t]+".
266
267       ::textutil::trimPrefix string prefix
268              Removes the prefix from the beginning of string and returns  the
269              result.  The  string is left unchanged if it doesn't have prefix
270              at its beginning.
271
272       ::textutil::trimEmptyHeading string
273              Looks for empty lines (including lines consisting of only white‐
274              space)  at the beginning of the string and removes it. The modi‐
275              fied string is returned as the result of the command.
276
277       ::textutil::untabify string ?num?
278              Untabify the string by replacing any tabulation char by  a  sub‐
279              string of num space chars and return the result as a new string.
280              num defaults to 8.
281
282       ::textutil::untabify2 string ?num?
283              Untabify the string by replacing any tabulation char by  a  sub‐
284              string of at most num space chars and return the result as a new
285              string. Unlike textutil::untabify each tab is not replaced by  a
286              fixed  number  of  space  characters.  The command overlays each
287              line in the string with tabstops every num columns  instead  and
288              replaces  tabs  with  just  enough space characters to reach the
289              next tabstop. This is the complement of  the  actions  taken  by
290              ::textutil::tabify2. num defaults to 8.
291
292              There is one asymmetry though: A tab can be replaced with a sin‐
293              gle space, but not the other way around.
294
295       ::textutil::strRepeat text num
296              The implementation depends on the core  executing  the  package.
297              Used  string  repeat if it is present, or a fast tcl implementa‐
298              tion if it is not. Returns a string containing the text repeated
299              num times. The repetitions are joined without characters between
300              them. A value of num <= 0 causes the command to return an  empty
301              string.
302
303       ::textutil::blank num
304              A convenience command. Returns a string of num spaces.
305
306       ::textutil::chop string
307              A  convenience command. Removes the last character of string and
308              returns the shortened string.
309
310       ::textutil::tail string
311              A convenience command. Removes the first character of string and
312              returns the shortened string.
313
314       ::textutil::cap string
315              Capitalizes  the first character of string and returns the modi‐
316              fied string.
317
318       ::textutil::uncap string
319              The complementary operation to ::textutil::cap. Forces the first
320              character  of  string  to  lower  case  and returns the modified
321              string.
322
323       ::textutil::longestCommonPrefixList list
324
325       ::textutil::longestCommonPrefix ?string...?
326              Computes the longest common prefix for either the strings  given
327              to the command, or the strings specified in the single list, and
328              returns it as the result of the command.
329
330              If no strings were specified the result is the empty string.  If
331              only one string was specified, the string itself is returned, as
332              it is its own longest common prefix.
333

SEE ALSO

335       regexp(n), split(n), string(n)
336

KEYWORDS

338       TeX, formatting, hyphenation, indenting, paragraph, regular expression,
339       string, trimming
340
341
342
343textutil                             0.7.1                         textutil(n)
Impressum