@@ -113,21 +113,33 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
113113 const auto OnClassWithEndsWithFunction = ClassTypeWithMethod (
114114 " ends_with_fun" , " ends_with" , " endsWith" , " endswith" , " EndsWith" );
115115
116- // Case 1: X.find(Y) [!=]= 0 -> starts_with.
116+ // Case 1: X.find(Y, [0], [LEN(Y)] ) [!=]= 0 -> starts_with.
117117 const auto FindExpr = cxxMemberCallExpr (
118- anyOf (argumentCountIs (1 ), hasArgument (1 , ZeroLiteral)),
119118 callee (
120119 cxxMethodDecl (hasName (" find" ), ofClass (OnClassWithStartsWithFunction))
121120 .bind (" find_fun" )),
122- hasArgument (0 , expr ().bind (" needle" )));
123-
124- // Case 2: X.rfind(Y, 0) [!=]= 0 -> starts_with.
121+ hasArgument (0 , expr ().bind (" needle" )),
122+ anyOf (
123+ // Detect the expression: X.find(Y);
124+ argumentCountIs (1 ),
125+ // Detect the expression: X.find(Y, 0);
126+ allOf (argumentCountIs (2 ), hasArgument (1 , ZeroLiteral)),
127+ // Detect the expression: X.find(Y, 0, LEN(Y));
128+ allOf (argumentCountIs (3 ), hasArgument (1 , ZeroLiteral),
129+ hasArgument (2 , lengthExprForStringNode (" needle" )))));
130+
131+ // Case 2: X.rfind(Y, 0, [LEN(Y)]) [!=]= 0 -> starts_with.
125132 const auto RFindExpr = cxxMemberCallExpr (
126- hasArgument (1 , ZeroLiteral),
127133 callee (cxxMethodDecl (hasName (" rfind" ),
128134 ofClass (OnClassWithStartsWithFunction))
129135 .bind (" find_fun" )),
130- hasArgument (0 , expr ().bind (" needle" )));
136+ hasArgument (0 , expr ().bind (" needle" )),
137+ anyOf (
138+ // Detect the expression: X.rfind(Y, 0);
139+ allOf (argumentCountIs (2 ), hasArgument (1 , ZeroLiteral)),
140+ // Detect the expression: X.rfind(Y, 0, LEN(Y));
141+ allOf (argumentCountIs (3 ), hasArgument (1 , ZeroLiteral),
142+ hasArgument (2 , lengthExprForStringNode (" needle" )))));
131143
132144 // Case 3: X.compare(0, LEN(Y), Y) [!=]= 0 -> starts_with.
133145 const auto CompareExpr = cxxMemberCallExpr (
0 commit comments