csvrow

Crates.iocsvrow
lib.rscsvrow
version0.2.1
sourcesrc
created_at2024-03-18 19:56:00.656512
updated_at2024-04-30 14:49:16.258425
descriptionFast and simple crate for taking a string slice and iterating over the fields in a manner that adheres to RFC-4180
homepagehttps://github.com/RetrospectionSoftware/csvrow/
repositoryhttps://github.com/RetrospectionSoftware/csvrow/
max_upload_size
id1178407
size13,136
(RetrospectionSoftware)

documentation

https://docs.rs/csvrow

README

csvrow

=== A small, fast utility library that allows you to wrap a string slice representing a line from a CSV file and iterate over its fields. Complies with RFC 4180 (CSV format) and UTF8.

Usage

Add csvrow to your Cargo.toml file directly, or alternatively type cargo add csvrow at a terminal prompt in your project root.

Example

Creating a CSV Row from a String slice and collecting the results into a Vec:

use CsvRow::*;

fn get_fields() {

    let row = "rust,is,awesome";
    let csv = CsvRow::new(row, ',', false);
    let vec_t: Vec<_> = csv.collect();
}

Fields wrapped in quotes, or containing escaped quotes (in accordance with RFC 4180) will by default be parsed and un-escaped. This behavior can be overridden with the 'literal' parameter of CsvRow::new

use CsvRow::*;

fn get_fields() {

    let row = r#""rust",is,"Awesome ""bring me the"" Sauce""#;
    let csv = CsvRow::new(row, ',', false);
    let vec_t: Vec<_> = csv.collect();

    // Will yield:
    // rust
    // is
    // Awesome "bring me the" Sauce

    let row = r#""rust",is,"Awesome ""bring me the"" Sauce""#;
    let csv = CsvRow::new(row, ',', true);
    let vec_t: Vec<_> = csv.collect();

    // Will yield:
    // "rust"
    // is
    // "Awesome ""bring me the"" Sauce"
}

License: Unlicense/MIT

Commit count: 7

cargo fmt