diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-06-29 00:15:46 +0200 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-06-29 00:32:13 +0200 |
| commit | 3522966d9584ec16e2f469acd0fe8727857a9d25 (patch) | |
| tree | f361cd32d54cc874bd3714c1cf9248254638df1d /src | |
| parent | f08dea5fead2f9ef9e0fa114b2e09aa94908d629 (diff) | |
implemented the ^~ pattern match construct: the rest of the pattern will be an Advanced Regular Expression
* Allows searching by regular expressions.
We will never support all ARE constructs in TECO patterns, so this is useful to have available.
* Can only be typed upcaret.
This leaves ^E~q available as an escape-regexp string building construct.
* Once we replace the pattern2regexp converter with a custom terex lexer,
we might want to restrict ^~ to the beginning of the pattern.
Currently, however it can be anywhere, so you can mix TECO patterns with regular expressions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/search.c b/src/search.c index 0df483f..ce4a338 100644 --- a/src/search.c +++ b/src/search.c @@ -425,14 +425,29 @@ teco_pattern2regexp(teco_string_t *pattern, teco_machine_qregspec_t *qreg_machin g_auto(teco_string_t) re = {NULL, 0}; do { - /* - * Previous character was caret. - * Make sure it is handled like a control character. - * This is necessary even though we have string building activated, - * to support constructs like ^Q^Q (typed with carets) in order to - * quote pattern matching characters. - */ if (state == TECO_SEARCH_STATE_CTL) { + if (*pattern->data == '~') { + /* rest of pattern is a regular expression */ + teco_string_append(&re, pattern->data+1, pattern->len-1); + /* + * FIXME: In terex, it actually could contain null bytes. + */ + if (teco_string_contains(re, '\0')) { + g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, + "Regular expression must not contain null-byte" + " - use \\0 instead"); + return NULL; + } + return g_steal_pointer(&re.data) ? : g_strdup(""); + } + + /* + * Previous character was caret. + * Make sure it is handled like a control character. + * This is necessary even though we have string building activated, + * to support constructs like ^Q^Q (typed with carets) in order to + * quote pattern matching characters. + */ *pattern->data = TECO_CTL_KEY(g_ascii_toupper(*pattern->data)); state = TECO_SEARCH_STATE_START; } |
