This is G o o g l e's cache of http://home.earthlink.net/~neilbawd/quotstr2.html.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:caUqpAw2McoC:home.earthlink.net/~neilbawd/quotstr2.html+&hl=en&ie=UTF-8


Google is not affiliated with the authors of this page nor responsible for its content.

Quote in String

Quote in String

Get TEXT

Wil Baden 2000-04-04 2001-07-05

Quote in string and LEXEME have been in Neil Bawd's Home for more than a year. My feelings about them have changed.

Double quote to get a single quote in S" and ." is nice to have in source code that needs quotes in strings or messages. However it is not Standard Forth, although I don't think that it breaks any Standard code example. But double quote for single quote will fail if it has not been implemented.

Now the feature is loaded when needed, with names S"" and ."". The double quote in the name is to show that double quotes will be changed to single quotes.

LEXEME is a poor name. A thesaurus is a bad programming aid. Names of functions should be descriptive, not mysterious. The open choice of delimiter is a ability that it not necessary with double quote for single quote.

LEXEME has been replaced with the better named NEXT-STRING that can use double quote for single quote.

Functions - Source in Neil Bawd's Home

    http://home.earthlink.net/~neilbawd/

S""                 ( "text" -- str len )
S" adapted to render "" as ". The text ends with a " that is not doubled. In this implementation just one buffer is used for the text.
.""                 ( "text" -- )
." adapted to render "" as ". The text ends with a " that is not doubled.
,""                 ( "text" -- )
," adapted to render "" as ". The text ends with a " that is not doubled.
NEXT-STRING         ( "name" -- str len )
Get the next word on the line as a character string. If it's the single character ", drop it and parse for a single quote to delimit the string.

Examples for NEXT-STRING

    Hello               ==> Hello
    "Hello"             ==> "Hello"
    " Hello World"      ==> Hello World
    " ""Hello World"""  ==> "Hello World"
    " """               ==> "

    : INCLUDE  NEXT-STRING INCLUDED ;

Program Text 1
    CREATE String-Pad  128 CHARS ALLOT

    : Parse-for-Single-Quote  ( "string<single-quote>" -- str len )
        0 >R
            SOURCE >IN @ /STRING      ( src len)
            BEGIN
                OVER C@ [CHAR] " = NOT
                ORIF OVER 1+ C@ [CHAR] " = THEN
            WHILE
                OVER C@ [CHAR] " = IF
                    1 /STRING  1 >IN +!
                THEN
                OVER C@ String-Pad R>  DUP 1+ >R  + C!
                1 /STRING  1 >IN +!
            REPEAT
            2DROP  1 >IN +!            ( )
        String-Pad R>                  ( src len)
        ;

: S""                ( "string<single-quote>" -- str len )
    Parse-for-Single-Quote               ( str len)
    STATE @ IF  POSTPONE SLITERAL  THEN
    ; IMMEDIATE

: .""                ( "string<single-quote>" -- )
    POSTPONE S""                ( str len)
    STATE @ IF  POSTPONE TYPE
    ELSE        TYPE
    THEN ; IMMEDIATE

: ,""                ( "string<single-quote>" -- )
   POSTPONE S"" STRING, ; IMMEDIATE

: NEXT-STRING        ( "string" -- str len )
    PARSE-WORD                    ( str len)
    2dup S"" """ COMPARE 0= IF
        2DROP  Parse-for-Single-Quote
    THEN ;


Go back to home page.