File 'base/string.tcl' (part of 'Pool_Base')

Description (short)
Additional string operations.
Written by
Andreas Kupries
Description
Additional string operations. Some procedures might be better placed below the standard string command, but I've decided to wait for ensembles before doing this.
Depends on
Tcl
Keywords
string operation, script, tcl code, remove non-essential whitespace, whitespace, replace, file, remove, empty lines, remove, continuation lines, comments, script, capitalize, heading comments, scripts, replication, uncapitalize, chopping, wrap, word wrap, indent, non-essential spacing, spacing, hanging, generate blanks, blank generation, whitespace., prefix, tail


::pool::string::blank (n)

Generates a string consisting out of n spaces. This is a convenient wrapper to ::pool::string::rep for creation of an arbitrary number of spaces.
Argument: n length of the string to generate.
Returns: A string consisting out of n spaces.

::pool::string::cap (string)

Capitalizes first character of the given string. Complementary procedure to ::pool::string::uncap.
Argument: string string to manipulate.
Returns: The string with its first character capitalized.

::pool::string::chop (string)

Removes the last character from the given string.
Argument: string The string to manipulate.
Returns: The string without its last character.

::pool::string::fillPrefixes (arrayVar)

Computes all unique prefixes of the values in arrayVar and maps to their longforms. Can be used to compute all possible shortcuts for a set of (widget) options.
Argument: arrayVar The name of the array containing the keys whose prefixes shall be computed here.

::pool::string::hangingIndent (text prefix)

The specified textblock is indented by prefixing each line after the first !
Notes: This procedure is not checked by the testsuite.
Argument: text The paragraph to indent.
Argument: prefix The string to use as prefix for each line of text with.
Returns: Basically text, but indented a certain amount.

::pool::string::indent (text prefix)

The specified textblock is indented by prefixing each line.
Notes: This procedure is not checked by the testsuite.
Argument: text The paragraph to indent.
Argument: prefix The string to use as prefix for each line of text with.
Returns: Basically text, but indented a certain amount.

::pool::string::multipleReplaceInFile (file replacements)

Replaces all occurences of the strings named as keys of the array variable replacements in the named file with the associated values. The same functionality as provided by ::pool::string::replaceInFile, but for a set of strings.
Notes: There are no guarantees about the order of replacements. The file read completely into memory before processing it. The file must be readable and writable. This procedure is not checked by the testsuite.
Argument: file name of the file to modify..
Argument: replacements name of an array variable containing strings and their corresponding substitutions.

::pool::string::oneLine (text)

Compresses the given text into a single line. Convenience procedure.
Argument: text The string to compress.
Returns: The compressed string

::pool::string::prefixMap (arrayVar)

Same as ::pool::string::fillPrefixes, but the original contents of arrayVar will be removed.
Argument: arrayVar The name of the array containing the keys whose prefixes shall be computed here.

::pool::string::removeComments (text)

Removes comments and continuation lines from tcl code stored in text and returns the modified result. The process used here will leave regular expressions and strings intact whilst doing at least some compression.
Notes: This procedure is not checked by the testsuite.
Argument: text the string to compress.
Returns: The compressed string

::pool::string::removeContinuations (text)

Removes continuation lines from the tcl code specified in text.
Notes: This procedure is not checked by the testsuite.
Argument: text The string to compress.
Returns: The compressed string

::pool::string::removeSpaces (text)

Removes all non-essential spacing from tcl-code stored in text and returns the modified result. Only spaces, tabs and line-endings are considered as spacing.
Notes: This procedure is not checked by the testsuite.
Argument: text The string to compress.
Returns: The compressed string

::pool::string::removeWhitespace (text)

Removes all non-essential whitespace from the tcl-code stored in text and returns the modified result. Comments are considered as whitespace!
Notes: This procedure is not checked by the testsuite.
Argument: text The string to compress.
Returns: The compressed string

::pool::string::rep (n text)

Replicates n times the string text.
Notes: This algorithm proved to be rather fast, even in the small range of n in {60..90}. An alternative definition using regsub and format with O(n) complexity, thus doing most things at C-level is beaten regularly for n > 74!
Argument: n Number of replications. A value < 0 is handled as 0
Argument: text string to replicate.
Returns: The text, replicated n times.

::pool::string::replace (string from to new)

Replaces the part of the string between indices from and <to> with the text in new. to must not be smaller than from.
Argument: string The string to manipulate.
Argument: from The index of the first character to cut out of string.
Argument: to The index behind the last character to cut of string. The special value 'new' denotes replacement to the end of the string.
Argument: new (= {}) The string replacing the information cut out of string.
Returns: The changed string.

::pool::string::replaceInFile (file before after)

Replaces all occurences of before in the named file with the string after. before can be any legal regexp pattern and after may use \<i> syntax to denote parts of the matched expression.
Notes: The file is read completely into memory before processing it. The file must be readable and writable. This procedure is not checked by the testsuite.
Argument: file name of the file to modify..
Argument: before string to search for (and to replace by after).
Argument: after string to insert in place of before.

::pool::string::rhc (text)

Removes the heading comments from tcl code stored in text and returns the modified result. Empty lines between comment lines are considered as part of the comment block and therefore removed.
Argument: text The code block to manipulate.
Returns: Basically text, but without heading comments.

::pool::string::rhel (text)

Removes the Heading Empty Lines of text.
Argument: text The text block to manipulate.
Returns: The text, but without heading empty lines.

::pool::string::stripPrefix (text prefix)

Strips prefix from text, if found at its start.
Argument: text The string to check for prefix.
Argument: prefix The string to remove from text.
Returns: The text, but without prefix.

::pool::string::tail (string)

Removes the first character from the given string. Convenience procedure.
Argument: string string to manipulate.
Returns: The string without its first character.

::pool::string::uncap (string)

unCapitalizes first character of the given string. Complementary procedure to ::pool::string::cap.
Argument: string string to manipulate.
Returns: The string with its first character uncapitalized.

::pool::string::wrap (text len)

by Jeffrey Hobbs
Wraps the given text into multiple lines not exceeding len characters each. Lines shorter than len characters might get filled up.
Notes: This procedure is not checked by the testsuite.
Argument: text The string to operate on.
Argument: len The maximum allowed length of a single line.
Returns: Basically text, but with changed newlines to restrict the length of individual lines to at most len characters.


Generated by AutoDoc 2.4 at 09/14/2000, invoked by Andreas Kupries