ANEW --QUOTSTR-- \ Wil Baden 2002-03-29 \ ******************************************************************* \ * * \ * Wil Baden 2003-01-21 * \ * * \ * Quote in String * \ * * \ * ," Check-Quote S * \ * ." Parse-for-Single-Quote S" * \ * * \ ******************************************************************* \ S" ( "ccc" -- str len ) \ `S"` adapted to render `""` as `"`. The text ends with a `"` \ that is not doubled. . \ ." ( "ccc" -- ) \ `."` adapted to render `""` as `"`. The text ends with a `"` \ that is not doubled. Works when interpreted. \ ," ( "ccc" -- ) \ `,"` adapted to render `""` as `"`. The text ends with a `"` \ that is not doubled. \ S ( "word [...]" -- str_2 len_2 ) \ Parse word. Then check quote. \ Parse-for-Single-Quote ( "ccc" -- str len ) \ Parse for quote `"` not followed by quote `"`. A pair of \ quotes `""` is taken as a single quote `"`. \ Check-Quote ( str len [...] -- str_2 len_2) \ Check if _str len_ is a single quote. If so, drop it and parse \ for a single quote. \ Uses `Parse-for-Single-Quote`. \ ************** Parse-for-Single-Quote Check-Quote ************** 128 BUFFER: Quote-Buffer : Parse-for-Single-Quote ( "ccc" -- str len ) 0 Quote-Buffer C! BEGIN [char] " PARSE ( str len) 2dup Quote-Buffer APPEND 1+ chars + dup C@ [char] " = WHILE ( addr) 1 Quote-Buffer APPEND ( ) 1 >IN +! REPEAT DROP Quote-Buffer COUNT ; : Check-Quote ( str len [...] -- str_2 len_2) dup 1 = IF over C@ [char] " = IF 2DROP Parse-for-Single-Quote THEN THEN ; \ ************************* S" ." ," S ************************* : S" ( "ccc" -- str len ) Parse-for-Single-Quote ( str len) STATE @ IF postpone SLITERAL THEN ; IMMEDIATE : ." ( "ccc" -- ) postpone S" ( str len) STATE @ IF postpone TYPE ELSE TYPE THEN ; IMMEDIATE : ," ( "ccc" -- ) postpone S" STRING, ; IMMEDIATE : S ( "string" -- str len ) PARSE-WORD Check-Quote ( str len) STATE @ IF postpone SLITERAL THEN ; IMMEDIATE \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\