preprocessor: handling the '\' in preprocessor code
This commit is contained in:
parent
ffa8e3d0b6
commit
b5e55859c4
|
@ -152,6 +152,17 @@ void preprocess(std::istream &istr, std::map<std::string, std::string> &result,
|
||||||
while ( codestr.find(" \n") != std::string::npos )
|
while ( codestr.find(" \n") != std::string::npos )
|
||||||
codestr.erase( codestr.find(" \n"), 1 );
|
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..
|
// Get all possible configurations..
|
||||||
std::list<std::string> cfgs = getcfgs( codestr );
|
std::list<std::string> cfgs = getcfgs( codestr );
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@ private:
|
||||||
TEST_CASE( include1 );
|
TEST_CASE( include1 );
|
||||||
|
|
||||||
TEST_CASE( if_cond1 );
|
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)
|
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));
|
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 )
|
REGISTER_TEST( TestPreprocessor )
|
||||||
|
|
Loading…
Reference in New Issue