File:  [gforth] / gforth / string.fs
Revision 1.8: download - view: text, annotated - select for diffs
Mon Dec 31 19:02:24 2007 UTC (16 years, 3 months ago) by anton
Branches: MAIN
CVS tags: v0-7-0, HEAD
updated copyright year after changing license notice

    1: \ dynamic string handling                              10aug99py
    2: 
    3: \ Copyright (C) 2000,2005,2007 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 3
   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, see http://www.gnu.org/licenses/.
   19: 
   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: 
   24: [IFUNDEF] insert
   25: : insert   ( string length buffer size -- )
   26:   rot over min >r  r@ - ( left over )
   27:   over dup r@ +  rot move   r> move  ;
   28: [THEN]
   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 ;
   45: : $off ( addr -- )  dup @ free throw off ;
   46: 
   47: \ dynamic string handling                              12dec99py
   48: 
   49: : $split ( addr u char -- addr1 u1 addr2 u2 )
   50:   >r 2dup r> scan dup >r dup IF  1 /string  THEN
   51:   2swap r> - 2swap ;
   52: 
   53: : $iter ( .. $addr char xt -- .. ) { char xt }
   54:   $@ BEGIN  dup  WHILE  char $split >r >r xt execute r> r>
   55:      REPEAT  2drop ;

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