diff --git a/src/core/opamStd.ml b/src/core/opamStd.ml index 9b31a42b8f9..013db09e45f 100644 --- a/src/core/opamStd.ml +++ b/src/core/opamStd.ml @@ -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)