diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-10-05 06:17:31 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-10-05 06:17:31 -0700 |
commit | c17054aa390ce42e867d9ce7b5fd821e0c666d45 (patch) | |
tree | 8000cfc275beeb0b2e0c7c4421cc00a1ad79f34a | |
parent | 75ddca922ba8dcaf696f23f613b1a9f594a1884f (diff) | |
download | txr-c17054aa390ce42e867d9ce7b5fd821e0c666d45.tar.gz txr-c17054aa390ce42e867d9ce7b5fd821e0c666d45.tar.bz2 txr-c17054aa390ce42e867d9ce7b5fd821e0c666d45.zip |
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.
-rw-r--r-- | lib.c | 17 | ||||
-rw-r--r-- | txr.1 | 12 |
2 files changed, 28 insertions, 1 deletions
@@ -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; @@ -16133,6 +16133,18 @@ function constructs a new string whose contents are identical to .metn string . +If +.meta string +is a lazy string, then a lazy string is constructed with the +same attributes as +.metn string . +The new lazy string has its own copy of the prefix portion of +.meta string +which has been forced so far. The unforced list and separator +string are shared between +.meta string +and the newly constructed lazy string. + .coNP Function @ upcase-str .synb .mets (upcase-str << string ) |