Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The most important early product on the way to developing a good product is an imperfect version.


devel / comp.lang.forth / Win32Forth REPLACE with a buffer > 255 characters

SubjectAuthor
* Win32Forth REPLACE with a buffer > 255 charactersHowerd Oakford
+* Re: Win32Forth REPLACE with a buffer > 255 charactersdxforth
|+- Re: Win32Forth REPLACE with a buffer > 255 charactersdxforth
|`* Re: Win32Forth REPLACE with a buffer > 255 charactersHowerd Oakford
| +- Re: Win32Forth REPLACE with a buffer > 255 charactersdxforth
| `* Re: Win32Forth REPLACE with a buffer > 255 charactersNN
|  `- Re: Win32Forth REPLACE with a buffer > 255 charactersdxforth
+* Re: Win32Forth REPLACE with a buffer > 255 charactersHans Bezemer
|+- Re: Win32Forth REPLACE with a buffer > 255 charactersdxforth
|`* Re: Win32Forth REPLACE with a buffer > 255 charactersGerry Jackson
| `* Re: Win32Forth REPLACE with a buffer > 255 charactersDoug Hoffman
|  `* Re: Win32Forth REPLACE with a buffer > 255 charactersdxforth
|   +- Re: Win32Forth REPLACE with a buffer > 255 charactersDoug Hoffman
|   `* Re: Win32Forth REPLACE with a buffer > 255 charactersHans Bezemer
|    `- Re: Win32Forth REPLACE with a buffer > 255 charactersHans Bezemer
+* Re: Win32Forth REPLACE with a buffer > 255 charactersRick C
|`* Re: Win32Forth REPLACE with a buffer > 255 charactersdxforth
| `* Re: Win32Forth REPLACE with a buffer > 255 charactersRick C
|  `* Re: Win32Forth REPLACE with a buffer > 255 charactersRick C
|   `- Re: Win32Forth REPLACE with a buffer > 255 charactersdxforth
`* Re: Win32Forth REPLACE with a buffer > 255 charactersGerry Jackson
 `- Re: Win32Forth REPLACE with a buffer > 255 charactersHowerd Oakford

1
Win32Forth REPLACE with a buffer > 255 characters

<smiq1s$opj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15224&group=comp.lang.forth#15224

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: how...@inventio.co.uk (Howerd Oakford)
Newsgroups: comp.lang.forth
Subject: Win32Forth REPLACE with a buffer > 255 characters
Date: Thu, 11 Nov 2021 11:07:56 +0100
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <smiq1s$opj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 11 Nov 2021 10:07:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="13f566b497cc23cfc02d39ac81a71873";
logging-data="25395"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PB3Mzbc5mahVjakey/udv"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Cancel-Lock: sha1:moKQoboRVcgtKDeZIbwICQys4kI=
Content-Language: en-US
 by: Howerd Oakford - Thu, 11 Nov 2021 10:07 UTC

Hi Forthers,

Having announced an update to Cweed4, I just noticed that the Win32Forth
word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
means that it cannot handle strings longer than 255 bytes.

Does anyone have a (high level?) version of REPLACE that can handle
longer strings?

Thanks in advance,
Howerd

Re: Win32Forth REPLACE with a buffer > 255 characters

<smj2l9$1um2$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15225&group=comp.lang.forth#15225

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Thu, 11 Nov 2021 23:34:48 +1100
Organization: Aioe.org NNTP Server
Message-ID: <smj2l9$1um2$1@gioia.aioe.org>
References: <smiq1s$opj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="64194"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Thu, 11 Nov 2021 12:34 UTC

On 11/11/2021 21:07, Howerd Oakford wrote:
> Hi Forthers,
>
> Having announced an update to Cweed4, I just noticed that the Win32Forth
> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
> means that it cannot handle strings longer than 255 bytes.
>
> Does anyone have a (high level?) version of REPLACE that can handle
> longer strings?

REPLACE is a search/substitute routine? Perhaps this will do.

: +STRING ( a1 u1 a2 u2 -- a2 u3 )
2swap swap 2over + 2 pick move + ;

: counted DOES> count ;

create "FND counted ( -- a u ) 0 c, 63 allot
create "REP counted ( -- a u ) 0 c, 63 allot

: SUBST ( a u a2 -- a2 u2 )
0 2>r begin 2dup "fnd search while
2swap 2 pick - 2r> +string
"rep 2swap +string 2>r "fnd nip /string
repeat 2r> +string 2nip ;

\ for Cweed (untested)

create "OUT 1024 allot \ or existing buffer of your choice

: ADDR ( "name" -- addr )
' >body state @ if postpone literal then ; immediate

: replaceBuf ( $old $new -- )
addr "rep place addr "fnd place
get_TempBuffer0 "out subst copy_toTempBuffer0 ;

Re: Win32Forth REPLACE with a buffer > 255 characters

<smj9ul$1ijt$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15227&group=comp.lang.forth#15227

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Fri, 12 Nov 2021 01:39:17 +1100
Organization: Aioe.org NNTP Server
Message-ID: <smj9ul$1ijt$1@gioia.aioe.org>
References: <smiq1s$opj$1@dont-email.me> <smj2l9$1um2$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="51837"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Thu, 11 Nov 2021 14:39 UTC

On 11/11/2021 23:34, dxforth wrote:
> On 11/11/2021 21:07, Howerd Oakford wrote:
>> Hi Forthers,
>>
>> Having announced an update to Cweed4, I just noticed that the Win32Forth
>> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
>> means that it cannot handle strings longer than 255 bytes.
>>
>> Does anyone have a (high level?) version of REPLACE that can handle
>> longer strings?
>
> REPLACE is a search/substitute routine?

It appears your REPLACE stops after the first match. In that case
use SUBST-FIRST instead of SUBST .

: SUBST-FIRST ( a u a2 -- a2 u2 )
0 2>r 2dup "fnd search if
2swap 2 pick - 2r> +string
"rep 2swap +string 2>r "fnd nip /string
else 2drop then 2r> +string ;

Re: Win32Forth REPLACE with a buffer > 255 characters

<2bc4b98e-3c25-a90e-f1eb-65adc96f03dd@inventio.co.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15229&group=comp.lang.forth#15229

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: how...@inventio.co.uk (Howerd Oakford)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Thu, 11 Nov 2021 22:54:02 +0100
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <2bc4b98e-3c25-a90e-f1eb-65adc96f03dd@inventio.co.uk>
References: <smiq1s$opj$1@dont-email.me> <smj2l9$1um2$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="b03402addb2f60e6262264ffaafd50cb";
logging-data="4097"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Il3qo99g6OiKzdXdA5UKk"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Cancel-Lock: sha1:cks6/JZxWm+q49NkJr1nChhwAHY=
In-Reply-To: <smj2l9$1um2$1@gioia.aioe.org>
Content-Language: en-US
 by: Howerd Oakford - Thu, 11 Nov 2021 21:54 UTC

