Menu

#24 Add alwaysQuote preference

2.1.0
closed
None
5
2013-04-24
2012-12-21
No

To make Super CSV quote all fields (regardless of whether they contain embedded commas, quotes or newlines) you have to create your own writer (as shown on this StackOverflow question).

We should add a CsvPreference ('alwaysQuote'?) that does this.

Discussion

  • James Bassett

    James Bassett - 2013-01-04

    In addition, it might be worth considering how to do this for individual columns (which Kasper is keen on). It should be trivial to do it globally (for all columns), but not so easy per column (you can't just do it in a cell processor as the quotes will be escaped!).

     
  • Kasper B. Graversen

    well, we could have a bool pr column which determines if there is a need for quoting. then a cell processor can easily be written which tells that there is no need for additional quoting. similarly for the numberparsers. maybe the introduction of said flags will even slightly speed up the writing process .

     
  • James Bassett

    James Bassett - 2013-03-01

    Okay, I've implemented this.

    You can now supply a QuoteMode. Quotes are still applied if the column contains special characters (comma, quote or newline), but you can enable them if you want them using AlwaysQuoteMode (always quotes), ColumnQuoteMode (always quotes particular columns, using a boolean array), or a custom mode.

    I've also allowed for a custom CsvEncoder (the default encoder uses the supplied QuoteMode), so users can write their own encoding if they want (you could avoid escaping altogether if you really want). The default encoder is pretty powerful though, as it keeps track of the line numbers (including embedded newlines in CSV data) which can be very handy.

    [r275] and [r277]

     

    Related

    Commit: [r275]
    Commit: [r277]

  • James Bassett

    James Bassett - 2013-03-01
    • status: open --> pending
     
  • James Bassett

    James Bassett - 2013-04-24
    • Status: pending --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.