src/lib/INIReader.cpp
branchv_0
changeset 19 967f73af64a4
parent 16 db994a2ddffa
child 20 9187f0439ca9
equal deleted inserted replaced
18:a8c1381ef103 19:967f73af64a4
   194 
   194 
   195 		bool inSection = false;
   195 		bool inSection = false;
   196 
   196 
   197 		while (input.good()) { // TODO: condition
   197 		while (input.good()) { // TODO: condition
   198 			{
   198 			{
       
   199 				INIContentHandler::WhitespaceEvent event;
       
   200 				event.lineNumber = lineNumber;
   199 				std::string whitespace = readAllWhitespace();
   201 				std::string whitespace = readAllWhitespace();
   200 				if (whitespace.size()) {
   202 				if (whitespace.size()) {
   201 					INIContentHandler::WhitespaceEvent event;
       
   202 					event.lineNumber = lineNumber;
       
   203 					event.eventNumber = ++eventNumber;
   203 					event.eventNumber = ++eventNumber;
   204 					event.whitespace = whitespace;
   204 					event.whitespace = whitespace;
   205 					for (INIContentHandler* handler : handlers) handler->whitespace(event);
   205 					for (INIContentHandler* handler : handlers) handler->whitespace(event);
   206 				}
   206 				}
   207 			}
   207 			}
   214 			if (ch == std::istream::traits_type::eof()) {
   214 			if (ch == std::istream::traits_type::eof()) {
   215 				break;
   215 				break;
   216 			} else if (ch == '[') {
   216 			} else if (ch == '[') {
   217 				if (inSection) for (INIContentHandler* handler : handlers) handler->endSection();
   217 				if (inSection) for (INIContentHandler* handler : handlers) handler->endSection();
   218 				inSection = true;
   218 				inSection = true;
   219 				get();
       
   220 				readAllWhitespace();
       
   221 				INIContentHandler::SectionStartEvent event;
   219 				INIContentHandler::SectionStartEvent event;
   222 				event.lineNumber = lineNumber;
   220 				event.lineNumber = lineNumber;
   223 				event.eventNumber = ++eventNumber;
   221 				event.eventNumber = ++eventNumber;
       
   222 				get();
       
   223 				readAllWhitespace();
   224 				event.name = readTokenAndEatTerminator(']', &quote, &found);
   224 				event.name = readTokenAndEatTerminator(']', &quote, &found);
   225 
   225 
   226 				readSpacesAndTabs();
   226 				readSpacesAndTabs();
   227 				if (allowSectionTags && peek() == '[') {
   227 				if (allowSectionTags && peek() == '[') {
   228 					get();
   228 					get();
   241 					throw std::logic_error(std::string("unexpected content after the section: '") + event.name + "'");
   241 					throw std::logic_error(std::string("unexpected content after the section: '") + event.name + "'");
   242 				}
   242 				}
   243 
   243 
   244 				for (INIContentHandler* handler : handlers) handler->startSection(event);
   244 				for (INIContentHandler* handler : handlers) handler->startSection(event);
   245 			} else if (isComment(ch)) {
   245 			} else if (isComment(ch)) {
   246 				get();
       
   247 				readSpacesAndTabs();
       
   248 				INIContentHandler::CommentEvent event;
   246 				INIContentHandler::CommentEvent event;
   249 				event.lineNumber = lineNumber;
   247 				event.lineNumber = lineNumber;
   250 				event.eventNumber = ++eventNumber;
   248 				event.eventNumber = ++eventNumber;
       
   249 				get();
       
   250 				readSpacesAndTabs();
   251 				event.comment = readUntil('\n', &found);
   251 				event.comment = readUntil('\n', &found);
   252 				for (INIContentHandler* handler : handlers) handler->comment(event);
   252 				for (INIContentHandler* handler : handlers) handler->comment(event);
   253 			} else {
   253 			} else {
       
   254 				INIContentHandler::EntryEvent event;
       
   255 				event.lineNumber = lineNumber;
       
   256 				event.eventNumber = ++eventNumber;
       
   257 
   254 				std::string fullKey = readToken('=', &quote, &found);
   258 				std::string fullKey = readToken('=', &quote, &found);
   255 				if (!found) throw std::logic_error(std::string("missing = after key: '") + fullKey + "'");
   259 				if (!found) throw std::logic_error(std::string("missing = after key: '") + fullKey + "'");
   256 				if (!quote) fullKey = trim(fullKey);
   260 				if (!quote) fullKey = trim(fullKey);
   257 				readSpacesAndTabs();
   261 				readSpacesAndTabs();
   258 
   262 
   263 				}
   267 				}
   264 
   268 
   265 				std::string value = readToken('\n', &quote, &found);
   269 				std::string value = readToken('\n', &quote, &found);
   266 				if (!quote) value = trim(value);
   270 				if (!quote) value = trim(value);
   267 
   271 
   268 				INIContentHandler::EntryEvent event;
       
   269 				event.lineNumber = lineNumber;
       
   270 				event.eventNumber = ++eventNumber;
       
   271 				event.key = fullKey;
   272 				event.key = fullKey;
   272 				event.fullKey = fullKey;
   273 				event.fullKey = fullKey;
   273 				event.value = value;
   274 				event.value = value;
   274 
   275 
   275 				if (allowSubKeys) {
   276 				if (allowSubKeys) {