StringType OnLiterals(SourceCode& sourceCode,char endChar) { StringType res; res += endChar; while (true) { if (sourceCode.AdvanceIfMatch('\\')) { res += '\\'; res += sourceCode.NextChar(); } else if (sourceCode.AdvanceIfMatch(endChar)) { res += endChar; return std::move(res); } else { auto c = sourceCode.NextChar(); if (c == InvalidCharacter) break; res += c; } } std::string exp; (exp += endChar) += " lost"; throw SyntaxError(exp.c_str()); }
StringType Filter(SourceCode& sourceCode) { StringType res; while (true) { if (sourceCode.AdvanceIfMatch('\"')) { res += OnLiterals(sourceCode,'\"'); } else if (sourceCode.AdvanceIfMatch('\'')) { res += OnLiterals(sourceCode,'\''); } else if (sourceCode.AdvanceIfMatch("/*"s)) { OnMultiLine(sourceCode); } else if (sourceCode.AdvanceIfMatch("//"s)) { OnSingleLine(sourceCode); } else { auto c = sourceCode.NextChar(); if (c == InvalidCharacter) break; res += c; } } return res; }