MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / peekNextText

Method peekNextText

other_src/astyle/src/ASFormatter.cpp:2444–2503  ·  view source on GitHub ↗

* get the next non-whitespace substring on following lines, bypassing all comments. * * @param the first line to check * @return the next non-whitespace substring. */

Source from the content-addressed store, hash-verified

2442 * @return the next non-whitespace substring.
2443 */
2444string ASFormatter::peekNextText(const string& firstLine, bool endOnEmptyLine /*false*/, bool shouldReset /*false*/) const
2445{
2446 bool isFirstLine = true;
2447 bool needReset = shouldReset;
2448 string nextLine_ = firstLine;
2449 size_t firstChar= string::npos;
2450
2451 // find the first non-blank text, bypassing all comments.
2452 bool isInComment_ = false;
2453 while (sourceIterator->hasMoreLines())
2454 {
2455 if (isFirstLine)
2456 isFirstLine = false;
2457 else
2458 {
2459 nextLine_ = sourceIterator->peekNextLine();
2460 needReset = true;
2461 }
2462
2463 firstChar = nextLine_.find_first_not_of(" \t");
2464 if (firstChar == string::npos)
2465 {
2466 if (endOnEmptyLine && !isInComment_)
2467 break;
2468 continue;
2469 }
2470
2471 if (nextLine_.compare(firstChar, 2, "/*") == 0)
2472 {
2473 firstChar += 2;
2474 isInComment_ = true;
2475 }
2476
2477 if (isInComment_)
2478 {
2479 firstChar = nextLine_.find("*/", firstChar);
2480 if (firstChar == string::npos)
2481 continue;
2482 firstChar += 2;
2483 isInComment_ = false;
2484 firstChar = nextLine_.find_first_not_of(" \t", firstChar);
2485 if (firstChar == string::npos)
2486 continue;
2487 }
2488
2489 if (nextLine_.compare(firstChar, 2, "//") == 0)
2490 continue;
2491
2492 // found the next text
2493 break;
2494 }
2495
2496 if (needReset)
2497 sourceIterator->peekReset();
2498 if (firstChar == string::npos)
2499 nextLine_ = "";
2500 else
2501 nextLine_ = nextLine_.substr(firstChar);

Callers

nothing calls this directly

Calls 4

peekNextLineMethod · 0.80
peekResetMethod · 0.80
hasMoreLinesMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected