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

BUGS, IDEAS, FEEDBACK

354       This  document,  and the package it describes, will undoubtedly contain
355       bugs and other problems.  Please report such in the  category  textutil
356       of  the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].  Please
357       also report any ideas for enhancements you may have for either  package
358       and/or documentation.
359
360       When proposing code changes, please provide unified diffs, i.e the out‐
361       put of diff -u.
362
363       Note further that  attachments  are  strongly  preferred  over  inlined
364       patches.  Attachments  can  be  made  by  going to the Edit form of the
365       ticket immediately after its creation, and  then  using  the  left-most
366       button in the secondary navigation bar.
367

SEE ALSO

369       regexp(n), split(n), string(n)
370

KEYWORDS

372       TeX, formatting, hyphenation, indenting, paragraph, regular expression,
373       string, trimming
374

CATEGORY

376       Text processing
377
378
379
380tcllib                                0.8                          textutil(n)
Impressum