* Remove comments from string. Comment must start with a single @c commentChar * character and end on new line (i.e. '\n') character. * For example LLVM comment: * %a = add i32 0, 0 ; this part will be removed * @param str String from which to remove comments. * @param commentChar Character used to start the comment (e.g. ';'). * @return String without comments. */
| 1362 | * @return String without comments. |
| 1363 | */ |
| 1364 | std::string removeComments(const std::string& str, char commentChar) |
| 1365 | { |
| 1366 | std::string ret = str; |
| 1367 | bool ers = false; |
| 1368 | for (auto it = ret.begin(); it != ret.end(); ) |
| 1369 | { |
| 1370 | if (*it == commentChar) |
| 1371 | { |
| 1372 | it = ret.erase(it); |
| 1373 | ers = true; |
| 1374 | } |
| 1375 | else if (*it == '\n') |
| 1376 | { |
| 1377 | ers = false; |
| 1378 | ++it; |
| 1379 | } |
| 1380 | else if (ers) |
| 1381 | { |
| 1382 | it = ret.erase(it); |
| 1383 | } |
| 1384 | else |
| 1385 | { |
| 1386 | ++it; |
| 1387 | } |
| 1388 | } |
| 1389 | return ret; |
| 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * Search for version stored in input string |