From c17054aa390ce42e867d9ce7b5fd821e0c666d45 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 5 Oct 2015 06:17:31 -0700 Subject: Copy lazy strings without forcing. * lib.c (copy_lazy_str): New static function. (copy_str): Use copy_lazy_str to copy lazy strings. * txr.1: Documentation added under copy-str. --- lib.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index c54924fe..87abf0b9 100644 --- a/lib.c +++ b/lib.c @@ -2543,9 +2543,13 @@ val init_str(val str, const wchar_t *data) return str; } +static val copy_lazy_str(val lstr); + val copy_str(val str) { - return string(c_str(str)); + return if3(lazy_stringp(str), + copy_lazy_str(str), + string(c_str(str))); } val upcase_str(val str) @@ -5683,6 +5687,17 @@ val lazy_str(val lst, val term, val limit) return obj; } +static val copy_lazy_str(val lstr) +{ + val obj = make_obj(); + obj->ls.type = LSTR; + obj->ls.opts = obj->ls.list = obj->ls.prefix = nil; + obj->ls.prefix = copy_str(lstr->ls.prefix); + obj->ls.list = lstr->ls.list; + obj->ls.opts = lstr->ls.opts; + return obj; +} + val lazy_str_force(val lstr) { val lim, term; -- cgit v1.2.3