package reason

  1. Overview
  2. Docs
Reason: Syntax & Toolchain for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

reason-3.15.0.tbz
sha256=ec3d2025f4391f0d2b88d2053e627a85aa1addd9c51320e9e72c690e05fb66a6
sha512=2bc7681a0e7649f619a8e93e961690531f697fadb1ae5d3f2c5913b0fce6995780394f2ce5b3e1920902ca7a2f4e188f62696f58f20ae3dd81c3658528bd0a33

doc/src/reason.refmt-lib/eol_convert.ml.html

Source file eol_convert.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
open Eol_detect

let lf_to_crlf s =
  let rec loop sz =
    match String.index sz '\n' with
    | exception Not_found -> sz
    | idx ->
      let l = String.sub sz 0 idx ^ "\r\n" in
      let length = String.length sz in
      l ^ loop (String.sub sz (idx + 1) (length - idx - 1))
  in
  loop s

let get_formatter output_channel eol =
  let f = Format.formatter_of_out_channel output_channel in
  let out_functions = Format.pp_get_formatter_out_functions f () in
  let out_string s p n =
    match eol with
    | LF -> out_functions.out_string s p n
    | CRLF ->
      let str = String.sub s p n in
      let str = lf_to_crlf str in
      out_functions.out_string str 0 (String.length str)
  in
  let new_functions = { out_functions with out_string } in
  Format.pp_set_formatter_out_functions f new_functions;
  f
OCaml

Innovation. Community. Security.