summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-09-01 19:26:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-09-01 19:26:35 -0700
commit9c0e5743188588ece98197880a3f1174170dc563 (patch)
tree6e94c391062b28a5277025bdeac9127fdc483483 /lib.c
parent43f64bd2d69cf39d09c4a3b96cd28d0966a6eda6 (diff)
downloadtxr-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.c20
1 files changed, 20 insertions, 0 deletions
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");