Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim only unquoted fields #307

Open
HalfVoxel opened this issue Mar 16, 2023 · 0 comments
Open

Trim only unquoted fields #307

HalfVoxel opened this issue Mar 16, 2023 · 0 comments

Comments

@HalfVoxel
Copy link

What version of the csv crate are you using?

1.2.1

Briefly describe the question, bug or feature request.

There are currently options for trimming fields. However, if a file has explicitly quoted fields, this strongly indicates that exactly what is within the quotes should be considered the field value. It would be very useful to have an option to only trim unquoted fields.

Alternatively, a way to get info about if a field was quoted or not when it was parsed would perhaps be even more helpful. This would allow anyone to implement the feature ourselves.

Include a complete program demonstrating a problem.

fn main() {
    let text = "
Hello, World
Hello,\" This field starts with a space\"
";
    let mut rdr = csv::ReaderBuilder::new()
            .has_headers(false)
            .trim(csv::Trim::All)
            .from_reader(std::io::Cursor::new(&text));
    
    for result in rdr.records() {
        println!("{:?}", result.unwrap().iter().map(|r| r.to_string()).collect::<Vec<_>>());
    }
}

What is the observed behavior of the code above?

["Hello", "World"]
["Hello", "This field starts with a space"]

What is the expected or desired behavior of the code above?

["Hello", "World"]
["Hello", " This field starts with a space"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant