From 3522966d9584ec16e2f469acd0fe8727857a9d25 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 29 Jun 2026 00:15:46 +0200 Subject: 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. --- src/search.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3