package embedded_ocaml_templates

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

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 "&amp;"
      | '<' ->
          Buffer.add_string buffer "&lt;"
      | '>' ->
          Buffer.add_string buffer "&gt;"
      | '"' ->
          Buffer.add_string buffer "&quot;"
      | '\'' ->
          Buffer.add_string buffer "&#x27;"
      | c ->
          Buffer.add_char buffer c )
    s ;
  Buffer.contents buffer
OCaml

Innovation. Community. Security.