compuphase / minIni

A small and portable INI file library with read/write support
http://www.compuphase.com/minini.htm
Other
382 stars 114 forks source link

Iterator API #8

Open tomeksowi opened 7 years ago

tomeksowi commented 7 years ago

Currently the only pull parsing APIs are ini_get* which are suboptimal as they open, re-parse, and close the file on each invocation. ini_browse is efficient but offers only push-style API which requires caller to define a function and often an artificial context struct. Adding iterator-based API would give both -- efficiency and pull parsing which results in more natural caller code.

Proposed outline of the API:

struct ini_iter;
int ini_iteropen(struct ini_iter* it, const char* filename);
int ini_iternext(struct ini_iter* it);
int ini_iterclose(struct ini_iter* it);

Example of use:

struct ini_iter it;
for (ini_iteropen(&it, "test.ini"); ini_iternext(&it); ) {
    printf("[%s] %s = %s\n", it.section, it.key, it.value);
}
ini_iterclose(&it);

I already looked at minini code and know how it could be implemented. I can take the effort but wanted to know first if such a design is welcome at all.