[gforth] / gforth / string.fs  

gforth: gforth/string.fs


1 : pazsan 1.1 \ dynamic string handling 10aug99py
2 :    
3 : anton 1.3 \ Copyright (C) 2000 Free Software Foundation, Inc.
4 :    
5 :     \ This file is part of Gforth.
6 :    
7 :     \ Gforth is free software; you can redistribute it and/or
8 :     \ modify it under the terms of the GNU General Public License
9 :     \ as published by the Free Software Foundation; either version 2
10 :     \ of the License, or (at your option) any later version.
11 :    
12 :     \ This program is distributed in the hope that it will be useful,
13 :     \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14 :     \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 :     \ GNU General Public License for more details.
16 :    
17 :     \ You should have received a copy of the GNU General Public License
18 :     \ along with this program; if not, write to the Free Software
19 : anton 1.4 \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 : anton 1.3
21 : pazsan 1.1 : delete ( buffer size count -- )
22 :     over min >r r@ - ( left over ) dup 0>
23 :     IF 2dup swap dup r@ + -rot swap move THEN + r> bl fill ;
24 :    
25 : pazsan 1.5 [IFUNDEF] insert
26 : pazsan 1.1 : insert ( string length buffer size -- )
27 :     rot over min >r r@ - ( left over )
28 :     over dup r@ + rot move r> move ;
29 : pazsan 1.5 [THEN]
30 : pazsan 1.1
31 :     : $padding ( n -- n' )
32 :     [ 6 cells ] Literal + [ -4 cells ] Literal and ;
33 :     : $! ( addr1 u addr2 -- )
34 :     dup @ IF dup @ free throw THEN
35 :     over $padding allocate throw over ! @
36 :     over >r rot over cell+ r> move 2dup ! + cell+ bl swap c! ;
37 :     : $@len ( addr -- u ) @ @ ;
38 :     : $@ ( addr1 -- addr2 u ) @ dup cell+ swap @ ;
39 :     : $!len ( u addr -- )
40 :     over $padding over @ swap resize throw over ! @ ! ;
41 :     : $del ( addr off u -- ) >r >r dup $@ r> /string r@ delete
42 :     dup $@len r> - swap $!len ;
43 :     : $ins ( addr1 u addr2 off -- ) >r
44 :     2dup dup $@len rot + swap $!len $@ 1+ r> /string insert ;
45 :     : $+! ( addr1 u addr2 -- ) dup $@len $ins ;
46 :     : $off ( addr -- ) dup @ free throw off ;
47 :    
48 :     \ dynamic string handling 12dec99py
49 :    
50 :     : $split ( addr u char -- addr1 u1 addr2 u2 )
51 : pazsan 1.2 >r 2dup r> scan dup >r dup IF 1 /string THEN
52 :     2swap r> - 2swap ;
53 : pazsan 1.1
54 :     : $iter ( .. $addr char xt -- .. ) { char xt }
55 :     $@ BEGIN dup WHILE char $split >r >r xt execute r> r>
56 :     REPEAT 2drop ;

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help