diff --git a/startup.4th b/startup.4th index 5062ae5..c23492e 100644 --- a/startup.4th +++ b/startup.4th @@ -1734,19 +1734,29 @@ CREATE TIB-LEFTOVER-BYTES 0 , ENDCASE THEN ; +2VARIABLE STRING-BUFFER +0 0 STRING-BUFFER 2! + \ Read a literal character string up to the next double-quote character -\ Unlike WORD the string is stored in contiguous *allocated* data space +\ The string is stored in a transient buffer and will become invalid when +\ the next string is read; both the address and content may change \ The delimiting double-quote character is removed from the input buffer \ Double-quote and backslash characters can be escaped with a backslash : READSTRING ( "ccc" -- c-addr u ) - HERE + STRING-BUFFER 2@ 0 + ( S: addr length index ) BEGIN PEEK-CHAR [CHAR] " <> WHILE - ESCAPED-CHAR C, + 2DUP <= IF + \ Grow the buffer by at least 50% + 16 bytes + \ Store the actual allocated object size, not the requested size + -ROT DUP 2/ + 16 + RESIZE DUP OBJECT-SIZE + 2DUP STRING-BUFFER 2! ROT + THEN + ROT 2DUP + ESCAPED-CHAR SWAP C! -ROT 1+ REPEAT - SKIP-CHAR - HERE OVER - ; + SKIP-CHAR NIP ; : PARSENUMBER ( c-addr u -- n TRUE | c-addr u FALSE ) DUP 0= IF FALSE EXIT THEN @@ -1776,12 +1786,11 @@ CREATE TIB-LEFTOVER-BYTES 0 , WHILE PEEK-CHAR [CHAR] " = IF SKIP-CHAR + READSTRING STATE @ IF POSTPONE LITSTRING - HERE 0 C, - READSTRING NIP SWAP C! ALIGN - ELSE - READSTRING + 255 UMIN DUP C, + HERE SWAP DUP ALLOT CMOVE ALIGN THEN ELSE WORD