Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #57323

Re: [Random] Escape the trolls

From Alex <alex@rivadpm.com>
Newsgroups comp.lang.forth
Subject Re: [Random] Escape the trolls
Date 2017-04-14 21:59 +0100
Organization A noiseless patient Spider
Message-ID <ocrd17$geb$1@dont-email.me> (permalink)
References (4 earlier) <892a9e40-5e94-4d9d-a883-b07b4f852e26@googlegroups.com> <ecbe8491-988e-4f14-9932-506b0041e4f9@googlegroups.com> <ocralc$8bd$1@dont-email.me> <632a018f-b830-4aa0-a96c-758d2cf3a1b3@googlegroups.com> <ocrcfr$epp$1@dont-email.me>

Show all headers | View raw


On 4/14/2017 21:49, rickman wrote:
> On 4/14/2017 4:25 PM, NN wrote:
>> s\" is not there because it hasnt been implemented. This is forth you 
>> can always write your own _
> 
> I know it hasn't been implemented in Win32Forth.  That's what I'm 
> wondering about.  I would hazard a guess that there is an equivalent 
> word and S/" just hasn't been added since it would just be a synonym.  I 
> haven't found it yet though.
> 

You could adapt this. It also supports \unnnn for Unicode point nnnn.

-400 constant throw_malestr

create esc-table ( table of translations for a..z )
         7 c,	\ \a bel (alert)
         8 c,	\ \b bs  (backspace)
       'c' c,    \ \c
       'd' c,    \ \d
        27 c,	\ \e esc (escape)
        12 c,	\ \f ff  (form feed)
       'g' c,    \ \g
       'h' c,    \ \h
       'i' c,    \ \i
       'j' c,    \ \j
       'k' c,    \ \k
        10 c,	\ \l lf  (line feed)
       'm' c,    \ \m
        10 c,    \ \n ( CRLF, \r\n )
       'o' c,    \ \o
       'p' c,    \ \p
       '"' c,    \ \q "   (double quote)
        13 c,	\ \r cr  (carriage return)
       's' c,    \ \s
         9 c,	\ \t ht  (horizontal tab}
       'u' c,    \ \u     (becomes UTF-8)
        11 c,	\ \v vt  (vertical tab)
       'w' c,    \ \w
       'x' c,    \ \x     (becomes hex)
       'y' c,    \ \y
         0 c,	\ \z nul (no character)

\ Convert a number to a UTF-8 string and append to
\ a counted string

8 import: WideCharToMultiByte

: addUTF-8 \ {: w^ n dest -- :}
     dup>r sp@ cell+ >r >r
     0 0 4 r> count +
     -1 r> 0 cp_utf8
     WideCharToMultiByte
     dup 0= throw_malestr ?throw
     1- r> c+! drop ;

\ Extract an n-digit hex number in the given base from the
\ start of the string, returning the remaining string
\ and the converted number.

: extract-hex ( c-addr len n -- c-addr' len' u )
     base@ >r hex
     >r 0 0 2over r@ < throw_malestr ?throw ( input string too short )
     r@ >number throw_malestr ?throw        ( not hex characters )
     2drop r> swap >r /string r>
     r> base! ;

: addEscape	( c-addr len dest -- c-addr' len' )
     >r dup 0= throw_malestr ?throw         ( input string too short )
     over c@ case
       'n' of
         crlf$ count r> +place endof
       'm' of
         crlf$ count r> +place endof
       'x' of
         1 /string 2 extract-hex r> c+place exit endof
       'u' of
         1 /string 4 extract-hex r> addUTF-8 exit endof
       dup dup 'a' 'z' between if
         'a' - esc-table + c@
       then r> c+place
     endcase 1 /string ;

: unescape-str ( c-addr len dest -- c-addr' len' )
     dup>r  0 swap c!                     \ zero destination
     begin dup                         \ -- caddr len ; R: -- dest
      while
       over c@ '"' <>                 \ check for terminator
      while
       over c@ dup
       '\' = if               \ deal with escapes
         drop 1 /string r@ addEscape
       else                                \ normal character
         r@ c+place
         1 /string
       then
     repeat then 1 /string r>drop ;

: parse\" ( "ccc" -- c-addr l )
     source-remain tuck
     buf-allot dup>r unescape-str nip
     - >in +!
     r> count ;

: s\" ( -- )
     parse\"
     compiles> ( -- c-addr len ) drop
       parse\"  postpone sliteral ;



