MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / parse

Method parse

Source/Utils/ini.hpp:265–332  ·  view source on GitHub ↗

Functions

Source from the content-addressed store, hash-verified

263
264 ///Functions
265 void parse(std::istream& file)
266 {
267 fini_string_t line;
268 bool first = true;
269 fini_sstream_t out;
270 while (std::getline(file, line))
271 {
272 if (first)
273 {
274 first = false;
275 if (line[0] == 0xEF) //Allows handling of UTF-16/32 documents
276 {
277 line.erase(0, 3);
278 return;
279 }
280 }
281 if (!line.empty())
282 {
283 auto len = line.length();
284 if (len > 0 && !((len >= 2 && (line[0] == '/' && line[1] == '/')) || (len >= 1 && line[0] == '#'))) //Ignore comment and empty lines
285 {
286 if (line[0] == ';')
287 continue;
288
289 // section
290 if (line[0] == '[')
291 {
292 // without section brackets
293 auto ssection = line.substr(1, line.find(']') - 1);
294 out << ssection;
295
296 // "convert" to section_t
297 section_t section;
298 out >> section;
299
300 current = new keys_t;
301 sections[section] = current;
302 }
303 // key
304 else
305 {
306 key_t key;
307 value_t value;
308 fini_string_t skey = line.substr(0, line.find('='));
309 fini_string_t svalue = line.substr(line.find('=') + 1, line.size());
310 if (!(skey.empty() || svalue.empty())) {
311 skey = skey.substr(skey.find_first_not_of(' '), skey.length());
312
313 // "convert" value
314 out << skey;
315 out >> key;
316 out.clear();
317 out.str(fini_string_t());
318
319 // "convert" value
320 out << svalue;
321 out >> value;
322

Callers

nothing calls this directly

Calls 8

value_tEnum · 0.85
parseFunction · 0.85
eraseMethod · 0.80
findMethod · 0.80
closeMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected