preprocessor: fixed handling of tabs and spaces

This commit is contained in:
Daniel Marjamäki 2008-12-03 18:35:58 +00:00
parent 17cb374ce2
commit d3a2a32a58
2 changed files with 15 additions and 6 deletions

View File

@ -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 )

View File

@ -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";