diff options
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; } |