On 11/11/2021 13:34, dxforth wrote:
> On 11/11/2021 21:07, Howerd Oakford wrote:
>> Hi Forthers,
>>
>> Having announced an update to Cweed4, I just noticed that the Win32Forth
>> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
>> means that it cannot handle strings longer than 255 bytes.
>>
>> Does anyone have a (high level?) version of REPLACE that can handle
>> longer strings?
>
> REPLACE is a search/substitute routine?  Perhaps this will do.
>
> : +STRING ( a1 u1 a2 u2 -- a2 u3 )
>   2swap swap 2over + 2 pick move + ;
>
> : counted DOES> count ;
>
> create "FND counted ( -- a u )  0 c, 63 allot
> create "REP counted ( -- a u )  0 c, 63 allot
>
> : SUBST ( a u a2 -- a2 u2 )
>   0  2>r  begin  2dup "fnd search  while
>     2swap  2 pick -  2r> +string
>     "rep 2swap +string  2>r  "fnd nip /string
>   repeat  2r> +string  2nip ;
>
>
> \ for Cweed (untested)
>
> create "OUT  1024 allot  \ or existing buffer of your choice
>
> : ADDR ( "name" -- addr )
>   ' >body state @ if postpone literal then ; immediate
>
> : replaceBuf ( $old $new -- )
>   addr "rep place  addr "fnd place
>   get_TempBuffer0 "out subst  copy_toTempBuffer0 ;
>

Hi dxforth,

Thanks for the code. I fixed this later in the day, and the new version
is online. I didn't change the version number because I thought nobody
would have downloaded it yet, but you beat me to it ;-)

It turns out that I had already done 32 bit versions of COUNT , PLACE
and APPEND / +PLACE , shown below.

So now Cweed works with long lines when checking the Barr coding rules :-)

All we need to do now is to decide on the right names for these new
creations ;-)

Cheers,
Howerd


*****************************************************************************
\ Big 32 bit count versions of Place , Append and Count
\ The first 32 bit cell contains a 32 bit byte count
\
*****************************************************************************
$800 Buffer: BIG_STRBUF

: BigPlace ( a n a -- )
2dup ! cell+ swap cells move
;

: BigCount ( a -- a n )
dup @ swap cell+ swap
;

: BigAppend ( a n a -- )
2dup 2>r BigCount + swap move 2r> +!
;

: BigSUBST ( source len old len new len -- result len )
LOCALS| nl n pl p | 0 BIG_STRBUF !
BEGIN DUP 0> WHILE
2DUP p pl SEARCH WHILE ( s l m l)
ROT OVER - >R ROT R> BIG_STRBUF BigAppend
n nl BIG_STRBUF BigAppend
pl /STRING
REPEAT 2SWAP BIG_STRBUF BigAppend THEN
2DROP BIG_STRBUF BigCount ;

: BigREPLACE ( new l source l old l -- result l )
DUP>R 2OVER 2>R
SEARCH IF ( new l a n)
DUP 2R> ROT - BIG_STRBUF BigPlace
R> /STRING 2SWAP BIG_STRBUF BigAppend BIG_STRBUF BigAppend
ELSE ( new l a n)
2R> BIG_STRBUF BigPlace R>DROP 2DROP 2DROP
THEN BIG_STRBUF BigCount ;

: ttBR ( -- )
s" totally wonderful" s" hello replaceme world!!!" cr 2dup type
s" replaceme" BigREPLACE cr type
;

Re: Win32Forth REPLACE with a buffer > 255 characters

<smlbou$s0$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15233&group=comp.lang.forth#15233

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Fri, 12 Nov 2021 20:22:37 +1100
Organization: Aioe.org NNTP Server
Message-ID: <smlbou$s0$1@gioia.aioe.org>
References: <smiq1s$opj$1@dont-email.me> <smj2l9$1um2$1@gioia.aioe.org>
<2bc4b98e-3c25-a90e-f1eb-65adc96f03dd@inventio.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="896"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-GB
 by: dxforth - Fri, 12 Nov 2021 09:22 UTC

On 12/11/2021 08:54, Howerd Oakford wrote:
>
> : BigPlace ( a n a -- )
> 2dup ! cell+ swap cells move
> ;

Following Wil Baden's PLACE:

: BigPlace ( a n a -- )
2dup 2>r cell+ swap cells move 2r> ! ;
;

source and destination are permitted to overlap.

Re: Win32Forth REPLACE with a buffer > 255 characters

<3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15234&group=comp.lang.forth#15234

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:1a8d:: with SMTP id bl13mr8689328qkb.200.1636737666309;
Fri, 12 Nov 2021 09:21:06 -0800 (PST)
X-Received: by 2002:a05:620a:754:: with SMTP id i20mr13691123qki.312.1636737666026;
Fri, 12 Nov 2021 09:21:06 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 12 Nov 2021 09:21:05 -0800 (PST)
In-Reply-To: <smiq1s$opj$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=82.95.228.79; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 82.95.228.79
References: <smiq1s$opj$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Fri, 12 Nov 2021 17:21:06 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Hans Bezemer - Fri, 12 Nov 2021 17:21 UTC

On Thursday, November 11, 2021 at 11:07:58 AM UTC+1, Howerd wrote:
> Hi Forthers,
>
> Having announced an update to Cweed4, I just noticed that the Win32Forth
> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
> means that it cannot handle strings longer than 255 bytes.
>
> Does anyone have a (high level?) version of REPLACE that can handle
> longer strings?

An old library, haven't used it in ages. Your mileage may vary.

---8<--
\ Delete string a2/n2 from string a1/n1
\ Return the resulting string in a1/n3 and the remainder of the
\ line after the delete in string a2/n4
\ If the deletion was made, f is 1 otherwise 0

: delete ( a1 n1 a2 n2 -- a1 n3 a2 n4 f)
2>r 2dup 2r> dup >r search
dup r> swap >r >r ( a1 n1 a2 n2 f)
if ( a1 n1 a2 n2)
2swap r@ - 2swap r@ - ( a1 n3 a2 n4)
2dup over r@ chars + ( a1 n3 a2 n4 a3)
-rot cmove ( a1 n3 a2 n4)
then
r> drop r>
;

\ Delete all occurences of string a2/n2 in string a1/n1
\ Return the resulting string in a1/n3

: deleteall ( a1 n1 a2 n2 -- a1 n3)
2>r swap dup rot ( a1 a1 n1)
begin ( a1 a1 n1)
2r> 2dup 2>r delete ( a1 a1 n3 a2 n4 f)
while ( a1 a1 n3 a2 n4)
2swap 2drop ( a1 a2 n4)
repeat ( a1 a2 n4)
2drop chars + over - ( a1 n5)
2r> 2drop ( a1 n5)
;

\ Spread string a1/n1 at position n2 by n3 characters
\ Return the resulting string in a1/n4 and the opened up
\ space in string a2 n3

: spread ( a1 n1 n2 n3 -- a1 n4 a2 n3)
rot >r >r ( a1 n2)
over over chars + swap ( a1 a2 n2)
over dup r@ + rot ( a1 a2 a2 a3 n2)
r> swap r@ swap - swap >r ( a1 a2 a2 a3 n1-n2)
cmove r@ rot r> r> + ( a2 n3 a1 n4)
2swap ( a1 n4 a2 n3)
;

