FasterXML / jackson-dataformats-text

Uber-project for (some) standard Jackson textual format backends: csv, properties, yaml (xml to be added in future)
Apache License 2.0
408 stars 149 forks source link

What is the correct way to escape the QuoteChar? #33

Closed cgendreau closed 7 years ago

cgendreau commented 7 years ago

I would like to escape the QuoteChar when it is doubled.

1, " the next word is ""quoted"""

The following snippet seems to give the expected result:

CsvSchema schema = CsvSchema.emptySchema()
.withQuoteChar('"')
//if we have a quote char, allow to escape it (see rfc4180)
.withEscapeChar('"')
...

But, the csv-compatibility section states :

If enabled, character immediately followed will be used as-is, except for a small set of "well-known" escapes (\n, \r, \t, \0)

cowtowncoder commented 7 years ago

I am not sure I follow the question: quote char is by default escaped by doubling it up. So shouldn't it work the way you want already?

cgendreau commented 7 years ago

Indeed, it works already.

I started from .withEscapeChar('\') to handle things like "1","{\"key\":\"value\"}" where the json escape char was included in the csv. I was confused about what to use in withEscapeChar after the file was fixed to have "1","{""key"":""value""}".

My bad

cowtowncoder commented 7 years ago

Ok. Just glad it works for you!