bool Parser::skipComments() { if (*it != '/') // if not char '/' then it can't be a comment return true; ++it; if (*it == '/') // single line comment return nextValidLine() && nextValidChar(); if (*it == '*') { // multi line comment while (true) { int dist = distance(currentLine.begin(), it); size_t pos = currentLine.find("*/", dist); if (pos != string::npos) { it = currentLine.begin() + pos + 2; // + 2 for num of chars in "*/" return nextValidChar(); } if (!nextValidLine()) return false; } } --it; // if not a comment, go back to previous valid char return true; }
int findString(QTextStream *stream, QString target) { QString line; while (nextValidLine(stream, &line)) { if (!(QString::compare(line, target))) { return 1; } } return 0; }
bool Parser::nextValidChar() { while (isspace(*it) || it == currentLine.end()) { // skipping whitespaces if (*it == '\n' || it == currentLine.end()) { // if so, read next valid line if (!nextValidLine()) return false; } else { it++; } } if (!skipComments()) // skip comments here return false; return true; }