intellij-csv-validator icon indicating copy to clipboard operation
intellij-csv-validator copied to clipboard

[Suggestion]Quoting of cells

Open kdschlosser opened this issue 5 years ago • 3 comments

I know this is already done but it quotes all cells when editing form table view. I also know there have been suggestions made for how to handle the quoting of a cell but this suggestion may differ from those approaches

This suggestion is to apply the K.I.S.S. (Keep It Stupid Simple) model to it. Because there is no official specification for a csv file the K.I.S.S. mechanics being used are almost a must. If a user has set a cell delimiter to a comma then if a comma is in a cells data OR a newline character is in a cells data then the data MUST be wrapped in quotes. Otherwise it should not.

Another option is a setting box where the user can specify characters that would flag the cell as needing quotes. This would be in addition to the newline and the current used delimiter.

kdschlosser avatar May 13 '20 20:05 kdschlosser

@kdschlosser Thanks for the suggestion.

It sounds to me like you are describing the default behavior how it is right now. Enforcing quotes on all cells can be enabled/disabled in the settings.

Another option is a setting box where the user can specify characters that would flag the cell as needing quotes. This would be in addition to the newline and the current used delimiter.

What should this be good for? The wishes I heard so far are going in the direction of column- or "type"-based quoting.

SeeSharpSoft avatar May 15 '20 16:05 SeeSharpSoft

having a simple setting where a user could enter characters that would force the quoting of cells.

so as a default a cell would always get quoted if the cell delimiter or the newline character was found in the data of a cell. the setting would be a text entry field where a users puts any additional characters that would force the quoting of a cell.

so say I wanted to have a cell get quoted if there are question marks in it. you would add a question mark to the setting and any cell that has a question mark in it is going to get quoted.

I saw an issue for the quotes not showing up in the table view. I believe not showing them is the correct thing to do but for the people that want to see them then maybe adding a setting to turn them on or off. I would suggest that the quotes show up as a different color so they can be identified as being created by the plugin.

I do not know what the typical escaping routine is that is used for csv files so I will use XML as an example. If a cell has quotes in it's data then those quotes would have to be escaped before wrapping the cell in quotes. This is the only thing that would have to be escaped i believe.

having the setting where a user can enter additional characters that would trigger the quoting of a cell I think would cover any oddities that can arise due to the lack of an actual CSV specification. It would offer some flexibility for the user to be able to tailor the plugin to their needs when deciding of a cell needs to be quoted or not. This setting could be used as a column setting or as a global setting. however you see fit. you may decide to add some special flags in order to handle "type" based quoting. so in this field a user could enter {int} or {float} to enable quoting for those data types.

It's a simple approach that would offer the largest amount of customization. So if used on a global scale a user could enter {int}? and it would quote all cells that were integers and also all cells that have question marks in them. I think that would be easy enough to use and would cover all of the different scenarios a user may want.

Offering the setting as a global setting but also as a column setting would be nice to do. the column setting would populate from the global setting unless the column setting as been changed by the user. ultimately the column setting is the only one that you would use on the back end to handle the parsing of the cell data.

The trickiest bit is going to be how to make the setting persistent between loading of a file, I am not sure if CSV has the ability to have comment lines. If it does then the information can be stored in the actual CSV file. if not then you will have to make some kind of a config file that would store the settings. If the CSV file is apart of a project this settings file could be stashed in the .idea folder. and if the CSV file is not in a project maybe a popup letting the user know any changes to the settings specific to a CSV file are not going to persist between loads.

kdschlosser avatar May 16 '20 18:05 kdschlosser

Regarding: "Because there is no official specification for a csv file"... and " due to the lack of an actual CSV specification."

see RFC 4180

starunit avatar May 29 '21 15:05 starunit