rickyah / ini-parser

Read/Write an INI file the easy way!
MIT License
971 stars 241 forks source link

Proposal: Allow supression of empty lines before Section #121

Open glatzert opened 7 years ago

glatzert commented 7 years ago

Allow the programmer to set something like "NewLineBeforeNextSection" in the Parser.Configuration. Some INI Readers don't like the empty lines there

rickyah commented 7 years ago

I don't really understand the issue. You mean that blank lines before a section confuses an INI reader? Which reader, do you have an example?

glatzert commented 7 years ago

I have a Blackbox-Software which will accept an INI file in a specific location. Whatever that parser inside the (proprietary) software is - it will stop processing files upon the first empty line. Yes, I know that parser sucks, no I cannot do anything about it.

But if I just load and write a file without modifications, the ini-parser (yours), which does a pretty good job, will not result in the same file, since \r\n will be added before Sections (or probably at the end of sections). So I use a MemoryStream to write the Ini-Data, write that to an string, make replace operations in the string (\r\n\r\n --> \r\n) and finally write the string to the hdd. And thus I proposed a setting.

rickyah commented 7 years ago

I'm planning a rewrite of the parser so it is easy to tackle this kind of things, and more (comments in the same line) but it will take a little bit of time

glatzert commented 7 years ago

Nice 👍 If you are up-for-grabs, I'd possibly able to spare some time into the Parser as well (since it is a valuable tool for me, that'd be more than fair :))

csnewman commented 6 years ago

It would also be nice to be able to disable the new line before comments on key-value pairs as well. https://github.com/rickyah/ini-parser/blob/260b764ea7ed0039eadb90d383e40b76287bb0ea/src/IniFileParser/Model/Formatting/IniDataFormatter.cs#L63