blob: 8802c0ef82a659d3ab68519c55e70c559626796c (
plain)
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
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2012 *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
open Cdglobals
let norm_char_latin1 c = match Char.uppercase c with
| '\192'..'\198' -> 'A'
| '\199' -> 'C'
| '\200'..'\203' -> 'E'
| '\204'..'\207' -> 'I'
| '\209' -> 'N'
| '\210'..'\214' -> 'O'
| '\217'..'\220' -> 'U'
| '\221' -> 'Y'
| c -> c
let norm_char_utf8 c = Char.uppercase c
let norm_char c =
if !utf8 then norm_char_utf8 c else
if !latin1 then norm_char_latin1 c else
Char.uppercase c
let norm_string s =
let u = String.copy s in
for i = 0 to String.length s - 1 do
u.[i] <- norm_char s.[i]
done;
u
let compare_char c1 c2 = match norm_char c1, norm_char c2 with
| ('A'..'Z' as c1), ('A'..'Z' as c2) -> compare c1 c2
| 'A'..'Z', _ -> -1
| _, 'A'..'Z' -> 1
| '_', _ -> -1
| _, '_' -> 1
| c1, c2 -> compare c1 c2
let compare_string s1 s2 =
let n1 = String.length s1 in
let n2 = String.length s2 in
let rec cmp i =
if i == n1 || i == n2 then
n1 - n2
else
let c = compare_char s1.[i] s2.[i] in
if c == 0 then cmp (succ i) else c
in
cmp 0
|