Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 84 lines (70 sloc) 3.195 kB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (* CF mli *)
19
20 include Char
21
22 (* TODO: benchmark against c1 = c2 or ... *)
23 (** égalité sans casse *)
24 let equal_insensitive c1 c2 =
25 lowercase c1 = lowercase c2
26
27 (** compare sans casse *)
28 let compare_insensitive c1 c2 =
29 compare (lowercase c1) (lowercase c2)
30
31 (**
32 Mathieu Tue Oct 19 13:33:05 CEST 2010
33 What does it do there ??
34 Who does use this ?
35 My opinion is that it should not be defined there.
36 *)
37 (* largeur (approximative) d'un caractère *)
38 let width =
39 (* open Graphics;;
40 #load "graphics.cma";;
41 open_graph "";;
42 set_font "-microsoft-trebuchet ms-*-*-*-*-*-*-*-*-*-*-*-*";;
43 let f i = fst (text_size (String.make 1 (char_of_int i)));;
44 let a = Array.init 256 f;;
45 Array.fold_left (+) 0 a;; *)
46 let char_width =
47 [|0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
48 0; 0; 0; 0; 0; 0; 0; 7; 8; 9; 13; 13; 16; 16; 7; 8; 8; 9; 13; 8; 8; 8; 9;
49 13; 13; 13; 13; 13; 13; 13; 13; 13; 13; 8; 8; 13; 13; 13; 9; 17; 13; 13;
50 13; 15; 13; 13; 16; 16; 7; 11; 15; 12; 17; 15; 16; 13; 17; 15; 12; 16; 15;
51 16; 21; 15; 16; 13; 11; 11; 11; 13; 13; 13; 13; 13; 11; 13; 12; 9; 12; 13;
52 8; 9; 12; 7; 19; 13; 13; 13; 13; 11; 11; 9; 12; 12; 17; 13; 13; 12; 11; 13;
53 11; 13; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
54 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 7; 8; 13; 13; 13; 13; 13; 13; 13; 16; 9;
55 12; 13; 8; 16; 13; 13; 13; 11; 11; 13; 12; 13; 8; 13; 11; 9; 12; 20; 20;
56 20; 8; 13; 13; 13; 13; 13; 13; 21; 13; 13; 13; 13; 13; 7; 7; 7; 7; 15; 15;
57 16; 16; 16; 16; 16; 13; 16; 15; 15; 15; 15; 16; 13; 13; 13; 13; 13; 13; 13;
58 13; 20; 11; 12; 12; 12; 12; 8; 8; 8; 8; 13; 13; 13; 13; 13; 13; 13; 13; 13;
59 12; 12; 12; 12; 13; 13; 13|] in
60 fun c -> char_width.(int_of_char c)
61
62 let is_digit c = c >= '0' && c <= '9'
63 let is_hex c = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')
64 let is_lower c = c >= 'a' && c <= 'z'
65 let is_upper c = c >= 'A' && c <= 'Z'
66
67 let is_alpha c = is_digit c or is_lower c or is_upper c
68
69 let pred a = (Obj.magic (pred (Obj.magic a)) : char)
70 let succ a = (Obj.magic (succ (Obj.magic a)) : char)
71
72 let is_space = function
73 | ' ' | '\t' | '\r' | '\n' -> true
74 | _ -> false
75
76 (** valeur entière d'un chiffre hexa *)
77 let hexa_value c =
78 int_of_char c - (
79 if c >= '0' && c <= '9' then 48 (*int_of_char '0'*)
80 else if c >= 'A' && c <= 'F' then 55 (* int_of_char 'A' - 10 *)
81 else if c >= 'a' && c <= 'f' then 87 (* int_of_char 'a' - 10 *)
82 else assert false
83 )
Something went wrong with that request. Please try again.