Skip to content
This repository
tree: 834bf9f877
Fetching contributors…

Cannot retrieve contributors at this time

file 83 lines (70 sloc) 3.195 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(* CF mli *)

include Char

(* TODO: benchmark against c1 = c2 or ... *)
(** égalité sans casse *)
let equal_insensitive c1 c2 =
  lowercase c1 = lowercase c2

(** compare sans casse *)
let compare_insensitive c1 c2 =
  compare (lowercase c1) (lowercase c2)

(**
Mathieu Tue Oct 19 13:33:05 CEST 2010
What does it do there ??
Who does use this ?
My opinion is that it should not be defined there.
*)
(* largeur (approximative) d'un caractère *)
let width =
  (* open Graphics;;
#load "graphics.cma";;
open_graph "";;
set_font "-microsoft-trebuchet ms-*-*-*-*-*-*-*-*-*-*-*-*";;
let f i = fst (text_size (String.make 1 (char_of_int i)));;
let a = Array.init 256 f;;
Array.fold_left (+) 0 a;; *)
  let char_width =
    [|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;
      0; 0; 0; 0; 0; 0; 0; 7; 8; 9; 13; 13; 16; 16; 7; 8; 8; 9; 13; 8; 8; 8; 9;
      13; 13; 13; 13; 13; 13; 13; 13; 13; 13; 8; 8; 13; 13; 13; 9; 17; 13; 13;
      13; 15; 13; 13; 16; 16; 7; 11; 15; 12; 17; 15; 16; 13; 17; 15; 12; 16; 15;
      16; 21; 15; 16; 13; 11; 11; 11; 13; 13; 13; 13; 13; 11; 13; 12; 9; 12; 13;
      8; 9; 12; 7; 19; 13; 13; 13; 13; 11; 11; 9; 12; 12; 17; 13; 13; 12; 11; 13;
      11; 13; 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; 0; 0; 0; 0; 0; 0; 0; 0; 7; 8; 13; 13; 13; 13; 13; 13; 13; 16; 9;
      12; 13; 8; 16; 13; 13; 13; 11; 11; 13; 12; 13; 8; 13; 11; 9; 12; 20; 20;
      20; 8; 13; 13; 13; 13; 13; 13; 21; 13; 13; 13; 13; 13; 7; 7; 7; 7; 15; 15;
      16; 16; 16; 16; 16; 13; 16; 15; 15; 15; 15; 16; 13; 13; 13; 13; 13; 13; 13;
      13; 20; 11; 12; 12; 12; 12; 8; 8; 8; 8; 13; 13; 13; 13; 13; 13; 13; 13; 13;
      12; 12; 12; 12; 13; 13; 13|] in
  fun c -> char_width.(int_of_char c)

let is_digit c = c >= '0' && c <= '9'
let is_hex c = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')
let is_lower c = c >= 'a' && c <= 'z'
let is_upper c = c >= 'A' && c <= 'Z'

let is_alpha c = is_digit c or is_lower c or is_upper c

let pred a = (Obj.magic (pred (Obj.magic a)) : char)
let succ a = (Obj.magic (succ (Obj.magic a)) : char)

let is_space = function
  | ' ' | '\t' | '\r' | '\n' -> true
  | _ -> false

(** valeur entière d'un chiffre hexa *)
let hexa_value c =
  int_of_char c - (
    if c >= '0' && c <= '9' then 48 (*int_of_char '0'*)
    else if c >= 'A' && c <= 'F' then 55 (* int_of_char 'A' - 10 *)
    else if c >= 'a' && c <= 'f' then 87 (* int_of_char 'a' - 10 *)
    else assert false
  )
Something went wrong with that request. Please try again.