From 667f03b30bae0a89f99bf9ac8183597ebde52fc2 Mon Sep 17 00:00:00 2001 From: crc Date: Tue, 11 Feb 2020 20:15:35 +0000 Subject: [PATCH] retro.forth: move s:tokenize-on-string, s:replace-all to be grouped with other string words, no longer needs a: words defined first FossilOrigin-Name: 0aff09c9faea31720dd867fa87309f386365e275330d473b5f20aca154b32168 --- image/retro.forth | 80 ++-- ngaImage | Bin 38108 -> 38328 bytes vm/nga-c/retro-image.c | 861 +++++++++++++++++++++-------------------- 3 files changed, 472 insertions(+), 469 deletions(-) diff --git a/image/retro.forth b/image/retro.forth index 18e00dc..7248bdf 100644 --- a/image/retro.forth +++ b/image/retro.forth @@ -1156,6 +1156,46 @@ returns an array containing pointers to each of them. }} ~~~ +`s:tokenize-on-string` is like `s:tokenize`, but for strings. + +~~~ +{{ + 'Needle d:create #128 allot + 'Length var + 'Tokens d:create #128 allot + 'TP var + :save s:keep @TP &Tokens + n:inc store &TP v:inc ; + :next [ @Length + ] sip ; + :done s:length n:zero? ; +---reveal--- + :s:tokenize-on-string (ss-s) + #0 !TP + [ dup &Needle s:copy s:append ] [ s:length !Length ] bi + [ &Needle s:split-on-string save next done ] until + &Tokens @TP n:dec !Tokens ; +}} +~~~ + +~~~ +{{ + 'Q var + :for-each (aq-) + &Q [ !Q fetch-next + [ fetch-next swap [ @Q call ] dip ] times drop + ] v:preserve ; + :substitute STRINGS #129 - ; + :extract substitute s:copy ; + :tokenize s:tokenize-on-string s:empty ; + :combine substitute s:append s:append ; + :merge swap &combine for-each nip ; + :find-end dup s:length substitute s:length - over + ; + :clean find-end #0 swap store ; +---reveal--- + :s:replace-all (sss-s) + &Heap [ extract tokenize merge clean s:temp ] v:preserve ; +}} +~~~ + Use `s:format` to construct a string from multiple items. This can be illustrated with: @@ -1550,46 +1590,6 @@ different array. &Heap [ dup a:length &swap dip a:right a:eq? ] v:preserve ; ~~~ -## Strings - -Returning to strings, leveraging the array words alongside them -I can implement `s:replace-all` and `s:tokenize-on-string`. - -`s:tokenize-on-string` is like `s:tokenize`, but for strings. - -~~~ -{{ - 'Needle d:create #128 allot - 'Length var - 'Tokens d:create #128 allot - 'TP var - :save s:keep @TP &Tokens a:store &TP v:inc ; - :next [ @Length + ] sip ; - :done s:length n:zero? ; ----reveal--- - :s:tokenize-on-string (ss-s) - #0 !TP - [ dup &Needle s:copy s:append ] [ s:length !Length ] bi - [ &Needle s:split-on-string save next done ] until - &Tokens @TP n:dec !Tokens ; -}} -~~~ - -~~~ -{{ - :substitute STRINGS #129 - ; - :extract substitute s:copy ; - :tokenize s:tokenize-on-string s:empty ; - :combine substitute s:append s:append ; - :merge swap &combine a:for-each nip ; - :find-end dup s:length substitute s:length - over + ; - :clean find-end #0 swap store ; ----reveal--- - :s:replace-all (sss-s) - &Heap [ extract tokenize merge clean s:temp ] v:preserve ; -}} -~~~ - ## Evaluating Source The standard interfaces have their own approaches to getting diff --git a/ngaImage b/ngaImage index 29b7a461b6b12cf0a0383d0d26662c07f4cad8f2..521198a94e2c1a75d373204c574077fe7bb5e265 100644 GIT binary patch delta 5652 zcmai24RBP|72bUz&m^*eBxIB9ZuT$929}x$MxsVs5|E$~LX1f34x*75NPzqxg^(E1 z0TBogHaY%RpgL+*bX3r`iZE!a9hgo=s)N;5q%(DFwN#OcKQqLB-`jiBHI4So+_~p` z=Q}_5-23j^=)Q<-{Lu4XtS+)-m%57M-SX%9CXNM6UHA{Jh3#8Ov~v5 z1Jf=r?dE|8F5NfPcrW+BH@!i_@n){g)|h9rZL-;H^W?fTcNzp+6i8d%f!d8hBX}F+ zFBD@TY;`24=TqRrc`|rssGJl#;5N(|nC&Sx+x!b{wuzK6EIY9Mz?kD4c-byl(&L_i z^4%`5Cd5mjHyQNGAr7yrFo-#zPsWHrZp3Jl>$YV{-R6nrUMyseOHM|ea>wSnUMn2} zUk|bYB7?mL3WNO-88`=!P$#;UiNIgX8MX!VLGA2~=KNUM>R=~#74?L;eieT>&(>lE z$yN@mSO>XPVQ(@BoY^m~T=yr6{xC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