-
Notifications
You must be signed in to change notification settings - Fork 212
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
Automatically escape fields that contain the comment character #283
Conversation
Currently, if data is written with QuoteStyle::Necessary, and the first field of a row happens to contain a comment character, the row will be ignored as a comment when later reading it back in. This change adds a `comment` property to Writer, and automatically quotes fields that have the provided comment character in them, so they round-trip correctly.
@BurntSushi Gentle ping - I know you're busy. Any thoughts on if this is something you would be interested in including? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense as when using the Reader interface with a comment character you'd loose lines that start with the comment if it's not escaped.
I'm not sure API-wise if it's better to have uniformity with the reader here and re-use comment, or just straight up allow setting characters to the requires_quotes array directly (as we're not writing comments!), but that's a matter of taste for @BurntSushi to decide and something that has less overhead than QuoteStyle::Always
definitely looks sane to me.
It'd be great if you could spare a minute to give some feedback and/or merge this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! There are a couple things that need to be addressed before merging.
Is the latest commit what you had in mind? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Previously, if data is written with QuoteStyle::Necessary, and the first field of a row happens to contain a comment character, the row will be ignored as a comment when later reading it back in. This change adds a `comment` property to Writer, and automatically quotes fields that have the provided comment character in them, so they round-trip correctly. Closes #283
Previously, if data is written with QuoteStyle::Necessary, and the first field of a row happens to contain a comment character, the row will be ignored as a comment when later reading it back in. This change adds a `comment` property to Writer, and automatically quotes fields that have the provided comment character in them, so they round-trip correctly. Closes #283
This PR is in |
Thank you very much! |
Currently, if data is written with QuoteStyle::Necessary, and the first
field of a row happens to start with a comment character, the row will be
ignored as a comment when later reading it back in.
This change adds a
comment
property to Writer, and automaticallyquotes fields that have the provided comment character in them, so they
round-trip correctly.