MatchEditor(3I)

πŸ’– MatchEditor(3I) πŸ’–

okay bestie, welcome to the InterViews Reference Manual ✨ this one's about MatchEditor, a StringEditor with pattern matching, and honestly? it's giving ✨format police✨ in the best way possible.


🌸 NAME 🌸

MatchEditor β€” a StringEditor with pattern matching πŸŽ€


✨ SYNOPSIS ✨

#include <InterViews/matcheditor.h>

πŸ¦‹ DESCRIPTION πŸ¦‹

so MatchEditor is a StringEditor subclass (yes, it inherits, we love a nepo baby πŸ‘‘) and what it does is check whether its contents are actually valid against a pattern you give it. vibe check for strings, fr fr πŸ’…

when would you even use this? when you need the user to type something that has to be in a specific format β€” like a number, or a file name. you know, the stuff where chaos is not cute πŸ™ˆ

the matching pattern follows the rules of scanf(3). and because examples just hit different, here's some:

  • pattern "%3d" β†’ matches a 3-digit integer πŸ”’
  • pattern "%[ab]" β†’ matches a string that only contains a's and b's πŸ…°οΈπŸ…±οΈ
  • pattern "(%f, %f)" β†’ matches the string "(12.0, 5E23)" 🌈

periodt. that's the whole concept.


πŸ’œ PUBLIC OPERATIONS πŸ’œ

  • MatchEditor(ButtonState*, const char* sample, const char* done) β€” makes a brand new MatchEditor object. the ButtonState, the sample string, and the termination string done all get passed straight on down to the StringEditor constructor. teamwork makes the dream work 🫢
  • void Match(const char* pattern, boolean keystroke = true) β€” this is where you tell it what to match against. when MatchEditor does its matching thing, it will highlight any trailing part of the edit string that doesn't conform to pattern, so the user can see exactly what's wrong and fix it. iconic, honestly πŸ‘‘

and the keystroke situation: if keystroke is true, matching happens on every single keystroke (instant feedback, main character energy ✨). if it's false, matching only happens when the edit is completed (chill, lowkey, patient vibes 🌸).

some defaults for you: the initial pattern matches any string, and the initial value of keystroke is true πŸ’–


πŸŽ€ RESTRICTIONS πŸŽ€

okay so here's the fine print and we're gonna say it clearly because it matters:

MatchEditor uses sscanf internally to check the pattern match. and different versions of sscanf have different scanning capabilities β€” so the patterns you can actually use depend on your local version. go check with your local version to see what patterns you've got available. no cap, this is a real "your mileage may vary" moment πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

  • StringEditor(3I) β€” the parent, the blueprint, the origin story 🌟

and that's a wrap, bestie!! this page came from the InterViews manual, dated 7 Dec 1989 β€” yes, 1989, ancient but still slaying, we love a vintage icon πŸ’…πŸ’– byeee πŸ¦‹