preprocessor: fixed handling of tabs and spaces
This commit is contained in:
parent
17cb374ce2
commit
d3a2a32a58
|
@ -146,17 +146,26 @@ void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::str
|
|||
|
||||
std::string codestr( code.str() );
|
||||
|
||||
// Replace all tabs with spaces..
|
||||
std::string::size_type loc = 0;
|
||||
while ( (loc = codestr.find("\t", loc)) != std::string::npos )
|
||||
codestr[loc] = ' ';
|
||||
|
||||
// Remove all indentation..
|
||||
if ( !codestr.empty() && codestr[0] == ' ' )
|
||||
codestr.erase( 0, codestr.find_first_not_of(" ") );
|
||||
std::string::size_type loc = 0;
|
||||
loc = 0;
|
||||
while ( (loc = codestr.find("\n ", loc)) != std::string::npos )
|
||||
codestr.erase( 1 + loc, 1 );
|
||||
|
||||
// Remove all trailing spaces..
|
||||
loc = 0;
|
||||
while ( (loc = codestr.find(" \n", loc)) != std::string::npos )
|
||||
{
|
||||
codestr.erase( loc, 1 );
|
||||
if ( loc > 0 )
|
||||
--loc;
|
||||
}
|
||||
|
||||
// Using the backslash at the end of a line..
|
||||
while ( (loc = codestr.rfind("\\\n")) != std::string::npos )
|
||||
|
|
|
@ -152,9 +152,9 @@ private:
|
|||
{
|
||||
const char filedata[] = "#ifdef WIN32 \n"
|
||||
" abcdef\n"
|
||||
"#else\n"
|
||||
"#else \n"
|
||||
" qwerty\n"
|
||||
"#endif\n";
|
||||
"#endif \n";
|
||||
|
||||
// Expected result..
|
||||
std::map<std::string, std::string> expected;
|
||||
|
@ -224,7 +224,7 @@ private:
|
|||
{
|
||||
const char filedata[] = "#ifdef ABC\n"
|
||||
"A\n"
|
||||
"#endif\n"
|
||||
"#endif\t\n"
|
||||
"#ifdef ABC\n"
|
||||
"A\n"
|
||||
"#endif\n";
|
||||
|
|
Loading…
Reference in New Issue