gsv

Types

Option for using “\n = LF = Unix” or “\r\n = CRLF = Windows” line endings. Use with the from_lists function when writing to a csv string.

pub type LineEnding {
  Windows
  Unix
}

Constructors

  • Windows
  • Unix

Functions

pub fn from_dicts(
  input: List(Dict(String, String)),
  separator separator: String,
  line_ending line_ending: LineEnding,
) -> String

Takes a list of dicts and writes it to a csv string. Will automatically escape strings that contain double quotes or line endings with double quotes (in csv, double quotes get escaped by doing a double doublequote) The string he"llo\n becomes "he""llo\n"

pub fn from_lists(
  input: List(List(String)),
  separator separator: String,
  line_ending line_ending: LineEnding,
) -> String

Takes a list of lists of strings and writes it to a csv string. Will automatically escape strings that contain double quotes or line endings with double quotes (in csv, double quotes get escaped by doing a double doublequote) The string he"llo\n becomes "he""llo\n"

pub fn to_dicts(
  input: String,
) -> Result(List(Dict(String, String)), String)

Parses a csv string to a list of dicts. Automatically handles Windows and Unix line endings. Returns a string error msg if the string is not valid csv. Unquoted strings are trimmed, while quoted strings have leading and trailing whitespace preserved. Whitespace only or empty strings are not valid headers and will be ignored. Whitespace only or empty strings are not considered “present” in the csv row and are not inserted into the row dict.

pub fn to_lists(
  input: String,
) -> Result(List(List(String)), String)

Parses a csv string to a list of lists of strings. Automatically handles Windows and Unix line endings. Returns a string error msg if the string is not valid csv. Unquoted strings are trimmed, while quoted strings have leading and trailing whitespace preserved.

Search Document