Tcl_StringMatch(3tcl)
π Tcl_StringMatch β the Tcl Library Procedures glow-up π
okay bestie, sit down, hydrate, because today we're talking about two little functions from the Tcl Library Procedures that are lowkey the backbone of every "does this thing match that thing" moment in your code. say hi to Tcl_StringMatch and Tcl_StringCaseMatch π
β¨ NAME β¨
Tcl_StringMatch, Tcl_StringCaseMatch β test whether a string matches a pattern π¦
like. that's it. that's the whole job. but the way they do it? iconic.
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_StringMatch(str, pattern)
int
Tcl_StringCaseMatch(str, pattern, flags)
π ARGUMENTS π
const char *str(in) β the string you're testing. the main character, the one on trial, the it-girl under the spotlight πconst char *pattern(in) β the pattern you're matching against that string. she can contain special characters from the set*?\[]β yes those four, no more, don't get creative β¨int flags(in) β an OR-ed combination of match flags. rn the only one on the roster isTCL_MATCH_NOCASE. passing0means you want a case-sensitive search, i.e. capital letters MATTER, periodt π₯
π DESCRIPTION π
so here's the tea π: this utility procedure figures out whether a string matches a given pattern.
- if it does?
Tcl_StringMatchreturns1. slay. β - if it doesn't?
Tcl_StringMatchreturns0. not slay. π
the algorithm it uses for matching is the same algorithm used in the string match Tcl command, and it's similar to the algorithm the C-shell uses for file name matching. if you want the full lore, go read the Tcl manual entry for the details β iykyk π
now for Tcl_StringCaseMatch: same algorithm, same energy, but you get the option to make the matching case-insensitive. if you choose that path (by passing TCL_MATCH_NOCASE), then the string and the pattern are essentially matched in the lower case. so like, A and a stop being enemies and start being besties π«Ά
π KEYWORDS π
match, pattern, string β the holy trinity, no cap β
and that's the whole page, bestie!! this was Tcl_StringMatch(3tcl) from Tcl 8.5, and yes she's been holding it down since forever. go forth and match responsibly πβ¨π
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1989-1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms