File:  [gforth] / gforth / string.fs
Revision 1.4: download - view: text, annotated - select for diffs
Sat Sep 23 15:46:59 2000 UTC (19 years, 1 month ago) by anton
Branches: MAIN
CVS tags: v0-6-2, v0-6-1, v0-6-0, v0-5-0, HEAD
changed FSF address in copyright messages

    1: \ dynamic string handling                              10aug99py
    2: 
    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: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   20: 
   21: : 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: : insert   ( string length buffer size -- )
   26:   rot over min >r  r@ - ( left over )
   27:   over dup r@ +  rot move   r> move  ;
   28: 
   29: : $padding ( n -- n' )
   30:   [ 6 cells ] Literal + [ -4 cells ] Literal and ;
   31: : $! ( addr1 u addr2 -- )
   32:   dup @ IF  dup @ free throw  THEN
   33:   over $padding allocate throw over ! @
   34:   over >r  rot over cell+  r> move 2dup ! + cell+ bl swap c! ;
   35: : $@len ( addr -- u )  @ @ ;
   36: : $@ ( addr1 -- addr2 u )  @ dup cell+ swap @ ;
   37: : $!len ( u addr -- )
   38:   over $padding over @ swap resize throw over ! @ ! ;
   39: : $del ( addr off u -- )   >r >r dup $@ r> /string r@ delete
   40:   dup $@len r> - swap $!len ;
   41: : $ins ( addr1 u addr2 off -- ) >r
   42:   2dup dup $@len rot + swap $!len  $@ 1+ r> /string insert ;
   43: : $+! ( addr1 u addr2 -- ) dup $@len $ins ;
   44: : $off ( addr -- )  dup @ free throw off ;
   45: 
   46: \ dynamic string handling                              12dec99py
   47: 
   48: : $split ( addr u char -- addr1 u1 addr2 u2 )
   49:   >r 2dup r> scan dup >r dup IF  1 /string  THEN
   50:   2swap r> - 2swap ;
   51: 
   52: : $iter ( .. $addr char xt -- .. ) { char xt }
   53:   $@ BEGIN  dup  WHILE  char $split >r >r xt execute r> r>
   54:      REPEAT  2drop ;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>