MCPcopy Create free account
hub / github.com/KDE/kdevelop / peekNextText

Method peekNextText

plugins/astyle/3rdparty/libastyle/ASFormatter.cpp:3837–3896  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3835 * @return the next non-whitespace substring.
3836 */
3837string ASFormatter::peekNextText(const string& firstLine,
3838 bool endOnEmptyLine /*false*/,
3839 shared_ptr<ASPeekStream> streamArg /*nullptr*/) const
3840{
3841 assert(sourceIterator->getPeekStart() == 0 || streamArg != nullptr); // Borland may need != 0
3842 bool isFirstLine = true;
3843 string nextLine_ = firstLine;
3844 size_t firstChar = string::npos;
3845 shared_ptr<ASPeekStream> stream = streamArg;
3846 if (stream == nullptr) // Borland may need == 0
3847 stream = make_shared<ASPeekStream>(sourceIterator);
3848
3849 // find the first non-blank text, bypassing all comments.
3850 bool isInComment_ = false;
3851 while (stream->hasMoreLines() || isFirstLine)
3852 {
3853 if (isFirstLine)
3854 isFirstLine = false;
3855 else
3856 nextLine_ = stream->peekNextLine();
3857
3858 firstChar = nextLine_.find_first_not_of(" \t");
3859 if (firstChar == string::npos)
3860 {
3861 if (endOnEmptyLine && !isInComment_)
3862 break;
3863 continue;
3864 }
3865
3866 if (nextLine_.compare(firstChar, 2, "/*") == 0)
3867 {
3868 firstChar += 2;
3869 isInComment_ = true;
3870 }
3871
3872 if (isInComment_)
3873 {
3874 firstChar = nextLine_.find("*/", firstChar);
3875 if (firstChar == string::npos)
3876 continue;
3877 firstChar += 2;
3878 isInComment_ = false;
3879 firstChar = nextLine_.find_first_not_of(" \t", firstChar);
3880 if (firstChar == string::npos)
3881 continue;
3882 }
3883
3884 if (nextLine_.compare(firstChar, 2, "//") == 0)
3885 continue;
3886
3887 // found the next text
3888 break;
3889 }
3890
3891 if (firstChar == string::npos)
3892 nextLine_ = "";
3893 else
3894 nextLine_ = nextLine_.substr(firstChar);

Callers

nothing calls this directly

Calls 6

getPeekStartMethod · 0.80
substrMethod · 0.80
hasMoreLinesMethod · 0.45
peekNextLineMethod · 0.45
compareMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected