Next: Control Sequence Reading, Previous: Helper Macros, Up: Top [Contents][Index]
Given a character string, checking whether it matches a control sequence is quite trivial, with only the standard C library:
char const *str /* = ... */; int row, col; if (0 == strcmp(str, CTLSEQS_XTVERSION())) { // ... } else if (2 == sscanf(str, CTLSEQS_CUP("%d", "%d"), &row, &col)) { // ... } else { // ... }
However, as the number of possible matches grows, this naive implementation becomes less efficient and harder to maintain.
Such problems can be easily solved by using the control sequence matcher provided by ctlseqs.
The struct ctlseqs_matcher *
is a pointer to an opaque type which
represents an instance of control sequence matcher. Before using, the matcher
should be initialized with ctlseqs_matcher_init
. After used, it should
be deallocated with ctlseqs_matcher_free
.
struct ctlseqs_matcher *matcher = ctlseqs_matcher_init(); // ... ctlseqs_matcher_free(matcher);
On rare occurences when ctlseqs fail to allocate enough memory, function
ctlseqs_matcher_init
may return NULL
.
However, it is safe to pass null pointers to ctlseqs_matcher_free
.
• Matcher Configuration | Configuring a control sequence matcher | |
• Matching String | Matching a string with control sequence matcher |