Package: headache / 1.03-27

utf8_length Patch series | download
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
Author: Mehdi Dogguy <mehdi@debian.org>
Description: Correctly determine length of lines containing UTF8 characters

--- a/main.ml
+++ b/main.ml
@@ -103,7 +103,7 @@
   in
   let header_width =
     List.fold_left 
-      (fun w line -> max (String.length line) w)  
+      (fun w line -> max (UTF8.length line) w)  
       0
       header
   in
--- a/Makefile.in
+++ b/Makefile.in
@@ -10,6 +10,8 @@
 OCAMLYACC=@OCAMLYACC@
 OCAMLLEX=@OCAMLLEX@
 
+OCAMLC_FLAGS=-I +extlib extLib.cma
+
 # Installation directory
 INSTALLDIR=@INSTALLDIR@
 
@@ -51,10 +53,10 @@
 	$(OCAMLDEP) *.ml *.mli > Depend
 
 headache: $(CMO)
-	ocamlc -o $@ unix.cma str.cma $^
+	ocamlc -o $@ unix.cma str.cma -I +extlib extLib.cma $^
 
 mkconfig: $(MKCONFIG.CMO)
-	ocamlc -o $@ unix.cma str.cma $^
+	ocamlc -o $@ unix.cma str.cma -I +extlib extLib.cma $^
 
 config_builtin.ml: config_builtin mkconfig
 	./mkconfig
--- a/model.ml
+++ b/model.ml
@@ -65,7 +65,7 @@
 
 let arg_char args ?default name =
   let s = arg_string args ?default name in
-  if String.length s = 1 then s.[0]
+  if UTF8.length s = 1 then s.[0]
   else raise (Error (sprintf "parameter %s expects a character" name))
 
     
@@ -103,7 +103,7 @@
       output_string oc open_comment;
       output_string oc margin;
       output_string oc string;
-      output oc white 0 (max 0 (real_width - String.length string));
+      output oc white 0 (max 0 (real_width - UTF8.length string));
       output_string oc margin;
       output_string oc close_comment;
       output_char oc '\n'
@@ -150,7 +150,7 @@
 	while
           let s = input_line ic in
             not (Str.string_match regexp_end s
-                   (max 0 (String.length s - end_length)))
+                   (max 0 (UTF8.length s - end_length)))
         do () done;
 	""
       end