-- 
Alex

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[Random] Escape the trolls Julian Fondren <julian.fondren@gmail.com> - 2017-04-13 22:46 -0700
  Re: [Random] Escape the trolls NN <november.nihal@gmail.com> - 2017-04-14 10:53 -0700
    Re: [Random] Escape the trolls Julian Fondren <julian.fondren@gmail.com> - 2017-04-14 11:26 -0700
      Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-14 15:30 -0400
        Re: [Random] Escape the trolls Julian Fondren <julian.fondren@gmail.com> - 2017-04-14 12:45 -0700
          Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-14 16:02 -0400
          Re: [Random] Escape the trolls NN <november.nihal@gmail.com> - 2017-04-14 13:13 -0700
            Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-14 16:18 -0400
              Re: [Random] Escape the trolls NN <november.nihal@gmail.com> - 2017-04-14 13:25 -0700
                Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-14 16:49 -0400
                Re: [Random] Escape the trolls Alex <alex@rivadpm.com> - 2017-04-14 21:59 +0100
              Re: [Random] Escape the trolls josv@planet.nl - 2017-04-15 04:09 -0700
                Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-15 12:45 -0400
                Re: [Random] Escape the trolls Coos Haak <htrofhc@gmail.com> - 2017-04-15 18:50 +0200
                Re: [Random] Escape the trolls NN <november.nihal@gmail.com> - 2017-04-15 15:45 -0700
          Re: [Random] Escape the trolls hughaguilar96@gmail.com - 2017-04-14 14:46 -0700
            Re: [Random] Escape the trolls Julian Fondren <julian.fondren@gmail.com> - 2017-04-14 15:35 -0700
              Re: [Random] Escape the trolls hughaguilar96@gmail.com - 2017-04-14 16:24 -0700
                Re: [Random] Escape the trolls Alex <alex@rivadpm.com> - 2017-04-15 00:34 +0100
                Re: [Random] Escape the trolls Alex <alex@rivadpm.com> - 2017-04-15 00:36 +0100
                Re: [Random] Escape the trolls hughaguilar96@gmail.com - 2017-04-14 20:58 -0700
                Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-15 00:24 -0400
                Re: [Random] Escape the trolls hughaguilar96@gmail.com - 2017-04-14 21:40 -0700
                Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-15 02:32 -0400
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-15 07:50 +0000
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-15 08:15 +0000
                Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-15 13:10 -0400
                Re: [Random] Escape the trolls Coos Haak <htrofhc@gmail.com> - 2017-04-15 19:27 +0200
                Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-15 14:25 -0400
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-17 14:05 +0000
                Re: [Random] Escape the trolls "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-16 01:42 +0000
                Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-15 21:51 -0400
                Re: [Random] Escape the trolls "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-16 02:10 +0000
                Re: [Random] Escape the trolls Coos Haak <htrofhc@gmail.com> - 2017-04-16 14:29 +0200
                Re: [Random] Escape the trolls "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-16 13:58 +0000
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-16 16:11 +0000
                Re: [Random] Escape the trolls "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-16 22:18 +0000
                Re: [Random] Escape the trolls Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2017-04-17 07:54 +0100
                Re: [Random] Escape the trolls "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-17 23:32 +0000
                Re: [Random] Escape the trolls "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-17 23:33 +0000
                Re: [Random] Escape the trolls Julian Fondren <julian.fondren@gmail.com> - 2017-04-14 22:33 -0700
                Re: [Random] Escape the trolls Julian Fondren <julian.fondren@gmail.com> - 2017-04-14 22:52 -0700
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-15 07:52 +0000
                Re: [Random] Escape the trolls Alex <alex@rivadpm.com> - 2017-04-15 11:20 +0100
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-15 11:53 +0000
                Re: [Random] Escape the trolls Alex <alex@rivadpm.com> - 2017-04-15 19:10 +0100
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-17 14:19 +0000
                Re: [Random] Escape the trolls Bernd Linsel <bl1@gmx.com> - 2017-04-15 20:21 +0200
                Re: [Random] Escape the trolls Alex <alex@rivadpm.com> - 2017-04-15 20:33 +0100
                Re: [Random] Escape the trolls Bernd Linsel <bl1@gmx.com> - 2017-04-16 11:50 +0200
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-16 14:22 +0000
                Re: [Random] Escape the trolls anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-16 14:47 +0000
                Re: [Random] Escape the trolls hughaguilar96@gmail.com - 2017-04-15 16:55 -0700
                Re: [Random] Escape the trolls hughaguilar96@gmail.com - 2017-04-15 17:03 -0700
                Re: [Random] Escape the trolls Alex <alex@rivadpm.com> - 2017-04-15 11:37 +0100
                Re: [Random] Escape the trolls Julian Fondren <julian.fondren@gmail.com> - 2017-04-14 16:51 -0700
                Re: [Random] Escape the trolls rickman <gnuarm@gmail.com> - 2017-04-14 21:24 -0400

csiph-web