\ Insert string a2/n2 into string a1/n1 at position n3
\ Return the resulting string in a1/n3 and the remainder of
\ the line after the insertion in a3/n4

: insert ( a1 n1 a2 n2 n3 -- a1 n3 a3 n4)
-rot 2dup 2>r ( a1 n1 n3 a2 n2)
nip spread ( a1 n3 a3 n2)
over 2r> ( a1 n3 a3 n2 a3 a2 n2)
rot swap cmove chars + ( a1 n3 a4)
>r 2dup chars + r@ - ( a1 n3 n4)
r> swap
;

\ Replace string a2/n2 in string a1/n1 by string a3/n3
\ Return the resulting string in a1/n4 and the remainder of the
\ line after the delete in string a4/n5
\ If the replacement was made, f is 1 otherwise 0

: replace ( a1 n1 a2 n2 a3 n3 -- a1 n4 a4 n5 f)
2>r delete dup 2r> rot >r 2>r
if
nip over swap - 2r> rot insert
else
2r> 2drop
then
r>
;

\ Replace all occurences of string a2/n2 in string a1/n1 by string a3/n3
\ Return the resulting string in a1/n4

: replaceall ( a1 n1 a2 n2 a3 n3 -- a1 n4)
2>r 2>r swap dup rot
begin
2r> 2dup 2r> 2dup 2>r 2swap 2>r replace
while
2swap 2drop
repeat
2drop chars + over -
2r> 2r> 2drop 2drop
;
---8<---

Hans Bezemer

Re: Win32Forth REPLACE with a buffer > 255 characters

<640b7a82-de1d-493c-b376-7b88691a92bdn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15235&group=comp.lang.forth#15235

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a37:ae84:: with SMTP id x126mr14511388qke.334.1636746540842;
Fri, 12 Nov 2021 11:49:00 -0800 (PST)
X-Received: by 2002:a05:622a:248:: with SMTP id c8mr18812018qtx.248.1636746540637;
Fri, 12 Nov 2021 11:49:00 -0800 (PST)
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Fri, 12 Nov 2021 11:49:00 -0800 (PST)
In-Reply-To: <2bc4b98e-3c25-a90e-f1eb-65adc96f03dd@inventio.co.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23c5:6f05:3a01:acda:6569:85ca:699e;
posting-account=9A5f7goAAAD_QfJPZnlK3Xq_UhzYjdP-
NNTP-Posting-Host: 2a00:23c5:6f05:3a01:acda:6569:85ca:699e
References: <smiq1s$opj$1@dont-email.me> <smj2l9$1um2$1@gioia.aioe.org> <2bc4b98e-3c25-a90e-f1eb-65adc96f03dd@inventio.co.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <640b7a82-de1d-493c-b376-7b88691a92bdn@googlegroups.com>
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
From: november...@gmail.com (NN)
Injection-Date: Fri, 12 Nov 2021 19:49:00 +0000
Content-Type: text/plain; charset="UTF-8"
 by: NN - Fri, 12 Nov 2021 19:49 UTC

On Thursday, 11 November 2021 at 21:54:06 UTC, Howerd wrote:
> On 11/11/2021 13:34, dxforth wrote:
> > On 11/11/2021 21:07, Howerd Oakford wrote:
> >> Hi Forthers,
> >>
> >> Having announced an update to Cweed4, I just noticed that the Win32Forth
> >> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
> >> means that it cannot handle strings longer than 255 bytes.
> >>
> >> Does anyone have a (high level?) version of REPLACE that can handle
> >> longer strings?
> >
> > REPLACE is a search/substitute routine? Perhaps this will do.
> >
> > : +STRING ( a1 u1 a2 u2 -- a2 u3 )
> > 2swap swap 2over + 2 pick move + ;
> >
> > : counted DOES> count ;
> >
> > create "FND counted ( -- a u ) 0 c, 63 allot
> > create "REP counted ( -- a u ) 0 c, 63 allot
> >
> > : SUBST ( a u a2 -- a2 u2 )
> > 0 2>r begin 2dup "fnd search while
> > 2swap 2 pick - 2r> +string
> > "rep 2swap +string 2>r "fnd nip /string
> > repeat 2r> +string 2nip ;
> >
> >
> > \ for Cweed (untested)
> >
> > create "OUT 1024 allot \ or existing buffer of your choice
> >
> > : ADDR ( "name" -- addr )
> > ' >body state @ if postpone literal then ; immediate
> >
> > : replaceBuf ( $old $new -- )
> > addr "rep place addr "fnd place
> > get_TempBuffer0 "out subst copy_toTempBuffer0 ;
> >
> Hi dxforth,
>
> Thanks for the code. I fixed this later in the day, and the new version
> is online. I didn't change the version number because I thought nobody
> would have downloaded it yet, but you beat me to it ;-)
>
>
> It turns out that I had already done 32 bit versions of COUNT , PLACE
> and APPEND / +PLACE , shown below.
>
> So now Cweed works with long lines when checking the Barr coding rules :-)
>
> All we need to do now is to decide on the right names for these new
> creations ;-)
>
> Cheers,
> Howerd
>
>
> *****************************************************************************
> \ Big 32 bit count versions of Place , Append and Count
> \ The first 32 bit cell contains a 32 bit byte count
> \
> *****************************************************************************
> $800 Buffer: BIG_STRBUF
>
> : BigPlace ( a n a -- )
> 2dup ! cell+ swap cells move
> ;
>
> : BigCount ( a -- a n )
> dup @ swap cell+ swap
> ;
>
> : BigAppend ( a n a -- )
> 2dup 2>r BigCount + swap move 2r> +!
> ;
>
> : BigSUBST ( source len old len new len -- result len )
> LOCALS| nl n pl p | 0 BIG_STRBUF !
> BEGIN DUP 0> WHILE
> 2DUP p pl SEARCH WHILE ( s l m l)
> ROT OVER - >R ROT R> BIG_STRBUF BigAppend
> n nl BIG_STRBUF BigAppend
> pl /STRING
> REPEAT 2SWAP BIG_STRBUF BigAppend THEN
> 2DROP BIG_STRBUF BigCount ;
>
>
> : BigREPLACE ( new l source l old l -- result l )
> DUP>R 2OVER 2>R
> SEARCH IF ( new l a n)
> DUP 2R> ROT - BIG_STRBUF BigPlace
> R> /STRING 2SWAP BIG_STRBUF BigAppend BIG_STRBUF BigAppend
> ELSE ( new l a n)
> 2R> BIG_STRBUF BigPlace R>DROP 2DROP 2DROP
> THEN BIG_STRBUF BigCount ;
>
> : ttBR ( -- )
> s" totally wonderful" s" hello replaceme world!!!" cr 2dup type
> s" replaceme" BigREPLACE cr type
> ;

I havent used win32forth in a while , but place, count and append appear very similar to lcount, lplace and l+place.

Re: Win32Forth REPLACE with a buffer > 255 characters

