diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-09-01 19:26:35 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-09-01 19:26:35 -0700 |
commit | 9c0e5743188588ece98197880a3f1174170dc563 (patch) | |
tree | 6e94c391062b28a5277025bdeac9127fdc483483 /lib.c | |
parent | 43f64bd2d69cf39d09c4a3b96cd28d0966a6eda6 (diff) | |
download | txr-9c0e5743188588ece98197880a3f1174170dc563.tar.gz txr-9c0e5743188588ece98197880a3f1174170dc563.tar.bz2 txr-9c0e5743188588ece98197880a3f1174170dc563.zip |
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.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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"); |