From 200346548925a963d4aa4df1a1f3cbfd8494787a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 1 Apr 2011 21:23:11 +0200 Subject: [PATCH] Config: Fix some errors in the comment handling Signed-off-by: Uli Schlachter --- Config.cpp | 23 +++++++---------------- test/ConfigTest.cpp | 2 ++ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Config.cpp b/Config.cpp index c17e66b2..4bc12ce8 100644 --- a/Config.cpp +++ b/Config.cpp @@ -76,26 +76,17 @@ bool CConfig::Parse(CFile& file, CString& sErrorMsg) sLine.TrimLeft(); sLine.TrimRight("\r\n"); + if (bCommented || sLine.Left(2) == "/*") { + /* Does this comment end on the same line again? */ + bCommented = (sLine.Right(2) != "*/"); + + continue; + } + if ((sLine.empty()) || (sLine[0] == '#') || (sLine.Left(2) == "//")) { continue; } - if (sLine.Left(2) == "/*") { - if (sLine.Right(2) != "*/") { - bCommented = true; - } - - continue; - } - - if (bCommented) { - if (sLine.Right(2) == "*/") { - bCommented = false; - } - - continue; - } - if ((sLine.Left(1) == "<") && (sLine.Right(1) == ">")) { sLine.LeftChomp(); sLine.RightChomp(); diff --git a/test/ConfigTest.cpp b/test/ConfigTest.cpp index 8c5bb9fd..20ece0c0 100644 --- a/test/ConfigTest.cpp +++ b/test/ConfigTest.cpp @@ -150,6 +150,8 @@ int main() { TEST_SUCCESS("Foo = bar // baz\n// Bar = baz", "foo=bar // baz\n"), TEST_SUCCESS("Foo = bar /* baz */\n/*** Foo = baz ***/\n /**** asdsdfdf \n Some quite invalid stuff ***/\n", "foo=bar /* baz */\n"), TEST_ERROR("\n/* Just a comment\n", "Error on line 3: Comment not closed at end of file."), + TEST_SUCCESS("/* Foo\n/* Bar */", ""), + TEST_SUCCESS("/* Foo\n// */", ""), }; unsigned int i; unsigned int failed = 0;