<smmvnk$1b7u$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15237&group=comp.lang.forth#15237

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Sat, 13 Nov 2021 11:09:24 +1100
Organization: Aioe.org NNTP Server
Message-ID: <smmvnk$1b7u$1@gioia.aioe.org>
References: <smiq1s$opj$1@dont-email.me>
<3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="44286"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Sat, 13 Nov 2021 00:09 UTC

On 13/11/2021 04:21, Hans Bezemer wrote:
> On Thursday, November 11, 2021 at 11:07:58 AM UTC+1, Howerd wrote:
>> Hi Forthers,
>>
>> Having announced an update to Cweed4, I just noticed that the Win32Forth
>> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
>> means that it cannot handle strings longer than 255 bytes.
>>
>> Does anyone have a (high level?) version of REPLACE that can handle
>> longer strings?
>
> An old library, haven't used it in ages. Your mileage may vary.
>

Some nice ideas in there I hadn't considered.

Only had use for such a thing recently (replacing .html with .htm
in some 800 files - not something I wanted to do manually :)

Re: Win32Forth REPLACE with a buffer > 255 characters

<smn022$1eh8$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15238&group=comp.lang.forth#15238

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Sat, 13 Nov 2021 11:14:58 +1100
Organization: Aioe.org NNTP Server
Message-ID: <smn022$1eh8$1@gioia.aioe.org>
References: <smiq1s$opj$1@dont-email.me> <smj2l9$1um2$1@gioia.aioe.org>
<2bc4b98e-3c25-a90e-f1eb-65adc96f03dd@inventio.co.uk>
<640b7a82-de1d-493c-b376-7b88691a92bdn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="47656"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Sat, 13 Nov 2021 00:14 UTC

On 13/11/2021 06:49, NN wrote:
>
> I havent used win32forth in a while , but place, count and append appear very similar to lcount, lplace and l+place.
>

Indeed it does. OTOH they're limited to 1024 chars for Windows-related reasons.
But hey, 1024 should be enough for anyone :)

Re: Win32Forth REPLACE with a buffer > 255 characters

<so2fni$hf4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15375&group=comp.lang.forth#15375

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: do-not-...@swldwa.uk (Gerry Jackson)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Mon, 29 Nov 2021 12:06:11 +0000
Organization: A noiseless patient Spider
Lines: 150
Message-ID: <so2fni$hf4$1@dont-email.me>
References: <smiq1s$opj$1@dont-email.me>
<3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 29 Nov 2021 12:06:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="33d1a91dd34c3645577e1c8e56152630";
logging-data="17892"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KaIP5RC36OA13HJJmEBo8ZxQVveoH45A="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:PkQP8XTwo/beX6Yw+GMN+luDSl0=
In-Reply-To: <3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
 by: Gerry Jackson - Mon, 29 Nov 2021 12:06 UTC

On 12/11/2021 17:21, Hans Bezemer wrote:
> On Thursday, November 11, 2021 at 11:07:58 AM UTC+1, Howerd wrote:
>> Hi Forthers,
>>
>> Having announced an update to Cweed4, I just noticed that the Win32Forth
>> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
>> means that it cannot handle strings longer than 255 bytes.
>>
>> Does anyone have a (high level?) version of REPLACE that can handle
>> longer strings?
>
> An old library, haven't used it in ages. Your mileage may vary.

It certainly does

>
> ---8<--
> \ Delete string a2/n2 from string a1/n1
> \ Return the resulting string in a1/n3 and the remainder of the
> \ line after the delete in string a2/n4
> \ If the deletion was made, f is 1 otherwise 0
>
> : delete ( a1 n1 a2 n2 -- a1 n3 a2 n4 f)
> 2>r 2dup 2r> dup >r search
> dup r> swap >r >r ( a1 n1 a2 n2 f)
> if ( a1 n1 a2 n2)
> 2swap r@ - 2swap r@ - ( a1 n3 a2 n4)
> 2dup over r@ chars + ( a1 n3 a2 n4 a3)
> -rot cmove ( a1 n3 a2 n4)
> then
> r> drop r>
> ;
>
> \ Delete all occurences of string a2/n2 in string a1/n1
> \ Return the resulting string in a1/n3
>
> : deleteall ( a1 n1 a2 n2 -- a1 n3)
> 2>r swap dup rot ( a1 a1 n1)
> begin ( a1 a1 n1)
> 2r> 2dup 2>r delete ( a1 a1 n3 a2 n4 f)
> while ( a1 a1 n3 a2 n4)
> 2swap 2drop ( a1 a2 n4)
> repeat ( a1 a2 n4)
> 2drop chars + over - ( a1 n5)
> 2r> 2drop ( a1 n5)
> ;
>
> \ Spread string a1/n1 at position n2 by n3 characters
> \ Return the resulting string in a1/n4 and the opened up
> \ space in string a2 n3
>
> : spread ( a1 n1 n2 n3 -- a1 n4 a2 n3)
> rot >r >r ( a1 n2)
> over over chars + swap ( a1 a2 n2)
> over dup r@ + rot ( a1 a2 a2 a3 n2)
> r> swap r@ swap - swap >r ( a1 a2 a2 a3 n1-n2)
> cmove r@ rot r> r> + ( a2 n3 a1 n4)
> 2swap ( a1 n4 a2 n3)
> ;
>
> \ Insert string a2/n2 into string a1/n1 at position n3
> \ Return the resulting string in a1/n3 and the remainder of
> \ the line after the insertion in a3/n4
>
> : insert ( a1 n1 a2 n2 n3 -- a1 n3 a3 n4)
> -rot 2dup 2>r ( a1 n1 n3 a2 n2)
> nip spread ( a1 n3 a3 n2)
> over 2r> ( a1 n3 a3 n2 a3 a2 n2)
> rot swap cmove chars + ( a1 n3 a4)
> >r 2dup chars + r@ - ( a1 n3 n4)
> r> swap
> ;
>
> \ Replace string a2/n2 in string a1/n1 by string a3/n3
> \ Return the resulting string in a1/n4 and the remainder of the
> \ line after the delete in string a4/n5
> \ If the replacement was made, f is 1 otherwise 0
>
> : replace ( a1 n1 a2 n2 a3 n3 -- a1 n4 a4 n5 f)
> 2>r delete dup 2r> rot >r 2>r
> if
> nip over swap - 2r> rot insert
> else
> 2r> 2drop
> then
> r>
> ;
>
> \ Replace all occurences of string a2/n2 in string a1/n1 by string a3/n3
> \ Return the resulting string in a1/n4
>
> : replaceall ( a1 n1 a2 n2 a3 n3 -- a1 n4)
> 2>r 2>r swap dup rot
> begin
> 2r> 2dup 2r> 2dup 2>r 2swap 2>r replace
> while
> 2swap 2drop
> repeat
> 2drop chars + over -
> 2r> 2r> 2drop 2drop
> ;
> ---8<---

Perhaps this works in 4th but, unless I'm misunderstanding something, it
doesn't work in standard Forth despite using standard words, for example
a crude test using GForth:

