File: unescape.mll

package info (click to toggle)
ocaml-odoc 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,008 kB
  • sloc: ml: 60,567; javascript: 2,572; sh: 566; makefile: 31
file content (24 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(* The goal of this lexer is to remove html encoding from strings, so that
   they display nicely on the command-line. The only encodings included are the
   one actually used. Because this executable is mainly used for testing, this
   is fine. *)
rule buffer b = parse
| "&" { Buffer.add_char b '&'; buffer b lexbuf } 
| "&lt;" { Buffer.add_char b '<'; buffer b lexbuf } 
| "&gt;" { Buffer.add_char b '>'; buffer b lexbuf } 
| "&gt" { Buffer.add_char b '>'; buffer b lexbuf } 
| "&gt;" { Buffer.add_char b '>'; buffer b lexbuf } 
| "&quot;" { Buffer.add_char b '>'; buffer b lexbuf } 
| "&#x27;" { Buffer.add_char b '\''; buffer b lexbuf } 
| "&#45" { Buffer.add_char b '-'; buffer b lexbuf } 

| eof { () }
| _ { Buffer.add_string b (Lexing.lexeme lexbuf) ; buffer b lexbuf }

{
let string str =
  let lexbuf = Lexing.from_string str in
  let b = Buffer.create (String.length str) in
  buffer b lexbuf ;
  Buffer.contents b
}