File:  [CSRG BSD Unix] / 43BSD / contrib / icon / src / lib / escape.icn
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:55 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43
BSD 4.3

#	ESCAPE(2)
#
#	Interpret Icon literal strings
#
#	William H. Mitchell
#
#	Last modified 8/14/84
#

procedure escape(s)
   static digits
   initial digits := '0123456789'
   ns := ""
   s ? while c := move(1) do {
      ns ||:=
         if c == "\\" then
         case c2 := (move(1) | "") of {
            "b": "\b"
            "d": "\d"
            "e": "\e"
            "f": "\f"
            "l": "\l"
            "n": "\n"
            "r": "\r"
            "t": "\t"
            "v": "\v"
            "\'": "\'"
            "\"": "\""
            "x": hexcode(move(2))
            "^": ctrlcode(move(1))
            any(digits,c2) & c2: octcode(c2 || move(2))
            "": c
            default: {move(-1); c}
            }
      else c
      }
   return ns
end

procedure hexcode(s)
   return &cset[integer("16r" || s) + 1]
end

procedure octcode(s)
   return &cset[integer("8r" || s) + 1]
end

procedure ctrlcode(s)
   return &cset[find(map(s),&lcase) + 1]
end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.