\ Test ok
ok
create buf 1000 allot ok
0 value len ok
: src s" aaa*****bbbb*****ccccc*****dd" ; ok
: targ s" *****" ; ok
: >buf ( ca u -- ) dup to len buf swap cmove ; ok
: buf@ buf len ; ok
: .buf ( -- ) buf@ cr type ; ok
ok
src >buf ok
buf@ 2dup cr type targ s" ------" replace cr . cr type cr type cr .s
aaa*****bbbb*****ccccc*****dd
-1
bbbb**bbbb**bbbb**bbb
aaa------bbbb**bbbb**bbbb**bbb
<0> ok
ok
src >buf ok
buf@ 2dup cr type targ s" ------" replaceall cr type cr .s
aaa*****bbbb*****ccccc*****dd
aaa------bbbb**bbbb**bbbb**bbb
<0> ok
ok
src >buf ok
buf@ 2dup cr type targ s" --" replace cr . cr type cr type cr .s
aaa*****bbbb*****ccccc*****dd
-1
bbbbbbbbbbbbbbbbbbbbb
aaa--bbbbbbbbbbbbbbbbbbbbb
<0> ok
ok
ok
src >buf ok
buf@ 2dup cr type targ s" --" replaceall cr type cr .s
aaa*****bbbb*****ccccc*****dd
aaa--bbbbbbbbbbbbbbbbbbbbb
<0> ok

Other Forth systems give the same result.

--
Gerry

Re: Win32Forth REPLACE with a buffer > 255 characters

<1380f3b6-3890-44f6-b8c1-abb7aee983e1n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15385&group=comp.lang.forth#15385

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:1a0b:: with SMTP id bk11mr39158464qkb.513.1638204283169;
Mon, 29 Nov 2021 08:44:43 -0800 (PST)
X-Received: by 2002:ad4:5945:: with SMTP id eo5mr31819178qvb.130.1638204283020;
Mon, 29 Nov 2021 08:44:43 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 29 Nov 2021 08:44:42 -0800 (PST)
In-Reply-To: <smiq1s$opj$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=24.138.223.107; posting-account=I-_H_woAAAA9zzro6crtEpUAyIvzd19b
NNTP-Posting-Host: 24.138.223.107
References: <smiq1s$opj$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1380f3b6-3890-44f6-b8c1-abb7aee983e1n@googlegroups.com>
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
From: gnuarm.d...@gmail.com (Rick C)
Injection-Date: Mon, 29 Nov 2021 16:44:43 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 17
 by: Rick C - Mon, 29 Nov 2021 16:44 UTC

On Thursday, November 11, 2021 at 6:07:58 AM UTC-4, Howerd wrote:
> Hi Forthers,
>
> Having announced an update to Cweed4, I just noticed that the Win32Forth
> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
> means that it cannot handle strings longer than 255 bytes.
>
> Does anyone have a (high level?) version of REPLACE that can handle
> longer strings?

Just curious, which version of Win32Forth are you using?

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

Re: Win32Forth REPLACE with a buffer > 255 characters

<so3u8o$13jg$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15388&group=comp.lang.forth#15388

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Tue, 30 Nov 2021 12:20:22 +1100
Organization: Aioe.org NNTP Server
Message-ID: <so3u8o$13jg$1@gioia.aioe.org>
References: <smiq1s$opj$1@dont-email.me>
<1380f3b6-3890-44f6-b8c1-abb7aee983e1n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="36464"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Tue, 30 Nov 2021 01:20 UTC

On 30/11/2021 03:44, Rick C wrote:
> On Thursday, November 11, 2021 at 6:07:58 AM UTC-4, Howerd wrote:
>> Hi Forthers,
>>
>> Having announced an update to Cweed4, I just noticed that the Win32Forth
>> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
>> means that it cannot handle strings longer than 255 bytes.
>>
>> Does anyone have a (high level?) version of REPLACE that can handle
>> longer strings?
>
> Just curious, which version of Win32Forth are you using?

http://www.inventio.co.uk/LegacyIndex.htm

Re: Win32Forth REPLACE with a buffer > 255 characters

<61a58bae$0$699$14726298@news.sunsite.dk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15391&group=comp.lang.forth#15391

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Date: Mon, 29 Nov 2021 21:25:47 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Content-Language: en-US
Newsgroups: comp.lang.forth
References: <smiq1s$opj$1@dont-email.me>
<3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
<so2fni$hf4$1@dont-email.me>
From: dhoffman...@gmail.com (Doug Hoffman)
In-Reply-To: <so2fni$hf4$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 15
Message-ID: <61a58bae$0$699$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: f50d8b49.news.sunsite.dk
X-Trace: 1638239151 news.sunsite.dk 699 glidedog@gmail.com/68.55.82.126:50779
X-Complaints-To: staff@sunsite.dk
 by: Doug Hoffman - Tue, 30 Nov 2021 02:25 UTC

On 11/29/21 7:06 AM, Gerry Jackson wrote:

> Perhaps this works in 4th but, unless I'm misunderstanding something, it
> doesn't work in standard Forth despite using standard words, for example
> ...

Yeah. I got similar errors on the tests I tried. Maybe I'm using the
words incorrectly. Not sure.

The same tests work fine with my object-based library replace routines.
Downside is having to load my library with its oo support code. Not an
issue for me because I always have it loaded.

-Doug

Re: Win32Forth REPLACE with a buffer > 255 characters

<a5c5deac-3490-4b64-a498-bdf666e636a2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15392&group=comp.lang.forth#15392

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a0c:c246:: with SMTP id w6mr34890970qvh.130.1638241084380;
Mon, 29 Nov 2021 18:58:04 -0800 (PST)
X-Received: by 2002:a05:620a:4691:: with SMTP id bq17mr43828760qkb.510.1638241084245;
Mon, 29 Nov 2021 18:58:04 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 29 Nov 2021 18:58:04 -0800 (PST)
In-Reply-To: <so3u8o$13jg$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=24.138.223.107; posting-account=I-_H_woAAAA9zzro6crtEpUAyIvzd19b
NNTP-Posting-Host: 24.138.223.107
References: <smiq1s$opj$1@dont-email.me> <1380f3b6-3890-44f6-b8c1-abb7aee983e1n@googlegroups.com>
<so3u8o$13jg$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a5c5deac-3490-4b64-a498-bdf666e636a2n@googlegroups.com>
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
From: gnuarm.d...@gmail.com (Rick C)
Injection-Date: Tue, 30 Nov 2021 02:58:04 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 24
 by: Rick C - Tue, 30 Nov 2021 02:58 UTC

On Monday, November 29, 2021 at 9:20:26 PM UTC-4, dxforth wrote:
> On 30/11/2021 03:44, Rick C wrote:
> > On Thursday, November 11, 2021 at 6:07:58 AM UTC-4, Howerd wrote:
> >> Hi Forthers,
> >>
> >> Having announced an update to Cweed4, I just noticed that the Win32Forth
> >> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
> >> means that it cannot handle strings longer than 255 bytes.
> >>
> >> Does anyone have a (high level?) version of REPLACE that can handle
> >> longer strings?
> >
> > Just curious, which version of Win32Forth are you using?
> http://www.inventio.co.uk/LegacyIndex.htm

So that would be Win32Forth V6.05H?

