( Title: Measured string concatenation File: mstrings-cat.fs Author: David N. Williams License: LGPL Version: 0.8.4 Test file: mstrings-test.fs Change log: mstrings.log Revised: November 22, 2008 Some of this file is derived from Wil Baden's ToolBelt, which we believe to be in the public domain. For the sake of the LGPL, any part of this file not under another copyright is Copyright [C] 2002, 2007, 2008 David N. Williams This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or at your option any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. If you take advantage of the option in the LGPL to put a particular version of this library under the GPL, the author[s] would regard it as polite if you would put any direct modifications under the LGPL as well, and include a copy of this request near the beginning of the modified library source. A "direct modification" is one that enhances or extends the library in line with its original concept, as opposed to developing a distinct application or library which might use it. This is a library in the mstrings collection. It is mostly ANS Forth compatible up to case dependence, [UNDEFINED], and REQUIRED. The code is intended to be character clean. Please see the file mstrings.txt for terminology and more detailed word specifications. ) decimal s" mstrings-srep.fs" required \ *** CONCATENATION WORDS \ (M+) M+ROOM? M+ \ *** UTILITY WORDS \ DEBUGGING \ : .# ( n -- ) cr ." #" . cr ; [UNDEFINED] u>= [IF] : u>= ( u1 u2 -- flag ) u< 0= ; [THEN] [UNDEFINED] 3drop [IF] : 3drop ( x y z -- ) 2drop drop ; [THEN] [UNDEFINED] chars+ [IF] : chars+ ( x n -- x+c[n] ) chars + ; [THEN] \ *** DEFINITIONS ( Note that a sequence of mstring concatenations can be initialized by invoking 0 !. ) : (m+) ( s m -- ) ( Append the fstring to the mstring, no checks. ) 2dup 2>r mcount chars+ swap cmove 2r> +! ; : m+room? ( len mbuf /mbuf -- len mbuf flag ) ( The flag is the value of the predicate: c[len + count] + cell <= /mbuf. ) over @ ( /mbuf count) 3 pick + /m u>= ; : m+ ( s mbuf /mbuf -- flag ) ( Append the fstring body to the mstring in the mbuffer, with overflow checking. Note that there is an ANS Forth Double-Number word with the same name. ) m+room? IF (m+) true ELSE 3drop false THEN ;