|
1 | | -/* |
| 1 | +/* |
2 | 2 | * c++check - c/c++ syntax checking |
3 | 3 | * Copyright (C) 2007 Daniel Marjamäki |
4 | 4 | * |
@@ -143,24 +143,25 @@ void preprocess(std::istream &istr, std::map<std::string, std::string> &result, |
143 | 143 | std::string codestr( code.str() ); |
144 | 144 |
|
145 | 145 | // Remove all indentation.. |
146 | | - while ( ! codestr.empty() && codestr[0] == ' ' ) |
147 | | - codestr.erase(0, 1); |
148 | | - while ( codestr.find("\n ") != std::string::npos ) |
149 | | - codestr.erase( 1 + codestr.find("\n "), 1 ); |
| 146 | + if ( !codestr.empty() && codestr[0] == ' ' ) |
| 147 | + codestr.erase( 0, codestr.find_first_not_of(" ") ); |
| 148 | + std::string::size_type loc = 0; |
| 149 | + while ( (loc = codestr.find("\n ", loc)) != std::string::npos ) |
| 150 | + codestr.erase( 1 + loc, 1 ); |
150 | 151 |
|
151 | 152 | // Remove all trailing spaces.. |
152 | | - while ( codestr.find(" \n") != std::string::npos ) |
153 | | - codestr.erase( codestr.find(" \n"), 1 ); |
| 153 | + loc = 0; |
| 154 | + while ( (loc = codestr.find(" \n", loc)) != std::string::npos ) |
| 155 | + codestr.erase( loc, 1 ); |
154 | 156 |
|
155 | 157 | // Using the backslash at the end of a line.. |
156 | | - while ( codestr.find("\\\n") != std::string::npos ) |
| 158 | + while ( (loc = codestr.rfind("\\\n")) != std::string::npos ) |
157 | 159 | { |
158 | | - std::string::size_type pos = codestr.rfind("\\\n"); |
159 | | - codestr.erase(pos,2); |
160 | | - if (pos > 0 && codestr[pos-1] != ' ') |
161 | | - codestr.insert(pos, " "); |
162 | | - if ( codestr.find("\n", pos) != std::string::npos) |
163 | | - codestr.insert( codestr.find("\n", pos), "\n" ); |
| 160 | + codestr.erase(loc, 2); |
| 161 | + if (loc > 0 && codestr[loc-1] != ' ') |
| 162 | + codestr.insert(loc, " "); |
| 163 | + if ( (loc = codestr.find("\n", loc)) != std::string::npos) |
| 164 | + codestr.insert( loc, "\n" ); |
164 | 165 | } |
165 | 166 |
|
166 | 167 | // Get all possible configurations.. |
@@ -282,6 +283,7 @@ static std::string getcode(const std::string &filedata, std::string cfg) |
282 | 283 | { |
283 | 284 | std::ostringstream ret; |
284 | 285 |
|
| 286 | + bool match = true; |
285 | 287 | std::list<bool> matching_ifdef; |
286 | 288 | std::list<bool> matched_ifdef; |
287 | 289 |
|
@@ -334,9 +336,12 @@ static std::string getcode(const std::string &filedata, std::string cfg) |
334 | 336 | matching_ifdef.pop_back(); |
335 | 337 | } |
336 | 338 |
|
337 | | - bool match = true; |
338 | | - for ( std::list<bool>::const_iterator it = matching_ifdef.begin(); it != matching_ifdef.end(); ++it ) |
339 | | - match &= bool(*it); |
| 339 | + if ( !line.empty() && line[0] == '#' ) |
| 340 | + { |
| 341 | + match = true; |
| 342 | + for ( std::list<bool>::const_iterator it = matching_ifdef.begin(); it != matching_ifdef.end(); ++it ) |
| 343 | + match &= bool(*it); |
| 344 | + } |
340 | 345 | if ( ! match ) |
341 | 346 | line = ""; |
342 | 347 |
|
|
0 commit comments