Is that because of issues with AVS from later editions or just because it works and no reason to change?

--

Rick C.

+ Get 1,000 miles of free Supercharging
+ Tesla referral code - https://ts.la/richard11209

Re: Win32Forth REPLACE with a buffer > 255 characters

<3620d34d-5368-4762-94d5-d8a7f0ca5327n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15393&group=comp.lang.forth#15393

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:5193:: with SMTP id kl19mr34690806qvb.77.1638241322968;
Mon, 29 Nov 2021 19:02:02 -0800 (PST)
X-Received: by 2002:a37:747:: with SMTP id 68mr43349638qkh.227.1638241322825;
Mon, 29 Nov 2021 19:02:02 -0800 (PST)
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 29 Nov 2021 19:02:02 -0800 (PST)
In-Reply-To: <a5c5deac-3490-4b64-a498-bdf666e636a2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=24.138.223.107; posting-account=I-_H_woAAAA9zzro6crtEpUAyIvzd19b
NNTP-Posting-Host: 24.138.223.107
References: <smiq1s$opj$1@dont-email.me> <1380f3b6-3890-44f6-b8c1-abb7aee983e1n@googlegroups.com>
<so3u8o$13jg$1@gioia.aioe.org> <a5c5deac-3490-4b64-a498-bdf666e636a2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3620d34d-5368-4762-94d5-d8a7f0ca5327n@googlegroups.com>
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
From: gnuarm.d...@gmail.com (Rick C)
Injection-Date: Tue, 30 Nov 2021 03:02:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 34
 by: Rick C - Tue, 30 Nov 2021 03:02 UTC

On Monday, November 29, 2021 at 10:58:05 PM UTC-4, Rick C wrote:
> On Monday, November 29, 2021 at 9:20:26 PM UTC-4, dxforth wrote:
> > On 30/11/2021 03:44, Rick C wrote:
> > > On Thursday, November 11, 2021 at 6:07:58 AM UTC-4, Howerd wrote:
> > >> Hi Forthers,
> > >>
> > >> Having announced an update to Cweed4, I just noticed that the Win32Forth
> > >> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
> > >> means that it cannot handle strings longer than 255 bytes.
> > >>
> > >> Does anyone have a (high level?) version of REPLACE that can handle
> > >> longer strings?
> > >
> > > Just curious, which version of Win32Forth are you using?
> > http://www.inventio.co.uk/LegacyIndex.htm
> So that would be Win32Forth V6.05H?
>
> Is that because of issues with AVS from later editions or just because it works and no reason to change?

BTW, the green font on that page is completely illegible to me. It vibrates into the background making the font illegible. The cyan font is not very clear either. Why use such difficult to see colors? I thought the dark gray on light gray fad was a PITA, but this is even worse. At least I can use Reader view in Firefox to read it losing all formatting.

--

Rick C.

-- Get 1,000 miles of free Supercharging
-- Tesla referral code - https://ts.la/richard11209

Re: Win32Forth REPLACE with a buffer > 255 characters

<so4cqm$1onb$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15394&group=comp.lang.forth#15394

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Tue, 30 Nov 2021 16:28:53 +1100
Organization: Aioe.org NNTP Server
Message-ID: <so4cqm$1onb$1@gioia.aioe.org>
References: <smiq1s$opj$1@dont-email.me>
<1380f3b6-3890-44f6-b8c1-abb7aee983e1n@googlegroups.com>
<so3u8o$13jg$1@gioia.aioe.org>
<a5c5deac-3490-4b64-a498-bdf666e636a2n@googlegroups.com>
<3620d34d-5368-4762-94d5-d8a7f0ca5327n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="58091"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-GB
 by: dxforth - Tue, 30 Nov 2021 05:28 UTC

On 30/11/2021 14:02, Rick C wrote:
> ...
> BTW, the green font on that page is completely illegible to me. It vibrates into the
> background making the font illegible. The cyan font is not very clear either. Why use such
> difficult to see colors? I thought the dark gray on light gray fad was a PITA, but this is
> even worse. At least I can use Reader view in Firefox to read it losing all formatting.

Perhaps colorForth wasn't such a good idea after all :)

Re: Win32Forth REPLACE with a buffer > 255 characters

<so52he$1379$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15397&group=comp.lang.forth#15397

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Tue, 30 Nov 2021 22:39:25 +1100
Organization: Aioe.org NNTP Server
Message-ID: <so52he$1379$1@gioia.aioe.org>
References: <smiq1s$opj$1@dont-email.me>
<3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
<so2fni$hf4$1@dont-email.me> <61a58bae$0$699$14726298@news.sunsite.dk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="36073"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-GB
 by: dxforth - Tue, 30 Nov 2021 11:39 UTC

On 30/11/2021 13:25, Doug Hoffman wrote:
> On 11/29/21 7:06 AM, Gerry Jackson wrote:
>
>> Perhaps this works in 4th but, unless I'm misunderstanding something, it
>> doesn't work in standard Forth despite using standard words, for example
>> ...
>
> Yeah. I got similar errors on the tests I tried. Maybe I'm using the
> words incorrectly. Not sure.
>
> The same tests work fine with my object-based library replace routines.
> Downside is having to load my library with its oo support code. Not an
> issue for me because I always have it loaded.

Got it going by replacing CMOVE with CMOVE> in SPREAD. Whether it's a
complete fix I don't know.

Re: Win32Forth REPLACE with a buffer > 255 characters

<61a6294c$0$695$14726298@news.sunsite.dk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15400&group=comp.lang.forth#15400

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Date: Tue, 30 Nov 2021 08:38:20 -0500
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Content-Language: en-US
Newsgroups: comp.lang.forth
References: <smiq1s$opj$1@dont-email.me>
<3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
<so2fni$hf4$1@dont-email.me> <61a58bae$0$699$14726298@news.sunsite.dk>
<so52he$1379$1@gioia.aioe.org>
From: glide...@gmail.com (Doug Hoffman)
In-Reply-To: <so52he$1379$1@gioia.aioe.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 8
Message-ID: <61a6294c$0$695$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: 269c432b.news.sunsite.dk
X-Trace: 1638279500 news.sunsite.dk 695 glidedog@gmail.com/68.55.82.126:58796
X-Complaints-To: staff@sunsite.dk
 by: Doug Hoffman - Tue, 30 Nov 2021 13:38 UTC

On 11/30/21 6:39 AM, dxforth wrote:
> Got it going by replacing CMOVE with CMOVE> in SPREAD.  Whether it's a
> complete fix I don't know.

It works fine with your fix on my large torture test ( 10 times the
size of the KJB from the Hoyt test). Nice catch!

-Doug

Re: Win32Forth REPLACE with a buffer > 255 characters

