stevemarple / IniFile

Arduino library to parse ini files.
GNU Lesser General Public License v2.1
87 stars 45 forks source link

Feature request w/ source #24

Closed ROSW6341 closed 5 years ago

ROSW6341 commented 5 years ago

The current library version does not support comments at the end of a line containing ini information. FOO = FooInfo # default value <= this causes problems A minor change to IniFile::removeTrailingWhiteSpace() will allow for that.

void IniFile::removeTrailingWhiteSpace(char str) { if (str == nullptr) return; char cp; if ((cp = strchr(str, '#')) || (cp = strchr(str, ';'))) // check for comment characters here cp = '\0'; // if found, shorten the string cp = str + strlen(str) - 1; while (cp >= str && isspace(cp)) *cp-- = '\0'; } This does exclude the comment characters from being within the ini information. If you have comments or wish to discuss this further my email address is: billk@rosw.com

stevemarple commented 5 years ago

This feature request has been made before (https://github.com/stevemarple/IniFile/issues/20) and was rejected for the reasons you have already identified. The functionality to insert any character into a value is more important that the positioning of comments.

ROSW6341 commented 5 years ago

I understand though now others can use the code I supplied to implement the feature if they are willing to give up being able to use the comment characters within the data fields. Your point is well taken and I'm still pondering which way I'll go. BTW - thanks for a very useful library. I've used a similar one on several of my professional projects. https://github.com/benhoyt/inih

stevemarple commented 5 years ago

It would be a breaking change with no workaround, unlike the position of where you write comments. It seems Microsoft's own .ini file format also requires comments to start at the beginning of a line: https://en.wikipedia.org/wiki/INI_file#Comments

ROSW6341 commented 5 years ago

Fair enough. For my part I'm adding a #define at the beginning of the .h file along with an explanation indicating the pros & cons of the two choices. That way I can switch either way at some time in the future.

ROSW6341 commented 5 years ago

Modified my version to be optional (#define in .h file). When enabled only ';' is accepted as the trailing comment character and only if it appears in or after the Value field. In the Section and/or Key fields it is treated the same as all other characters.