(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))))