1 (***********************************************************************)
5 (* Kim Nguyen, LRI UMR8623 *)
6 (* Université Paris-Sud & CNRS *)
8 (* Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
9 (* Recherche Scientifique. All rights reserved. This file is *)
10 (* distributed under the terms of the GNU Lesser General Public *)
11 (* License, with the special exception on linking described in file *)
14 (***********************************************************************)
17 Time-stamp: <Last modified on 2013-03-09 10:41:21 CET by Kim Nguyen>
22 exception InvalidUtf8Codepoint of int
24 let subscripts = "₀₁₂₃₄₅₆₇₈₉"
25 let superscripts = "⁰¹²³⁴⁵⁶⁷⁸⁹"
28 let code = Char.code c in
29 if code <= 0x7f then 1
30 else if 0xc2 <= code && code <= 0xdf then 2
31 else if 0xe0 <= code && code <= 0xef then 3
32 else if 0xf0 <= code && code <= 0xf4 then 4
33 else raise (InvalidUtf8Codepoint code)
36 let next_char s i len =
37 let n = i + char_length s.[i] in
38 if n >= len then -1 else n
41 let len = String.length s in
44 else loop (next_char s i len) (acc+1)
51 let len = String.length s in
52 let rec loop j count =
53 if count == i then String.sub s j (char_length s.[j])
54 else loop (next_char s j len) (count+1)
59 let format_number digits i =
60 let s = string_of_int i in
61 let len = String.length s in
62 let buf = Buffer.create (len*4) in
63 for i = 0 to len - 1 do
64 let d = Char.code s.[i] - Char.code '0' in
65 Buffer.add_string buf (get_char digits d)
70 let len = str_len s in
74 loop (i+1) ((get_char s i) :: acc)
79 let explode s = List.rev (rev_explode s)
81 let combine_all comp s =
82 let l = rev_explode s in
83 String.concat "" (List.fold_left (fun acc e -> comp::e::acc) [] l)
86 let subscript = format_number subscripts
87 let superscript = format_number superscripts
103 let double_right_arrow = "⇒"
104 let combining_overbar = "\204\133"
105 let combining_underbar = "\204\178"
106 let combining_stroke = "\204\182"
107 let combining_vertical_line = "\226\131\146"
110 let overline s = combine_all combining_overbar s
111 let underline s = combine_all combining_underbar s
112 let strike s = combine_all combining_stroke s
114 let padding i = String.make i ' '
115 let line i = String.make i '_'
121 pp_print_string fmt (f s)
123 let pp_overline = ppf overline
124 let pp_underline = ppf underline
125 let pp_strike = ppf strike
126 let pp_subscript = ppf subscript
127 let pp_superscript = ppf superscript
128 let dummy_printer _ () = ()
130 let pp_print_list ?(sep=dummy_printer) printer fmt l =
133 | [ e ] -> printer fmt e
134 | e :: es -> printer fmt e; List.iter
137 fprintf fmt "%a" printer x) es
139 let pp_print_array ?(sep=dummy_printer) printer fmt a =
140 pp_print_list ~sep:sep printer fmt (Array.to_list a)
142 let print_list ?(sep=" ") printer fmt l =
143 let sep_printer fmt () =
144 pp_print_string fmt sep
146 pp_print_list ~sep:sep_printer printer fmt l
148 let print_array ?(sep=" ") printer fmt a =
149 print_list ~sep:sep printer fmt (Array.to_list a)