package core_extended

  1. Overview
  2. Docs
Extra components that are not as closely vetted or as stable as Core

Install

Dune Dependency

Authors

Maintainers

Sources

core_extended-v0.14.0.tar.gz
sha256=a7bf672f617891b10e405f1edb1c2ddc1db9e5b3169bd278bbb75b84d57d23ce
md5=00eb9b3ed6b0b02f74a2cf01e4d5827f

doc/src/core_extended.delimited_kernel/write_intf.ml.html

Source file write_intf.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
open Core_kernel

module type To_string = sig
  type t

  val to_string : t -> string
end

module type M = sig
  (** Used to describe a way to create a single row of a CSV
      from a given type.
  *)
  type -'a t

  val empty : 'a t
  val column : ('a -> string) -> header:string -> 'a t
  val column_m : (module To_string with type t = 'a) -> header:string -> 'a t

  (** [default] is printed in place of [None], and if not supplied
      is the empty string.
  *)
  val column_m_opt
    :  ?default:string
    -> (module To_string with type t = 'a)
    -> header:string
    -> 'a option t

  val of_list : 'a t list -> 'a t
  val append : 'a t -> 'a t -> 'a t
  val contra_map : 'b t -> f:('a -> 'b) -> 'a t
  val map_headers : 'a t -> f:(string -> string) -> 'a t
  val headers : 'a t -> string list
  val to_columns : 'a t -> 'a -> string list

  (** Open for prefix operators useful for using with Fields.to_list.

      e.g.
      {[
        let csv =
          Delimited.Write.Fields_O.(
            Fields.to_list
              ~a_string:!!Fn.id
              ~a_date:!!Date.to_string
              ~mv:!>Long_short.csv)
          |> Delimited.Write.of_list
      ]}
  *)
  module Fields_O : sig
    (** Create a single column from a field of a record. *)
    val ( !! ) : ('a -> string) -> ('b, 'a) Field.t -> 'b t

    (** Nest a builder in a field of a record.

        Column headers will be prefixed with the name of the field.
    *)
    val ( !> ) : 'a t -> ('b, 'a) Field.t -> 'b t
  end

  module O : sig
    val ( <<| ) : 'b t -> ('a -> 'b) -> 'a t
    val ( <> ) : 'a t -> 'a t -> 'a t
  end

  module By_row : sig
    type row = string list

    (** Prints a valid csv file to a given channel.
        The [line_breaks] arg can be used to override the default line ending
        of "\r\n" (DOS/Windows line endings).
        Example ~line_breaks:`Unix to get *nix line endings
    *)
    val output_lines
      :  ?quote:char
      -> ?sep:char
      -> ?line_breaks:[ `Windows | `Unix ]
      -> Out_channel.t
      -> row list
      -> unit

    (** Convert one CSV line to a string. *)
    val line_to_string : ?quote:char -> ?sep:char -> row -> string
  end

  module Expert : sig
    (** Escape the a CSV field if need be.*)
    val maybe_escape_field : ?quote:char -> ?sep:char -> string -> string

    (** Escape a CSV (even if doesn't have any characters that require escaping).*)
    val escape_field : ?quote:char -> string -> string

    (** Get the escaped length of one quoted field (without the quotes). Returns
        None if the field doesn't need to be escaped. *)
    val quote_len : quote:char -> sep:char -> pos:int -> len:int -> string -> int option

    (** Copy and escapes the content of a field over from one string to
        another. This does not put the quotes in.*)
    val quote_blit
      :  quote:char
      -> src:string
      -> dst:Bytes.t
      -> src_pos:int
      -> dst_pos:int
      -> len:int
      -> int
  end
end
OCaml

Innovation. Community. Security.