On Sat, 20 Nov 1999, Brandon Gillespie wrote:
> There is a bug in $buffer.bufsub(), which I think I have fixed. Here is an updated copy:
>
>
> @program $buffer.bufsub() -e=0 +access=pub
> arg buf, a, b;
> var i, la, lb, lt;
>
> // do we need a builtin for this?
> // from Kipp's core (until I write a builtin--optimized by Brandon)
> if (a == b || buflen(a) > buflen(buf) || !a || !buf)
> return buf;
> la = buflen(a);
> lb = buflen(b);
> lt = buflen(buf);
> i = 1;
> anticipate_assignment();
> while (i <= buflen(buf) && (i = bufidx(buf, a, i))) {
> buf = subbuf(buf, 1, i - 1) + b + subbuf(buf, i + la);
> i += lb;
> }
> return buf;
> .
>
> Let me know if this fixes some of the problems people have been reporting lately.
>
> -Brandon
This didn't work for me, it changed the first two occurrences of the
pattern only. Funny thing is that it looks like it should work.
A guaranteed fix, which has side effects though would be to change the
while:
while (i=bufidx(buf,a)) {
this could generate infinite loops if the the pattern also appeared
inside the replacement and is also less efficient, but I figure someone
with more time on their hands will fix this properly ;)
Jon
|