preprocessor: handling the '\' in preprocessor code

This commit is contained in:
Daniel Marjamäki 2008-11-02 17:04:46 +00:00
parent ffa8e3d0b6
commit b5e55859c4
2 changed files with 31 additions and 0 deletions

View File

@ -152,6 +152,17 @@ void preprocess(std::istream &istr, std::map<std::string, std::string> &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<std::string> cfgs = getcfgs( codestr );

View File

@ -57,6 +57,8 @@ private:
TEST_CASE( include1 );
TEST_CASE( if_cond1 );
TEST_CASE( multiline );
}
bool cmpmaps(const std::map<std::string, std::string> &m1, const std::map<std::string, std::string> &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<std::string, std::string> expected;
expected[""] = "#define str \"abc\" \"def\"\n\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
preprocess( istr, actual, "" );
// Compare results..
ASSERT_EQUALS( true, cmpmaps(actual, expected));
}
};
REGISTER_TEST( TestPreprocessor )