|
|
1.1 root 1: # ESCAPE
2: #
3: # Interpret Icon literal escapes
4: #
5: # William H. Mitchell
6: #
7: # Last mofied 2/1/86
8: #
9:
10: procedure escape(s)
11: ns := ""
12: s ? while c := move(1) do {
13: ns ||:= if c == "\\" then case c2 := (move(1) | "") of {
14: "b": "\b"
15: "d": "\d"
16: "e": "\e"
17: "f": "\f"
18: "l": "\n"
19: "n": "\n"
20: "r": "\r"
21: "t": "\t"
22: "v": "\v"
23: "'": "'"
24: "\"": "\""
25: "x": hexcode()
26: "^": ctrlcode(move(1))
27: any('01234567',c2) & c2: octcode(c2)
28: default: c2
29: } else c
30: }
31: return ns
32: end
33:
34: procedure hexcode()
35: static cdigs
36: initial cdigs := ~'0123456789ABCDEFabcdef'
37:
38: move(i := 2 | 1) ? s := tab(upto(cdigs) | 0)
39: move(*s - i)
40: return &cset[integer("16r" || s) + 1]
41: end
42:
43: procedure octcode(c)
44: static cdigs
45: initial cdigs := ~'01234567'
46:
47: move(-1)
48: move(i := 3 | 2 | 1) ? s := tab(upto(cdigs) | 0)
49: move(*s - i)
50: return &cset[integer("8r" || s) + 1]
51: end
52:
53: procedure ctrlcode(s)
54: return &cset[find(map(s),&lcase) + 1]
55: end
56:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.