MCPcopy Create free account
hub / github.com/MonaSolutions/MonaServer / ReadIniFile

Method ReadIniFile

MonaBase/sources/Util.cpp:391–450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389
390
391bool Util::ReadIniFile(const string& path,Parameters& parameters) {
392 ifstream ifile(path, ios::in | ios::binary | ios::ate);
393 if (!ifile.good())
394 return false;
395 UInt32 size = (UInt32)ifile.tellg();
396 if (size == 0)
397 return true;
398 vector<char> buffer(size);
399 ifile.seekg(0);
400 ifile.read(buffer.data(), size);
401 UInt32 i(0);
402 string section;
403 while (i<size) {
404 char c(0);
405 do {
406 c = buffer[i++];
407 } while (isspace(c) && i < size);
408 if (i==size)
409 return true;
410 if (c == ';') {
411 while (c != '\n' && i<size)
412 c = buffer[i++];
413 } else if (c == '[') {
414 section.clear();
415 do {
416 c = buffer[i++];
417 } while (isblank(c) && i < size);
418 do {
419 section += c;
420 if (i == size)
421 break;
422 c = buffer[i++];
423 } while (c != ']' && c != '\n');
424 } else {
425 string key;
426 while (i < size && c != '=' && c != '\n') {
427 key += c;
428 c = buffer[i++];
429 }
430 string value;
431 if (i < size && c == '=') {
432 do {
433 c = buffer[i++];
434 } while (isblank(c) && i < size);
435 do {
436 value += c;
437 if (i == size)
438 break;
439 c = buffer[i++];
440 } while (c != '\n');
441 }
442 string fullKey(String::Trim(section, String::TRIM_RIGHT));
443 if (!fullKey.empty())
444 fullKey += '.';
445 fullKey.append(String::Trim(key, String::TRIM_RIGHT));
446 parameters.setString(fullKey, String::Trim(value, String::TRIM_RIGHT));
447 }
448 }

Callers

nothing calls this directly

Calls 8

isspaceFunction · 0.85
isblankFunction · 0.85
readMethod · 0.45
dataMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45
appendMethod · 0.45
setStringMethod · 0.45

Tested by

no test coverage detected