home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # Name: escape.icn
- #
- # Title: Interpret Icon literal escapes
- #
- # Author: William H. Mitchell, modified by Ralph E. Griswold
- #
- # Date: November 21, 1988
- #
- ############################################################################
- #
- # The procedure escape(s) produces a string in which Icon quoted
- # literal escape conventions in s are replaced by the corresponding
- # characters. For example, escape("\\143\\141\\164") produces the
- # string "cat".
- #
- ############################################################################
-
- procedure escape(s)
- local ns, c
-
- ns := ""
- s ? {
- while ns ||:= tab(upto('\\')) do {
- move(1)
- ns ||:= case c := move(1 | 0) of {
- "b": "\b"
- "d": "\d"
- "e": "\e"
- "f": "\f"
- "l": "\n"
- "n": "\n"
- "r": "\r"
- "t": "\t"
- "v": "\v"
- "'": "'"
- "\"": "\""
- "x": hexcode()
- "^": ctrlcode()
- !"01234567": octcode()
- default: c
- }
- }
- ns ||:= tab(0)
- }
- return ns
- end
-
- procedure hexcode()
- local i, s
- static cdigs
- initial cdigs := ~'0123456789ABCDEFabcdef'
-
- move(i := 2 | 1) ? s := tab(upto(cdigs) | 0)
- move(*s - i)
- return char("16r" || s)
- end
-
- procedure octcode()
- local i, s
- static cdigs
- initial cdigs := ~'01234567'
-
- move(-1)
- move(i := 3 | 2 | 1) ? s := tab(upto(cdigs) | 0)
- move(*s - i)
- return char("8r" || s)
- end
-
- procedure ctrlcode(s)
- return char(upto(map(move(1)),&lcase))
- end
-
-