(ns ^{:go-imports []
      :doc "Reads and writes comma-separated values (CSV) files as defined in RFC 4180."}
  csv)

(defn csv-seq
  "Returns the csv records from rdr as a lazy sequence.
  rdr must be a string or implement io.Reader.
  opts may have the following keys:

  :comma - field delimiter (defaults to ',').
  Must be a valid char and must not be \\r, \\n,
  or the Unicode replacement character (0xFFFD).

  :comment - comment character (defaults to 0 meaning no comments).
  Lines beginning with the comment character without preceding whitespace are ignored.
  With leading whitespace the comment character becomes part of the
  field, even if trim-leading-space is true.
  comment must be a valid chat and must not be \\r, \\n,
  or the Unicode replacement character (0xFFFD).
  It must also not be equal to comma.

  :fields-per-record - number of expected fields per record.
  If fields-per-record is positive, csv-seq requires each record to
  have the given number of fields. If fields-per-record is 0 (default), csv-seq sets it to
  the number of fields in the first record, so that future records must
  have the same field count. If fields-per-record is negative, no check is
  made and records may have a variable number of fields.

  :lazy-quotes - if true, a quote may appear in an unquoted field and a
  non-doubled quote may appear in a quoted field. Default value is false.

  :trim-leading-space - if true, leading white space in a field is ignored.
  This is done even if the field delimiter, comma, is white space.
  Default value is false."
  {:added "1.0"
   :go {1 "csvSeqOpts(rdr, EmptyArrayMap())"
        2 "csvSeqOpts(rdr, opts)"}}
  ([^Object rdr])
  ([^Object rdr ^Map opts]))

(defn ^String write-string
  "Writes records to a string in CSV format and returns the string.
  data must be Seqable, each element of which must be Seqable as well.
  opts may have the following keys:

  :comma - field delimiter (defaults to ',')

  :use-crlf - if true, uses \\r\\n as the line terminator. Default value is false."
  {:added "1.0"
   :go {1 "writeString(data, EmptyArrayMap())"
        2 "writeString(data, opts)"}}
  ([^Seqable data])
  ([^Seqable data ^Map opts]))

(defn write
  "Writes records to a CSV encoded file.
  f must be io.Writer (for example, as returned by joker.os/create).
  data must be Seqable, each element of which must be Seqable as well.
  opts is as in joker.csv/write-string."
  {:added "1.0"
   :go {2 "write(f, data, EmptyArrayMap())"
        3 "write(f, data, opts)"}}
  ([^IOWriter f ^Seqable data])
  ([^IOWriter f ^Seqable data ^Map opts]))



