metayeti/mINI

trailing comments on all lines

reFX-Mike opened this issue · 4 comments

Would it be possible to add support for trailing comments on key/value lines? It would be nice to leave a comment here and there for the end users (or myself) of my program. Maybe a relatively crude method would suffice? Store everything after the value as a comment, no matter how much whitespace, etc.?

key = value ; This is the background color

While writing, simply append the stored string back to the value.

Pretty please.

Hey. Yeah, actually what you get on your side is just that entire string - "value ; This is the background color". So the absolute easiest way to deal with this is just to take that value out manually. Something like string.split(';')[0].trim() (the C++ equivalent) would get you "value". You could put that into a function and just call it like value = parseInlineComment(ini["section"]["key"]). That's the crudest but simplest solution, but obviously if you don't mind digging into the library code you can just make that modification on the library-side, if you for some reason wanted to generalize it.

The reason the library doesn't parse those as comments is because values are allowed to contain ; and I didn't want to complicate the API needlessly for that. I think I envisioned people would just do what I described above. I'm not sure I'll add support for that anytime soon though, sorry. Hope that helps!

But then those comments would be lost. Let's say I use "end-of-line" comments for documentation purposes, load the settings file, the user makes a change, I change the ini file, and now that comment is lost forever.

Allowing semicolons in values would be possible by escaping them during write.

Yeah, you'd have to basically write them back manually as well. I didn't think about that. Still though, I don't think it's a worthy complication. In my opinion, it's more readable if those comments go above the key/value pair anyway. But I understand your point too. Maybe in some future point I'll consider it, if it doesn't complicate things too much. Thanks for bringing this to my attention anyway and sorry to disappoint. :-)

Thanks. I will fork this and make my own modifications then.