<415972e8-90df-430e-bc0d-bc9b77fb5959n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15408&group=comp.lang.forth#15408

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5fc4:: with SMTP id k4mr5863456qta.472.1638357454761;
Wed, 01 Dec 2021 03:17:34 -0800 (PST)
X-Received: by 2002:ac8:5c03:: with SMTP id i3mr6315853qti.107.1638357454607;
Wed, 01 Dec 2021 03:17:34 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 1 Dec 2021 03:17:34 -0800 (PST)
In-Reply-To: <so52he$1379$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=82.95.228.79; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 82.95.228.79
References: <smiq1s$opj$1@dont-email.me> <3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
<so2fni$hf4$1@dont-email.me> <61a58bae$0$699$14726298@news.sunsite.dk> <so52he$1379$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <415972e8-90df-430e-bc0d-bc9b77fb5959n@googlegroups.com>
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Wed, 01 Dec 2021 11:17:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Hans Bezemer - Wed, 1 Dec 2021 11:17 UTC

On Tuesday, November 30, 2021 at 12:39:29 PM UTC+1, dxforth wrote:
> Got it going by replacing CMOVE with CMOVE> in SPREAD. Whether it's a
> complete fix I don't know.

In 4tH there is no bug, because ALL "MOVE" variations (CMOVE, CMOVE>, MOVE - and their cell equivalent SMOVE) are INTELLIGENT. They do not only check whether a "move" goes outside the sandbox, they also evaluate the direction and adjust accordingly. So, yes - a fix at "SPREAD" makes sense - and given it's the only word that moves in that direction, it might be the fix one needed.

I've applied it in my source as well, so others won't fall in the same trap when they rip one of my libs ;-)
BTW, it's a smart move to PLACE the source string in an appropriately sized buffer. There is a lot of movement going on - especially when expanding by sizeof("replacement") > sizeof("original") of course.

I'm sorry for any inconvenience caused, but I warned you this was an old vanilla lib from 4tH. Thanks for figuring this out!

Hans Bezemer

Re: Win32Forth REPLACE with a buffer > 255 characters

<22a6951d-8f83-40b3-8e1b-a034e678e535n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15410&group=comp.lang.forth#15410

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:7e8d:: with SMTP id w13mr6206586qtj.527.1638361081024;
Wed, 01 Dec 2021 04:18:01 -0800 (PST)
X-Received: by 2002:a05:6214:f6c:: with SMTP id iy12mr5979959qvb.29.1638361080887;
Wed, 01 Dec 2021 04:18:00 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Wed, 1 Dec 2021 04:18:00 -0800 (PST)
In-Reply-To: <415972e8-90df-430e-bc0d-bc9b77fb5959n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=82.95.228.79; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 82.95.228.79
References: <smiq1s$opj$1@dont-email.me> <3e4fcfa4-a4ef-47cf-98ca-f02f5a9ce27an@googlegroups.com>
<so2fni$hf4$1@dont-email.me> <61a58bae$0$699$14726298@news.sunsite.dk>
<so52he$1379$1@gioia.aioe.org> <415972e8-90df-430e-bc0d-bc9b77fb5959n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <22a6951d-8f83-40b3-8e1b-a034e678e535n@googlegroups.com>
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Wed, 01 Dec 2021 12:18:01 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Hans Bezemer - Wed, 1 Dec 2021 12:18 UTC

On Wednesday, December 1, 2021 at 12:17:35 PM UTC+1, Hans Bezemer wrote:

> I've applied it in my source as well, so others won't fall in the same trap when they rip one of my libs ;-)
https://sourceforge.net/p/forth-4th/code/1370/

Re: Win32Forth REPLACE with a buffer > 255 characters

<sp0f14$ml5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15491&group=comp.lang.forth#15491

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: do-not-...@swldwa.uk (Gerry Jackson)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Fri, 10 Dec 2021 20:58:13 +0000
Organization: A noiseless patient Spider
Lines: 93
Message-ID: <sp0f14$ml5$1@dont-email.me>
References: <smiq1s$opj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 10 Dec 2021 20:58:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="280c49b391be6ba328b11f5f95de3fb5";
logging-data="23205"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+G8cyET4Pj0yCECaHS/SHqN4Yj6O/35Ws="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:Aabud3radkpKxJNygto828S3rvo=
In-Reply-To: <smiq1s$opj$1@dont-email.me>
 by: Gerry Jackson - Fri, 10 Dec 2021 20:58 UTC

On 11/11/2021 10:07, Howerd Oakford wrote:
> Hi Forthers,
>
> Having announced an update to Cweed4, I just noticed that the Win32Forth
> word REPLACE uses a 256 byte string buffer and COUNT and APPEND. This
> means that it cannot handle strings longer than 255 bytes.
>
> Does anyone have a (high level?) version of REPLACE that can handle
> longer strings?
>

This implementation of REPLACE and REPLACE-ALL was written to test the
functionality of a simple buffer similar to the standard pictured output
buffer but without the defects.

The method is straightforward. SPLIT-ALL recursively splits the source
string into substrings of the text between replacements. When the
recursion unwinds the substrings are copied to a buffer and their
buffered (ca u)'s left on the data stack.

Then SAVE-RESULT simply repeatedly copies a substring and replacement
string to create the final result

REPLACE calls a REPLACE-ALL factor for a single replacement. REPLACE-ALL
should be more efficient than other solutions e.g. those that repeatedly
delete/spread/insert the replacement as it does less string copying.

\ --------------------------
\ download buffer.fth from:
\ https://github.com/gerryjackson/Forth-sprintf/blob/master/buffer.fth
\ Note: <~ opens a new buffer and clears it
\ ~holds ( ca u -- ) appends the string to the current buffer
\ ~><~ ( -- ca u ) returns the buffer contents, closes it and
\ opens a new one

include buffer.fth

here 500 dup allot create~buffer rep-buf

defer search? \ Will be set to simulate a failed SEARCH after the first
\ search when REPLACE is used otherwise SEARCH

