tags 620379 + patch
thanks
On 01/04/11 17:05, Ralf Treinen wrote:
Package: headache
Version: 1.03-18
Severity: normal
yes I know that this is a general problem with missing UTF8 support in
OCaml, but it is still ugly: The right end of frames is not correctly
aligned when the text contains multibyte UTF8 characters.
I was also annoyed by the same issue. I've pushed a (tentative) fix to
the Git repository. (I attach the patch here for reference only). I've
used extlib's UTF8.length function to correctly determine length of
strings. I'd appreciate testing and any feedback. I didn't change all
String.length invocations though, only for lines' content. The idea is
that it is quite unlikely to use a non-ascii character for comment
delimiters.
Kind regards,
--
Mehdi
--- 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
@@ -51,10 +51,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