Skip to content

Commit

Permalink
Fix visual_length_substring
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Dec 13, 2017
1 parent e7743f8 commit 16e9393
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/core/opamStd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -799,20 +799,20 @@ module OpamFormat = struct
let visual_length_substring s ofs len =
let rec aux acc i =
if i >= len then acc
else match s.[i] with
| '\xc2'..'\xdf' -> aux (acc + (min 1 (len - i))) (i + 2)
| '\xe0'..'\xef' -> aux (acc + (min 2 (len - i))) (i + 3)
| '\xf0'..'\xf4' -> aux (acc + (min 3 (len - i))) (i + 4)
else match s.[ofs + i] with
| '\xc2'..'\xdf' -> aux (acc - min 1 (len - i)) (i + 2)
| '\xe0'..'\xef' -> aux (acc - min 2 (len - i)) (i + 3)
| '\xf0'..'\xf4' -> aux (acc - min 3 (len - i)) (i + 4)
| '\027' ->
(try
let j = String.index_from s (i+1) 'm' in
if j > ofs + len then acc + len - i else
aux (acc + j - i + 1) (j + 1)
let j = String.index_from s (ofs+i+1) 'm' - ofs in
if j > len then acc - (len - i) else
aux (acc - (j - i + 1)) (j + 1)
with Not_found | Invalid_argument _ ->
acc + len - i)
acc - (len - i))
| _ -> aux acc (i + 1)
in
len - aux 0 ofs
aux len 0

let visual_length s = visual_length_substring s 0 (String.length s)

Expand Down

0 comments on commit 16e9393

Please sign in to comment.