zeroflag / punyforth

Forth inspired programming language for the ESP8266
Other
410 stars 43 forks source link

Enhancement Request - Escape " in strings #10

Closed ghost closed 7 years ago

ghost commented 7 years ago

The application I am writing uses a lot of strings. In this app I need to embed double quotes in other strings. I need to do things like: "\"Hello World\""

To this end I made the following change to core.frt

: eschr ( char -- char ) \ read next char from stdin
    dup [ char: \ ] literal = if
        drop key case
            [ char: r ] literal of 13 endof
            [ char: n ] literal of 10 endof
            [ char: t ] literal of 9  endof
            [ char: \ ] literal of 92 endof
            [ char: " ] literal of 34 endof  \ CAL
            EESCAPE throw
        endcase
    then ;
zeroflag commented 7 years ago

An other option is just use single single quotes in that case ( str: 'asdf "qwer" zxc'). But adding escape support makes sens too. I'll check if it brakes something, and if not I'll integrate it.

On Mon, Jan 9, 2017 at 9:41 PM, Craig Lindley notifications@github.com wrote:

The application I am writing uses a lot of strings. In this app I need to embed double quotes in other strings. I need to do things like: ""Hello World""

To this end I made the following change to core.frt

: eschr ( char -- char ) \ read next char from stdin dup [ char: \ ] literal = if drop key case [ char: r ] literal of 13 endof [ char: n ] literal of 10 endof [ char: t ] literal of 9 endof [ char: \ ] literal of 92 endof [ char: " ] literal of 34 endof \ CAL EESCAPE throw endcase then ;

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zeroflag/punyforth/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/AAnJVcN4dvcc0eZCTwUEEh_DpUXp-yFyks5rQpt_gaJpZM4LetG1 .

zeroflag commented 7 years ago

integrated