From b5e55859c4729fbff7daa9dbf22436bdda2f215f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 2 Nov 2008 17:04:46 +0000 Subject: [PATCH] preprocessor: handling the '\' in preprocessor code --- preprocessor.cpp | 11 +++++++++++ testpreprocessor.cpp | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) 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 )