0c0cded41d/library/data/strings.retro
Commiter: Charles Childers
Author: Charles Childers
Revision: 0c0cded41d
File Size: 2.14 KB
(March 07, 2010 03:47 UTC) About 2 years ago
more reorganizations
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( String Manipulation )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Copyright [c] 2009, Luke Parrish )
( Copyright [c] 2010, Marc Simpson )
( License: ISC )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
: prepend ( $$-$ )
here -rot
2 for
dup here swap
getLength dup
allot copy
next
0 , ;
: append ( $$-$ ) swap prepend ;
: split ( $c-$$ )
tib !
here swap
dup getLength dup
for 2dup r - +
@ dup tib @
=if drop
here 1+ -rot
0 then ,
next
0 , 2drop ;
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Convert counted and zero-terminated strings. )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
{{
create buffer 64 allot
---reveal---
: cs ( $-an ) tempString dup getLength ;
: zt ( an-$ ) tuck buffer swap copy 0 swap buffer + ! buffer tempString ;
: cstype fori over + @ emit nexti ;
}}
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Append/prepend counted strings. )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
{{
: sav ( n-n ) ` dup ` push ;
---reveal---
: csprepend ( anan-an )
here sav swap sav dup allot copy
here swap sav dup allot copy
pop pop + pop swap ;
: csappend ( anan-an ) push -rot pop -rot prepend ;
}}
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Get input into a string )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
: accept$ ( $c- )
push repeat ekey dup r =if pop 2drop 0 swap ! ;then swap !+ again ;
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Search for a character in a string. Returns the address or )
( 0 if not found. )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
: scan ( $c-a )
push
repeat @+
dup 0 =if rdrop 2drop 0 ;then
r =if rdrop 1- ;then
again ; |