From 9c0e5743188588ece98197880a3f1174170dc563 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 1 Sep 2023 19:26:35 -0700 Subject: New function: str-esc. * lib.[ch] (str_esc): New function. * eval.c (eval_init): str-esc intrinsic registered. * tests/015/esc.tl: New file. * txr.1: Documented. --- lib.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib.c') diff --git a/lib.c b/lib.c index e5d01387..422dbe57 100644 --- a/lib.c +++ b/lib.c @@ -6400,6 +6400,26 @@ val trim_str(val str) } } +val str_esc(val escset, val escchr, val str) +{ + val self = lit("shell-escape"); + val out = mkstring(zero, chr(' ')); + const wchar_t *s = c_str(str, self); + const wchar_t *es = c_str(escset, self); + wchar_t ch; + + while ((ch = *s++)) { + if (wcschr(es, ch)) { + string_extend(out, escchr, nil); + string_extend(out, chr(ch), nil); + } else { + string_extend(out, chr(ch), nil); + } + } + + return string_finish(out); +} + val cmp_str(val astr, val bstr) { val self = lit("cmp-str"); -- cgit v1.2.3