Looking for some C++ library (like boost::program_options) that is able to return line number of an INI file, where the given option or section was found.
Use cases:
I ask that library to find value "vvv" in a section "[SSS]". Library returns line number where "vvv" in section "[SSS]" is found, or -1. It gives me an ability to say "line 55: vvv must be < 256".
I iterate INI file for sections and validate their names. When some wild secsion is found, i tell: "line 55: section [Hahaha] is unknown".
update: i know about "INI is older than mammoth", but currently i have to port large windows project to cross-platform and cannot get rid of .ini files soon.
Once again, took the opportunity to play with Boost Spirit. This time I got to play with
line_pos_iterator
.Here is the fruit of my labour: https://gist.github.com/1425972
POSITIONINFO == 0
map<string, map<string, string> >
for the sections)When
POSITIONINFO == 1
output is
textnode_t
:This means that the resulting
map<textnode_t, map<textnode_t, textnode_t> >
is able to report exactly what (line,col) start and end points mark the individual text nodes. See test output for a demoComments (
#
,/* ... */
style) have been implementedWhitespace is 'tolerated'
name = value # use a comment to force inclusion of trailing whitespace alternative = escape\ with slash\
De-escaping of the
slashes
is left as an exerciseNOTE C++11 support is NOT required, but I used it to dump the result of the parse. I'm too lazy to write it with C++03 verbose iterator style. :)
All code, makefile, example.ini can be found here: https://gist.github.com/1425972
Code
Demo Input
Demo Output (POSITIONINFO == 0)
Demo Output (POSITIONINFO == 1)