(index ("csv-record?" 0) ("list->csv-record" 168) ("csv-record->list" 330) ("csv-parser" 502) ("csv-parser" 949) ("make-parser" 1384) ("make-format" 2740))
(def (sig (procedure "(csv-record? X) => BOOL" (id csv-record?))) (p "Returns " (tt "#t") " if the given object is a " (tt "csv-record") ", " (tt "#f") " otherwise."))
(def (sig (procedure "(list->csv-record LIST) => CSV-RECORD" (id list->csv-record))) (p "Takes in a list of values and creates a " (tt "csv-record") " object."))
(def (sig (procedure "(csv-record->list CSV-RECORD) => LIST" (id csv-record->list))) (p "Returns the list of values contained in the given " (tt "csv-record") " object."))
(def (sig (procedure "(csv-parser [DELIMITER]) => PARSER" (id csv-parser))) (p "When invoked, " (tt "csv-parser") " returns a parser procedure takes in a list of characters and returns a list of the form:") (pre " ((<#csv-record (FIELD1 FIELD2 ...)>) (<#csv-record ... >))") (p "where " (tt "FIELD") " represents the field values in a record.") (p "Optional arguments " (tt "DELIMITER") " is the field delimiter character, if other than comma."))
(def (sig (procedure "(csv-parser [DELIMITER]) => PARSER" (id csv-parser))) (p "When invoked, " (tt "csv-parser") " returns a parser procedure takes in a string and returns a list of the form:") (pre " ((<#csv-record (FIELD1 FIELD2 ...)>) (<#csv-record ... >))") (p "where " (tt "FIELD") " represents the field values in a record.") (p "Optional arguments " (tt "DELIMITER") " is the field delimiter character, if other than comma."))
(def (sig (procedure "(make-parser CSV-INSTANCE) => (LAMBDA [DELIMITER]) => PARSER" (id make-parser))) (p "Once applied to an instance of the " (tt "<CSV>") " typeclass, " (tt "make-parser") " returns a constructor for the CSV parsing procedure. Optional argument " (tt "DELIMITER") " specifies the field delimiter (comma by default). " (tt "DELIMITER") " can be a character, or an SRFI-14 character set. The returned procedure takes in an input stream and returns a list of the form:") (pre " ((<#csv-record (FIELD1 FIELD2 ...)>) (<#csv-record ... >))") (p "where " (tt "FIELD") " represents the field values in a record.") (p "The following example illustrates the creation of an instance of " (tt "<CSV>") " specialized for character lists.") (highlight scheme "(require-extension typeclass input-classes abnf csv)\n\n(define char-list-<Input>\n  (make-<Input> null? car cdr))\n\n(define char-list-<Token>\n  (Input->Token char-list-<Input>))\n\n(define char-list-<CharLex>\n  (Token->CharLex char-list-<Token>))\n\n(define char-list-<CoreABNF>\n  (CharLex->CoreABNF char-list-<CharLex>))\n\n(define char-list-<CSV>\n  (CoreABNF->CSV char-list-<CoreABNF> ))\n\n(define parse-csv ((make-parser char-list-<CSV>) #\\|))\n\n(parse-csv (string->list \"a|b|c\"))\n\n(map csv-record->list (parse-csv (string->list \"a|b|c\")))\n\n ==> ((\"a\" \"b\" \"c\"))"))
(def (sig (procedure "(make-format [DELIMITER]) => FORMAT-CELL * FORMAT-RECORD * FORMAT-CSV" (id make-format))) (p "Returns procedures for outputting individual field values, CSV records, and lists of CSV records, where each list is printed on a separate line.") (p "Procedure " (tt "FORMAT-CELL") " takes in a value, obtains its string representation via " (tt "format") ", and surrounds the string with quotes, if it contains characters that need to be escaped (such as quote characters, the delimiter character, or newlines).") (p "Procedure " (tt "FORMAT-RECORD") " takes in a record of type " (tt "csv-record") " and returns its string representation, based on the strings produced by " (tt "FORMAT-CELL") " and the delimiter character.") (p "Procedure " (tt "FORMAT-CSV") " takes in a list of " (tt "csv-record") " objects and produces a string representation using " (tt "FORMAT-RECORD") ".") (p "Example:") (highlight scheme "(use csv)\n\n(define-values (fmt-cell fmt-record fmt-csv) (make-format \";\"))\n\n(fmt-cell \"hello\") => \"hello\"\n\n;; This is quoted because it contains delimiter-characters\n(fmt-cell \"one;two;three\") => \"\\\"one;two;three\\\"\"\n\n;; This is quoted because it contains quotes, which are then doubled for escaping\n(fmt-cell \"say \\\"hi\\\"\") => \"\\\"say \\\"\\\"hi\\\"\\\"\\\"\"\n\n;; Converts one line at a time (useful when converting data in a streaming manner)\n(fmt-record (list->csv-record '(\"hi there\" \"let's say \\\"hello world\\\" again\" \"until we are bored\")))\n=> \"hi there;\\\"let's say \\\"\\\"hello world\\\"\\\" again\\\";until we are bored\"\n\n;; And an example of how to quickly convert a list of lists \n;; to a CSV string containing the entire CSV file\n(fmt-csv (map list->csv-record\n              '((\"one\" \"two\")\n                (\"and another \\\"line\\\"\" \"of csv stuff\"))))\n=> \"one;two\\r\\n\\\"and another \\\"\\\"line\\\"\\\"\\\";of csv stuff\\r\\n\""))
