@@ -138,7 +138,7 @@ static bool startsWith(const std::string &str, const std::string &s)
138138
139139static bool endsWith (const std::string &s, const std::string &e)
140140{
141- return (s.size () >= e.size () && s. compare (s. size () - e. size (), e. size (), e) == 0 );
141+ return (s.size () >= e.size ()) && std::equal (e. rbegin (), e. rend (), s. rbegin () );
142142}
143143
144144static bool sameline (const simplecpp::Token *tok1, const simplecpp::Token *tok2)
@@ -568,7 +568,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
568568
569569 TokenString currentToken;
570570
571- if (cback () && cback ()->location .line == location.line && cback ()->previous && cback ()->previous ->op == ' #' && (lastLine () == " # error" || lastLine () == " # warning" )) {
571+ if (cback () && cback ()->location .line == location.line && cback ()->previous && cback ()->previous ->op == ' #' && isLastLinePreprocessor () && (lastLine () == " # error" || lastLine () == " # warning" )) {
572572 char prev = ' ' ;
573573 while (istr.good () && (prev == ' \\ ' || (ch != ' \r ' && ch != ' \n ' ))) {
574574 currentToken += ch;
@@ -629,7 +629,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
629629 currentToken.erase (pos,2 );
630630 ++multiline;
631631 }
632- if (multiline || startsWith ( lastLine ( 10 ), " # " )) {
632+ if (multiline || isLastLinePreprocessor ( )) {
633633 pos = 0 ;
634634 while ((pos = currentToken.find (' \n ' ,pos)) != std::string::npos) {
635635 currentToken.erase (pos,1 );
@@ -710,7 +710,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
710710 else
711711 back ()->setstr (prefix + s);
712712
713- if (newlines > 0 && lastLine ().compare (0 ,9 ," # define " ) == 0 ) {
713+ if (newlines > 0 && isLastLinePreprocessor () && lastLine ().compare (0 ,9 ," # define " ) == 0 ) {
714714 multiline += newlines;
715715 location.adjust (s);
716716 } else {
@@ -723,7 +723,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
723723 currentToken += ch;
724724 }
725725
726- if (currentToken == " < " && lastLine () == " # include" ) {
726+ if (* currentToken. begin () == ' < ' && isLastLinePreprocessor () && lastLine () == " # include" ) {
727727 currentToken = readUntil (istr, location, ' <' , ' >' , outputList, bom);
728728 if (currentToken.size () < 2U )
729729 return ;
0 commit comments