home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OL.LZH
/
PROCS.LZH
/
ESCAPE.ICN
< prev
next >
Wrap
Text File
|
1991-09-05
|
2KB
|
90 lines
############################################################################
#
# Name: escape.icn
#
# Title: Interpret Icon literal escapes
#
# Author: William H. Mitchell, modified by Ralph E. Griswold, and
# Alan Beale
#
# Date: July 26, 1991
#
############################################################################
#
# 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".
#
############################################################################
#
# Links: ebcdic
#
############################################################################
link ebcdic
procedure escape(s)
local ns, c
ns := ""
s ? {
while ns ||:= tab(upto('\\')) do {
move(1)
ns ||:= {
c := map(move(1)) | break
case c 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 hdigits
initial hdigits := ~'0123456789ABCDEFabcdef'
move(i := 2 | 1) ? s := tab(upto(hdigits) | 0)
move(*s - i)
return char("16r" || s)
end
procedure octcode()
local i, s
static odigits
initial odigits := ~'01234567'
move(-1)
move(i := 3 | 2 | 1) ? s := tab(upto(odigits) | 0)
move(*s - i)
if s > 377 then { # back off if too large
s := s[1:3]
move(-1)
}
return char("8r" || s)
end
procedure ctrlcode(s)
return Control(move(1))
end