: split-all ( ca1 u1 ca2 u2 -- ~cai' ~ui' ... ~ca1 ~u1 )
2>r over swap 2r@ search? ( -- ca1 ca4 ux f ) ( R: -- ca2 u2 )
if
2dup 2>r drop over - 2r> ( -- ca1 u1' ca4 ux )
r@ /string ( -- ca1 u1' ca4' ux' )
2r> 2rot 2>r ( -- ca4' ux' ca2 u2 ) ( R: -- ca1 u1' )
recurse ( -- ) ( R: ca1 u1' )
2r> ~holds ~><~ ( -- ~ca1 ~u1 ) \ (~ca ~u) is ~buffer (ca u)
else ( -- cai' cai' ui' ) ( R: ca2 u2 )
2r> 2drop nip ( -- cai' ui' ) ( R: -- )
~holds ~><~ ( -- ~cai ~ui )
then
;

: source-concat ( ca1 u1 ca2 -- ca2' ) \ where ca2' = ca2 + u1
swap 2dup + >r cmove r>
;

: save-result ( 0 0 ~cai ~ui ... ~ca1 ~u1 ca1 ca3 u3 -- ad )
2>r + >r drop ( -- 0 0 ~cai ~ui ... ~ca2 ~u2) ( R: -- ca3 u3 ad1)
begin
2dup or
while
r> 2r@ rot source-concat ( -- 0 0 ~cai ~ui ... ~ca2 ~u2 ad2)
source-concat >r ( -- 0 0 ~cai ~ui ... ~ca3 ~u3 )
repeat ( 0 0 ) ( R: ca3 u3 ad )
2drop r> 2r> 2drop ( -- ad ) ( R: -- )
;

\ Replace 0 or more occurrences of (ca2 u2) with (ca3 u3) in
\ string (ca1 u1), returning the results in (ca1 u4)
: replace* ( ca1 u1 ca2 u2 ca3 u3 -- ca1 u4 )
2>r 3 pick >r 2>r ( -- ca1 u1 ) ( R: -- ca3 u3 ca1 ca2 u2 )
over swap 0 0 2swap 2r> ( -- ca1 0 0 ca1 u1 ca2 u2 )
rep-buf <~ split-all ( -- ca1 0 0 ~cai ~ui ... ~ca1 ~u1 )
r> 2r> save-result ( -- ca1 caj )
over - ( -- ca1 u4 )
;

: replace ( ca1 u1 ca2 u2 ca3 u3 -- ca1 u )
[: search [: 2drop 0 ;] is search? ;] is search? replace*
;

: replace-all ( ca1 u1 ca2 u2 ca3 u3 -- ca1 u )
2 pick 0= abort" Error: String to be replaced cannot be empty"
['] search is search? replace*
;

--
Gerry

Re: Win32Forth REPLACE with a buffer > 255 characters

<sp3svm$c7o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15521&group=comp.lang.forth#15521

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: how...@inventio.co.uk (Howerd Oakford)
Newsgroups: comp.lang.forth
Subject: Re: Win32Forth REPLACE with a buffer > 255 characters
Date: Sun, 12 Dec 2021 05:14:47 +0100
Organization: A noiseless patient Spider
Lines: 100
Message-ID: <sp3svm$c7o$1@dont-email.me>
References: <smiq1s$opj$1@dont-email.me> <sp0f14$ml5$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 12 Dec 2021 04:14:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="868903b9f2ae5eee0e1a358d564fdb65";
logging-data="12536"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180li8wGmow4lStYicBeCHB"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:Gl4/WmXeGoBmd/UHrk2schMGBxw=
In-Reply-To: <sp0f14$ml5$1@dont-email.me>
Content-Language: en-US
 by: Howerd Oakford - Sun, 12 Dec 2021 04:14 UTC

On 10/12/2021 21:58, Gerry Jackson wrote:
> On 11/11/2021 10:07, Howerd Oakford wrote:
>> Hi Forthers,
>>
>> Having announced an update to Cweed4, I just noticed that the
>> Win32Forth word REPLACE uses a 256 byte string buffer and COUNT and
>> APPEND. This means that it cannot handle strings longer than 255 bytes.
>>
>> Does anyone have a (high level?) version of REPLACE that can handle
>> longer strings?
>>
>
> This implementation of REPLACE and REPLACE-ALL was written to test the
> functionality of a simple buffer similar to the standard pictured output
> buffer but without the defects.
>
> The method is straightforward. SPLIT-ALL recursively splits the source
> string into substrings of the text between replacements. When the
> recursion unwinds the substrings are copied to a buffer and their
> buffered (ca u)'s left on the data stack.
>
> Then SAVE-RESULT simply repeatedly copies a substring and replacement
> string to create the final result
>
> REPLACE calls a REPLACE-ALL factor for a single replacement. REPLACE-ALL
> should be more efficient than other solutions e.g. those that repeatedly
> delete/spread/insert the replacement as it does less string copying.
>
> \ --------------------------
> \ download buffer.fth from:
> \ https://github.com/gerryjackson/Forth-sprintf/blob/master/buffer.fth
> \ Note: <~  opens a new buffer and clears it
> \       ~holds ( ca u -- ) appends the string to the current buffer
> \       ~><~   ( -- ca u ) returns the buffer contents, closes it and
> \                          opens a new one
>
> include buffer.fth
>
> here 500 dup allot create~buffer rep-buf
>
> defer search?  \ Will be set to simulate a failed SEARCH after the first
>                \ search when REPLACE is used otherwise SEARCH
>
> : split-all  ( ca1 u1 ca2 u2 -- ~cai' ~ui' ... ~ca1 ~u1 )
>    2>r over swap 2r@ search?  ( -- ca1 ca4 ux f ) ( R: -- ca2 u2 )
>    if
>       2dup 2>r drop over - 2r>   ( -- ca1 u1' ca4 ux )
>       r@ /string        ( -- ca1 u1' ca4' ux' )
>       2r> 2rot 2>r      ( -- ca4' ux' ca2 u2 ) ( R: -- ca1 u1' )
>       recurse           ( -- )  ( R: ca1 u1' )
>       2r> ~holds ~><~   ( -- ~ca1 ~u1 )   \ (~ca ~u) is ~buffer (ca u)
>    else                 ( -- cai' cai' ui' ) ( R: ca2 u2 )
>       2r> 2drop nip     ( -- cai' ui' ) ( R: -- )
>       ~holds ~><~       ( -- ~cai ~ui )
>    then
> ;
>
> : source-concat  ( ca1 u1 ca2 -- ca2' ) \ where ca2' = ca2 + u1
>    swap 2dup + >r cmove r>
> ;
>
> : save-result  ( 0 0 ~cai ~ui ... ~ca1 ~u1 ca1 ca3 u3 -- ad )
>    2>r + >r drop   ( -- 0 0 ~cai ~ui ... ~ca2 ~u2) ( R: -- ca3 u3 ad1)
>    begin
>       2dup or
>    while
>       r> 2r@ rot source-concat ( -- 0 0 ~cai ~ui ... ~ca2 ~u2 ad2)
>       source-concat >r         ( -- 0 0 ~cai ~ui ... ~ca3 ~u3 )
>    repeat                      ( 0 0 ) ( R: ca3 u3 ad )
>    2drop r> 2r> 2drop          ( -- ad )  ( R: -- )
> ;
>
>
> \ Replace 0 or more occurrences of (ca2 u2) with (ca3 u3) in
> \ string (ca1 u1), returning the results in (ca1 u4)
> : replace*  ( ca1 u1 ca2 u2 ca3 u3 -- ca1 u4 )
>    2>r 3 pick >r 2>r          ( -- ca1 u1 ) ( R: -- ca3 u3 ca1 ca2 u2 )
>    over swap 0 0 2swap 2r>    ( -- ca1 0 0 ca1 u1 ca2 u2 )
>    rep-buf <~ split-all       ( -- ca1 0 0 ~cai ~ui ... ~ca1 ~u1 )
>    r> 2r> save-result         ( -- ca1 caj )
>    over -                     ( -- ca1 u4 )
> ;
>
> : replace  ( ca1 u1 ca2 u2 ca3 u3 -- ca1 u )
>    [: search [: 2drop 0 ;] is search? ;] is search? replace*
> ;
>
> : replace-all  ( ca1 u1 ca2 u2 ca3 u3 -- ca1 u )
>    2 pick 0= abort" Error: String to be replaced cannot be empty"
>    ['] search is search? replace*
> ;
>
Hi Gerry,

Thanks for this - I have added it to my Forth collection :-)
It is interesting to compare the different approaches...

Cheers,
Howerd

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor