Source file EML_runtime.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(** [EML_runtime] provides runtime utilities for the code generated by the EML
compiler. *)
(** [escape s] is the HTML-escaped version of the string [s].
Characters '&', '<', '>', '"' and ''' are replaced by their HTMl encoding. *)
let escape s =
let buffer = Buffer.create (String.length s) in
String.iter
(function
| '&' ->
Buffer.add_string buffer "&"
| '<' ->
Buffer.add_string buffer "<"
| '>' ->
Buffer.add_string buffer ">"
| '"' ->
Buffer.add_string buffer """
| '\'' ->
Buffer.add_string buffer "'"
| c ->
Buffer.add_char buffer c )
s ;
Buffer.contents buffer