diff --git a/preprocessor.cpp b/preprocessor.cpp index ce97d01a3..4892d9a78 100644 --- a/preprocessor.cpp +++ b/preprocessor.cpp @@ -152,6 +152,17 @@ void preprocess(std::istream &istr, std::map &result, while ( codestr.find(" \n") != std::string::npos ) codestr.erase( codestr.find(" \n"), 1 ); + // Using the backslash at the end of a line.. + while ( codestr.find("\\\n") != std::string::npos ) + { + std::string::size_type pos = codestr.rfind("\\\n"); + codestr.erase(pos,2); + if (pos > 0 && codestr[pos-1] != ' ') + codestr.insert(pos, " "); + if ( codestr.find("\n", pos) != std::string::npos) + codestr.insert( codestr.find("\n", pos), "\n" ); + } + // Get all possible configurations.. std::list cfgs = getcfgs( codestr ); diff --git a/testpreprocessor.cpp b/testpreprocessor.cpp index 22567d468..312a193bb 100644 --- a/testpreprocessor.cpp +++ b/testpreprocessor.cpp @@ -57,6 +57,8 @@ private: TEST_CASE( include1 ); TEST_CASE( if_cond1 ); + + TEST_CASE( multiline ); } bool cmpmaps(const std::map &m1, const std::map &m2) @@ -393,6 +395,24 @@ private: ASSERT_EQUALS( true, cmpmaps(actual, expected)); } + + void multiline() + { + const char filedata[] = "#define str \"abc\" \\\n" + " \"def\"\n"; + + std::map expected; + expected[""] = "#define str \"abc\" \"def\"\n\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + preprocess( istr, actual, "" ); + + // Compare results.. + ASSERT_EQUALS( true, cmpmaps(actual, expected)); + } + }; REGISTER_TEST( TestPreprocessor )