summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-10-21 13:27:31 -0400
committerKaz Kylheku <kaz@kylheku.com>2011-10-21 13:27:31 -0400
commite98d94aa2a8c46c392eec4b7ac664eb989f3c589 (patch)
treea656c2267ebf3fc1e62f5606e914bcf9f7860825 /lib.c
parent7cf8f4c01a851c8dc3158802df0d5132d146bf69 (diff)
downloadtxr-e98d94aa2a8c46c392eec4b7ac664eb989f3c589.tar.gz
txr-e98d94aa2a8c46c392eec4b7ac664eb989f3c589.tar.bz2
txr-e98d94aa2a8c46c392eec4b7ac664eb989f3c589.zip
New features. Strling list output streams in stream
library, allow output to be captured as a list of strings representing lines (in contrast to string streams which capture a single string). The output directive can output to a variable, and next can scan over a variable. * lib.c (span_str, compl_span_str, break_str): New functions. * lib.h (span_str, compl_span_str, break_str): New functions declared. * match.c (into_k, var_k): New keyword variables. (mf_file_data): New static function. (v_next): Refactored argument handling. Added support for :var keyword. (v_output): Added support for :into keyword. * stream.c (strlist_mark, strlist_out_put_string, strlist_out_put_char): New static functions. (strlist_out_ops): New static struct. (make_strlist_output_stream, get_list_from_stream): New functions. * stream.h (make_strlist_output_stream, get_list_from_stream): New functions declared.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 91e958b8..c773ca60 100644
--- a/lib.c
+++ b/lib.c
@@ -1199,6 +1199,32 @@ val chr_str_set(val str, val index, val chr)
return chr;
}
+val span_str(val str, val set)
+{
+ const wchar_t *cstr = c_str(str);
+ const wchar_t *cset = c_str(set);
+ size_t span = wcsspn(cstr, cset);
+ return num(span);
+}
+
+val compl_span_str(val str, val set)
+{
+ const wchar_t *cstr = c_str(str);
+ const wchar_t *cset = c_str(set);
+ size_t span = wcscspn(cstr, cset);
+ return num(span);
+}
+
+val break_str(val str, val set)
+{
+ const wchar_t *cstr = c_str(str);
+ const wchar_t *cset = c_str(set);
+ const wchar_t *brk = wcspbrk(cstr, cset);
+ if (!brk)
+ return nil;
+ return num(brk - cstr);
+}
+
val symbol_name(val sym)
{
if (sym)