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

question about escaping #50

Open
ghost opened this issue Apr 5, 2022 · 0 comments
Open

question about escaping #50

ghost opened this issue Apr 5, 2022 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Apr 5, 2022

Question

With the default config, how can I escape commas and line returns within a field in order to ensure the resulting CSV is readable?

Additional Context

I'm hacking together an app with Swift and Xcode and I'm a complete novice. To provide the app with some basic data I have provided it with csv files, which are parsed with CodableCSV. Many thanks for the package!

Using basic data it's working fine. I have tried not to fiddle with the configuration. Delimiters are commas and end of line is "\r".

However, for one of my tables I need now to expand one of the fields to include sentences or even paragraphs of text, which contain commas and newlines. Initially I understood from the documentation that the way to do this is to enclose the whole field in double quotes ("..."). That crashed the app and so did escaping the individual offending characters with double quotes (",) or with a backslash (,).

Many thanks for any pointers!

Example extract of table:

id,title,introduction
reg,Regular Models,"The good news for learners of Spanish..."
irr_i,Essentials I,
irr_ii,Essentials II,

Error message:

CodableCSV/Reader.swift:75:` Fatal error: 'try!' expression unexpectedly raised an error: [CSVReader] Invalid input
	Reason: The targeted field parsed successfully. However, the character right after it was not a field nor row delimiter.
	Help: If your CSV is CRLF, change the row delimiter to "\r\n" or add a trim strategy for "\r".
	User info: Row index: 1, Field: The good news for learners of `Spanish...

System

  • OS: macOS 12.3
  • CodableCSV: 0.6.7
  • Xcode 13
@ghost ghost added the question Further information is requested label Apr 5, 2022
@ghost ghost assigned dehesa Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant