with compat >= 4.02, use Format.pp_print_text directly

This commit is contained in:
Simon Cruanes 2018-02-05 08:56:01 -06:00
parent 27c768eebf
commit 3ab9cd58e1

View file

@ -46,35 +46,7 @@ let newline = Format.pp_force_newline
let substring out (s,i,len): unit =
string out (String.sub s i len)
let text out (s:string): unit =
let len = String.length s in
let i = ref 0 in
let search_ c =
try Some (String.index_from s !i c) with Not_found -> None
in
while !i < len do
let j_newline = search_ '\n' in
let j_space = search_ ' ' in
let on_newline j =
substring out (s, !i, j - !i);
newline out ();
i := j + 1
and on_space j =
substring out (s, !i, j - !i);
Format.pp_print_space out ();
i := j + 1
in
begin match j_newline, j_space with
| None, None ->
(* done *)
substring out (s, !i, len - !i);
i := len
| Some j, None -> on_newline j
| None, Some j -> on_space j
| Some j1, Some j2 ->
if j1<j2 then on_newline j1 else on_space j2
end
done
let text = Format.pp_print_text
(*$= & ~printer:(fun s->CCFormat.sprintf "%S" s)
"a\nb\nc" (sprintf_no_color "@[<v>%a@]%!" text "a b c")