Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/refmt/end_of_line.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ end

module Convert = struct
let lf_to_crlf =
let crlf = "\r\n" in
let rec loop sz =
match String.index sz '\n' with
| exception Not_found -> sz
| idx ->
let l = String.sub sz ~pos:0 ~len:idx ^ "\r\n" in
let buf = Bytes.create (idx + 2) in
Bytes.unsafe_blit_string ~src:sz ~src_pos:0 ~dst:buf ~dst_pos:0 ~len:idx;
Bytes.unsafe_blit_string
~src:crlf
~src_pos:0
~dst:buf
~dst_pos:idx
~len:2;
let l = Bytes.unsafe_to_string buf in
let length = String.length sz in
l ^ loop (String.sub sz ~pos:(idx + 1) ~len:(length - idx - 1))
in
Expand Down