Annotation of gforth/string.fs, revision 1.12
1.1 pazsan 1: \ dynamic string handling 10aug99py
2:
1.12 ! anton 3: \ Copyright (C) 2000,2005,2007,2010 Free Software Foundation, Inc.
1.3 anton 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
1.7 anton 9: \ as published by the Free Software Foundation, either version 3
1.3 anton 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
1.7 anton 18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.3 anton 19:
1.1 pazsan 20: : 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:
1.5 pazsan 24: [IFUNDEF] insert
1.1 pazsan 25: : insert ( string length buffer size -- )
26: rot over min >r r@ - ( left over )
27: over dup r@ + rot move r> move ;
1.5 pazsan 28: [THEN]
1.1 pazsan 29:
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 ;
1.9 pazsan 45: : $off ( addr -- ) dup @ dup IF free throw off ELSE 2drop THEN ;
1.11 pazsan 46: : $init ( addr -- ) >r r@ off s" " r> $! ;
1.1 pazsan 47:
48: \ dynamic string handling 12dec99py
49:
50: : $split ( addr u char -- addr1 u1 addr2 u2 )
1.2 pazsan 51: >r 2dup r> scan dup >r dup IF 1 /string THEN
52: 2swap r> - 2swap ;
1.1 pazsan 53:
1.10 pazsan 54: : $iter ( .. $addr char xt -- .. ) >r >r
55: $@ BEGIN dup WHILE r@ $split i' -rot >r >r execute r> r>
56: REPEAT 2drop rdrop rdrop ;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>