Simple CSV Library

Build status

This is a CSV (delimiter can be changed) reader with a focus on: 1. Simplicity 2. Robustness 3. Performance (to a lesser extent)

It follows RFC 4180, but allows for non-conformant files to be processed. In order to accomplish this, it makes the following assumptions:

  1. Commas on the end of a line results in a empty string for that column.
  2. Double quotes in a field that is not enclosed in double quotes are processed as a regular character and are included in the column string.
  3. Non-delimiter characters immediately following a quoted field are treated as part of the column data and are appended to the column string.
  4. An EOF in the middle of a quoted field is parsed as if the field was properly closed.
  5. There is no error for empty lines or varying number of columns per line.

Limitations

Usage

Add to your Cargo.toml:

[dependencies] simple_csv = "~0.0.7"

Simple CSV usage

```rust let teststring = "1,2,3\r\n4,5,6".tostring(); let bytes = teststring.intobytes(); let mut testcsvreader = bytes.as_slice();

let mut reader = SimpleCsvReader::new(testcsvreader);

asserteq!(reader.nextrow(), Ok(vec!["1".tostring(),"2".tostring(),"3".tostring()].asslice())); asserteq!(reader.nextrow(), Ok(vec!["4".tostring(),"5".tostring(),"6".tostring()].asslice())); assert!(reader.nextrow().iserr()); ```

Different Delimiter

```rust let teststring = "1|2|3\r\n4|5|6".tostring(); let bytes = teststring.intobytes(); let testcsvreader = bytes.as_slice();

let mut reader = SimpleCsvReader::withdelimiter(testcsv_reader,'|');

asserteq!(reader.nextrow(), Ok(vec!["1".tostring(),"2".tostring(),"3".tostring()].asslice())); asserteq!(reader.nextrow(), Ok(vec!["4".tostring(),"5".tostring(),"6".tostring()].asslice())); assert!(reader.nextrow().iserr()); ```

Using a iterator

```rust let teststring = "1|2|3\r\n4|5|6".tostring(); let bytes = teststring.intobytes(); let testcsvreader = bytes.as_slice();

let mut reader = SimpleCsvReader::withdelimiter(testcsv_reader,'|');

for row in reader { println!("{}",row); } ```

Different Text Enclosing Character

```rust let teststring = "1,#2#,3\r\n#4#,5,6".tostring(); let bytes = teststring.intobytes(); let testcsvreader = bytes.as_slice();

let mut reader = SimpleCsvReader::withcustomchars(testcsvreader, ',', '#', '\n');

asserteq!(reader.nextrow(), Ok(vec!["1".tostring(),"2".tostring(),"3".tostring()].asslice())); asserteq!(reader.nextrow(), Ok(vec!["4".tostring(),"5".tostring(),"6".tostring()].asslice())); assert!(reader.nextrow().iserr()); ```

To Do