blob: 197e01a4d2d3723fea1fb6811a85ed7834786639 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
(define-module (c trigraph)
:use-module (ice-9 regex)
:export (replace-trigraphs))
(define rx (make-regexp "\\?\\?([=\\(\\)'!<>/-])"))
(define (proc m)
(case (string-ref (match:substring m 2) 0)
((#\=) "#")
((#\() "[")
((#\)) "]")
((#\') "^")
((#\<) "{")
((#\>) "}")
((#\!) "|")
((#\-) "~")
((#\/) "\\")))
(define (replace-trigraphs string)
(call-with-output-string
(lambda (port)
(regexp-substitute/global
port rx string
'pre proc 'post))))
|