preprocessor optimized to handle faster removal of spaces near newline
This commit is contained in:
parent
c5247aa887
commit
31e9a7e10c
|
@ -149,6 +149,30 @@ void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::str
|
||||||
result[ *it ] = Preprocessor::getcode( data, *it );
|
result[ *it ] = Preprocessor::getcode( data, *it );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Preprocessor::removeSpaceNearNL( const std::string &str )
|
||||||
|
{
|
||||||
|
std::string tmp;
|
||||||
|
int prev = -1;
|
||||||
|
for( unsigned int i = 0; i < str.size(); i++ )
|
||||||
|
{
|
||||||
|
if( str[i] == ' ' &&
|
||||||
|
( ( i > 0 && tmp[prev] == '\n' ) ||
|
||||||
|
( i+1 < str.size() && str[i+1] == '\n' )
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Ignore space that has new line in either side of it
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp.append( 1,str[i] );
|
||||||
|
prev++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
void Preprocessor::preprocess(std::istream &istr, const std::string &filename, std::string &processedFile, std::list<std::string> &resultConfigurations)
|
void Preprocessor::preprocess(std::istream &istr, const std::string &filename, std::string &processedFile, std::list<std::string> &resultConfigurations)
|
||||||
{
|
{
|
||||||
processedFile = read(istr, filename);
|
processedFile = read(istr, filename);
|
||||||
|
@ -160,21 +184,11 @@ void Preprocessor::preprocess(std::istream &istr, const std::string &filename, s
|
||||||
if ( !processedFile.empty() && processedFile[0] == ' ' )
|
if ( !processedFile.empty() && processedFile[0] == ' ' )
|
||||||
processedFile.erase( 0, processedFile.find_first_not_of(" ") );
|
processedFile.erase( 0, processedFile.find_first_not_of(" ") );
|
||||||
|
|
||||||
// TODO, this is very slow with very big files, make it faster
|
// Remove space characters that are after or before new line character
|
||||||
std::string::size_type loc = 0;
|
processedFile = removeSpaceNearNL( processedFile );
|
||||||
while ( (loc = processedFile.find("\n ", loc)) != std::string::npos )
|
|
||||||
processedFile.erase( 1 + loc, 1 );
|
|
||||||
|
|
||||||
// Remove all trailing spaces..
|
|
||||||
loc = 0;
|
|
||||||
while ( (loc = processedFile.find(" \n", loc)) != std::string::npos )
|
|
||||||
{
|
|
||||||
processedFile.erase( loc, 1 );
|
|
||||||
if ( loc > 0 )
|
|
||||||
--loc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Using the backslash at the end of a line..
|
// Using the backslash at the end of a line..
|
||||||
|
std::string::size_type loc = 0;
|
||||||
while ( (loc = processedFile.rfind("\\\n")) != std::string::npos )
|
while ( (loc = processedFile.rfind("\\\n")) != std::string::npos )
|
||||||
{
|
{
|
||||||
processedFile.erase(loc, 2);
|
processedFile.erase(loc, 2);
|
||||||
|
|
|
@ -63,6 +63,14 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove space that has new line character on left or right side of it.
|
||||||
|
*
|
||||||
|
* @param str The string to be converted
|
||||||
|
* @return The string where space characters have been removed.
|
||||||
|
*/
|
||||||
|
static std::string removeSpaceNearNL( const std::string &str );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all possible configurations. By looking at the ifdefs and ifndefs in filedata
|
* Get all possible configurations. By looking at the ifdefs and ifndefs in filedata
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue