@@ -412,9 +412,9 @@ std::string clangimport::AstNode::getSpelling() const
412412 return " " ;
413413 }
414414 const std::string &str = mExtTokens [typeIndex - 1 ];
415- if (str. compare ( 0 , 4 , " col:" ) == 0 )
415+ if (startsWith (str, " col:" ))
416416 return " " ;
417- if (str. compare ( 0 , 8 , " <invalid" ) == 0 )
417+ if (startsWith (str, " <invalid" ))
418418 return " " ;
419419 if (nodeType == RecordDecl && str == " struct" )
420420 return " " ;
@@ -499,9 +499,9 @@ void clangimport::AstNode::dumpAst(int num, int indent) const
499499void clangimport::AstNode::setLocations (TokenList *tokenList, int file, int line, int col)
500500{
501501 for (const std::string &ext: mExtTokens ) {
502- if (ext. compare ( 0 , 5 , " <col:" ) == 0 )
502+ if (startsWith (ext, " <col:" ))
503503 col = strToInt<int >(ext.substr (5 , ext.find_first_of (" ,>" , 5 ) - 5 ));
504- else if (ext. compare ( 0 , 6 , " <line:" ) == 0 ) {
504+ else if (startsWith (ext, " <line:" )) {
505505 line = strToInt<int >(ext.substr (6 , ext.find_first_of (" :,>" , 6 ) - 6 ));
506506 const auto pos = ext.find (" , col:" );
507507 if (pos != std::string::npos)
@@ -542,7 +542,7 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList *tokenList, const s
542542 return addTypeTokens (tokenList, str.substr (0 , str.find (" \' :\' " ) + 1 ), scope);
543543 }
544544
545- if (str. compare ( 0 , 16 , " 'enum (anonymous" ) == 0 )
545+ if (startsWith (str, " 'enum (anonymous" ))
546546 return nullptr ;
547547
548548 std::string type;
@@ -943,7 +943,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
943943 }
944944 if (nodeType == DeclRefExpr) {
945945 int addrIndex = mExtTokens .size () - 1 ;
946- while (addrIndex > 1 && mExtTokens [addrIndex]. compare ( 0 , 2 , " 0x" ) != 0 )
946+ while (addrIndex > 1 && ! startsWith ( mExtTokens [addrIndex], " 0x" ))
947947 --addrIndex;
948948 const std::string addr = mExtTokens [addrIndex];
949949 std::string name = unquote (getSpelling ());
@@ -985,7 +985,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
985985 }
986986 if (nodeType == EnumDecl) {
987987 int colIndex = mExtTokens .size () - 1 ;
988- while (colIndex > 0 && mExtTokens [colIndex]. compare ( 0 , 4 , " col:" ) != 0 && mExtTokens [colIndex]. compare ( 0 , 5 , " line:" ) != 0 )
988+ while (colIndex > 0 && ! startsWith ( mExtTokens [colIndex], " col:" ) && ! startsWith ( mExtTokens [colIndex], " line:" ))
989989 --colIndex;
990990 if (colIndex == 0 )
991991 return nullptr ;
@@ -1131,10 +1131,10 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
11311131 Token *s = getChild (0 )->createTokens (tokenList);
11321132 Token *dot = addtoken (tokenList, " ." );
11331133 std::string memberName = getSpelling ();
1134- if (memberName. compare ( 0 , 2 , " ->" ) == 0 ) {
1134+ if (startsWith (memberName, " ->" )) {
11351135 dot->originalName (" ->" );
11361136 memberName = memberName.substr (2 );
1137- } else if (memberName. compare ( 0 , 1 , " ." ) == 0 ) {
1137+ } else if (startsWith (memberName, " ." )) {
11381138 memberName = memberName.substr (1 );
11391139 }
11401140 if (memberName.empty ())
@@ -1150,7 +1150,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
11501150 return nullptr ;
11511151 const Token *defToken = addtoken (tokenList, " namespace" );
11521152 const std::string &s = mExtTokens [mExtTokens .size () - 2 ];
1153- const Token* nameToken = (s. compare ( 0 , 4 , " col:" ) == 0 || s. compare ( 0 , 5 , " line:" ) == 0 ) ?
1153+ const Token* nameToken = (startsWith (s, " col:" ) || startsWith (s, " line:" )) ?
11541154 addtoken (tokenList, mExtTokens .back ()) : nullptr ;
11551155 Scope *scope = createScope (tokenList, Scope::ScopeType::eNamespace, children, defToken);
11561156 if (nameToken)
0 commit comments