[gforth] / gforth / string.fs  

gforth: gforth/string.fs


1 : pazsan 1.1 \ dynamic string handling 10aug99py
2 :    
3 : anton 1.8 \ Copyright (C) 2000,2005,2007 Free Software Foundation, Inc.
4 : anton 1.3
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 : anton 1.7 \ as published by the Free Software Foundation, either version 3
10 : anton 1.3 \ 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 : anton 1.7 \ along with this program. If not, see http://www.gnu.org/licenses/.
19 : anton 1.3
20 : pazsan 1.1 : delete ( buffer size count -- )
21 :     over min >r r@ - ( left over ) dup 0>
22 :     IF 2dup swap dup r@ + -rot swap move THEN + r> bl fill ;
23 :    
24 : pazsan 1.5 [IFUNDEF] insert
25 : pazsan 1.1 : insert ( string length buffer size -- )
26 :     rot over min >r r@ - ( left over )
27 :     over dup r@ + rot move r> move ;
28 : pazsan 1.5 [THEN]
29 : pazsan 1.1
30 :     : $padding ( n -- n' )
31 :     [ 6 cells ] Literal + [ -4 cells ] Literal and ;
32 :     : $! ( addr1 u addr2 -- )
33 :     dup @ IF dup @ free throw THEN
34 :     over $padding allocate throw over ! @
35 :     over >r rot over cell+ r> move 2dup ! + cell+ bl swap c! ;
36 :     : $@len ( addr -- u ) @ @ ;
37 :     : $@ ( addr1 -- addr2 u ) @ dup cell+ swap @ ;
38 :     : $!len ( u addr -- )
39 :     over $padding over @ swap resize throw over ! @ ! ;
40 :     : $del ( addr off u -- ) >r >r dup $@ r> /string r@ delete
41 :     dup $@len r> - swap $!len ;
42 :     : $ins ( addr1 u addr2 off -- ) >r
43 :     2dup dup $@len rot + swap $!len $@ 1+ r> /string insert ;
44 :     : $+! ( addr1 u addr2 -- ) dup $@len $ins ;
45 : pazsan 1.9 : $off ( addr -- ) dup @ dup IF free throw off ELSE 2drop THEN ;
46 : pazsan 1.1
47 :     \ dynamic string handling 12dec99py
48 :    
49 :     : $split ( addr u char -- addr1 u1 addr2 u2 )
50 : pazsan 1.2 >r 2dup r> scan dup >r dup IF 1 /string THEN
51 :     2swap r> - 2swap ;
52 : pazsan 1.1
53 : pazsan 1.10 : $iter ( .. $addr char xt -- .. ) >r >r
54 :     $@ BEGIN dup WHILE r@ $split i' -rot >r >r execute r> r>
55 :     REPEAT 2drop rdrop rdrop ;

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help