text...trim(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– text...trim β€” aka the Text and string utilities, macro processing glow-up πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about textutil::trim, a whole package from the Text and string utilities, macro processing corner of the world that just... trims strings. With regexes. Iconic behavior honestly.


✨ NAME ✨

textutil::trim β€” the procedures that trim strings πŸŽ€


✨ SYNOPSIS ✨

package require Tcl 8.5 9

package require textutil::trim ?0.8?

::textutil::trim::trim string ?regexp?

::textutil::trim::trimleft string ?regexp?

::textutil::trim::trimright string ?regexp?

::textutil::trim::trimPrefix string prefix

::textutil::trim::trimEmptyHeading string

✨ DESCRIPTION ✨

so the textutil::trim package hands you a bunch of commands that trim strings using arbitrary regular expressions. no cap. whatever regex you want, it'll trim with it.

and here's the full lineup of procedures, described one by one, because we do not skip anybody in this house πŸ’…


  • ::textutil::trim::trim string ?regexp?

Removes from string any leading and trailing substring that matches the regular expression regexp, and returns the result as a brand new string. and this happens for all lines in the string β€” meaning any substring between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string, or, if the string contains no newline at all, between the beginning and the end of the string. the regexp defaults to "[ \t]+". yes really, that's the default, go off.

  • ::textutil::trim::trimleft string ?regexp?

Removes from string any leading substring that matches the regular expression regexp, and returns the result as a new string. this applies to any line in the string β€” any substring between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string, or, if the string contains no newline, between the beginning and the end of the string. the regexp defaults to "[ \t]+". left side only, she's selective like that πŸ¦‹

  • ::textutil::trim::trimright string ?regexp?

Removes from string any trailing substring that matches the regular expression regexp, and returns the result as a new string. this applies to any line in the string β€” any substring between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string, or, if the string contains no newline, between the beginning and the end of the string. the regexp defaults to "[ \t]+". right side only, she's the mirror twin ✨

  • ::textutil::trim::trimPrefix string prefix

Removes the prefix from the beginning of string and returns the result. and here's the key part, bestie: the string is left unchanged if it doesn't have prefix at its beginning. no prefix, no touch, we respect boundaries πŸ’œ

  • ::textutil::trim::trimEmptyHeading string

Looks for empty lines (and yes, that includes lines consisting of only whitespace) at the beginning of the string and removes them. the modified string comes back as the result of the command. bye bye dead air at the top 🫢


πŸ› BUGS, IDEAS, FEEDBACK πŸ›

not to be dramatic but: this document, and the package it describes, will undoubtedly contain bugs and other problems. the manpage said it, not me 😭

please report such things in the category textutil of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist). and please also report any ideas for enhancements you may have for either the package and/or the documentation. we love a glow-up suggestion.

when proposing code changes, please provide unified diffs, i.e. the output of diff -u.

also note, and this is important: attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. okay? okay. πŸ’–


πŸ‘€ SEE ALSO πŸ‘€

regexp(3tcl), split(3tcl), string(3tcl)


πŸ”‘ KEYWORDS πŸ”‘

prefix, regular expression, string, trimming


πŸ—‚οΈ CATEGORY πŸ—‚οΈ

Text processing


and that's the whole page, no notes, we ate πŸ“

tcllib, version 0.8, and it's filed under text...trim(3tcl) β€” mwah, sending you off with a forehead kiss and a working regex πŸ’…βœ¨

πŸ“¦ where this page comes from