summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-13 18:35:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-13 18:35:52 -0700
commit7864acb3e7baaed37356562b7d74259d0cfa1d17 (patch)
tree6161c358f26fabd59fc5ad7ee5e56cbbcedb0ecf
parentf35f559b7ed6455af72b995a2cacd19d44cf32fd (diff)
downloadtxr-7864acb3e7baaed37356562b7d74259d0cfa1d17.tar.gz
txr-7864acb3e7baaed37356562b7d74259d0cfa1d17.tar.bz2
txr-7864acb3e7baaed37356562b7d74259d0cfa1d17.zip
* regex.c (regsub): the replacement argument
can now be a function of one argument which maps the original piece of text matched by the regex to a replacement text.
-rw-r--r--ChangeLog7
-rw-r--r--regex.c5
2 files changed, 11 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index ffccdb02..09356ae7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2012-03-13 Kaz Kylheku <kaz@kylheku.com>
+ * regex.c (regsub): the replacement argument
+ can now be a function of one argument which maps
+ the original piece of text matched by the regex
+ to a replacement text.
+
+2012-03-13 Kaz Kylheku <kaz@kylheku.com>
+
* stream.c (stdio_put_string, stdio_put_char, stdio_put_byte): Do not
consider data sent to std_error to be output for the purposes of
the output_produced flag. Otherwise the program behavior changes
diff --git a/regex.c b/regex.c
index 60f5cd2d..9d07f411 100644
--- a/regex.c
+++ b/regex.c
@@ -1728,6 +1728,7 @@ val regsub(val regex, val repl, val str)
{
list_collect_decl (out, ptail);
val pos = zero;
+ val isfunc = functionp(repl);
do {
cons_bind (find, len, search_regex(str, regex, pos, nil));
@@ -1738,7 +1739,9 @@ val regsub(val regex, val repl, val str)
break;
}
list_collect(ptail, sub_str(str, pos, find));
- list_collect(ptail, repl);
+ list_collect(ptail, if3(isfunc,
+ funcall1(repl, sub_str(str, find, plus(find, len))),
+ repl));
if (len == zero && eql(find, pos)) {
if (lt(pos, length_str(str))) {
list_collect(ptail, chr_str(str, pos));