Fix the istream INI reader to work with the latest ini parser version
MODIFY
src/inireader.cpp
src/inireader.cpp
@@ -45,9 +45,19 @@ INIReader::INIReader(const string& filename)
INIReader::INIReader(std::istream& filestream)
{
- std::ifstream filestream(filename, std::ios::ios_base::in);
- _error = ini_parse(filestream, ValueHandler, this);
- filestream.close();
+ _error = ini_parse_stream([](char* str, int num, void* stream) {
+ std::istream* s = reinterpret_cast<std::istream*>(stream);
+ if (num > 0) {
+ s->read(str, num - 1);
+ std::streamsize bytes_read = s->gcount();
+ if (bytes_read > 0) {
+ str[s->gcount()] = '\0';
+ return str;
+ }
+ }
+
+ return (char*)NULL;
+ }, &filestream, ValueHandler, this);
}
int INIReader::ParseError() const

MODIFY
src/inireader.h
src/inireader.h
@@ -43,10 +43,10 @@ public:
// Construct INIReader and parse given filename. See ini.h for more info
// about the parsing.
INIReader(const std::string& filename);
- /**
- * Construct INIReader and parse given filename. See ini.h for more info
- * about the parsing.
- */
+
+ // Construct INIReader and parse given stream. See ini.h for more info
+ // about the parsing.
+ // Custom function for liblcf.
INIReader(std::istream& filestream);
// Return the result of ini_parse(), i.e., 0 on success, line number of

Fix the istream INI reader to work with the latest ini parser version