Tcl_StringMatch(3tcl)

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

πŸ’– 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 is TCL_MATCH_NOCASE. passing 0 means 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_StringMatch returns 1. slay. βœ…
  • if it doesn't? Tcl_StringMatch returns 0. 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