forked from OSchip/llvm-project
abseil-string-find-str-contains should not propose an edit for the three-parameter version of find().
std::string, std::string_view, and absl::string_view all have a three-parameter version of find() which has a "count" (or "n") paremeter limiting the size of the substring to search. We don't want to propose changing to absl::StrContains in those cases. This change fixes that and adds unit tests to confirm. Reviewed By: ymandel Differential Revision: https://reviews.llvm.org/D107837
This commit is contained in:
parent
2ced1f338a
commit
1fdb3e36ff
|
@ -53,7 +53,7 @@ makeRewriteRule(const std::vector<std::string> &StringLikeClassNames,
|
|||
to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass))));
|
||||
auto StringFind = cxxMemberCallExpr(
|
||||
callee(cxxMethodDecl(
|
||||
hasName("find"),
|
||||
hasName("find"), parameterCountIs(2),
|
||||
hasParameter(
|
||||
0, parmVarDecl(anyOf(hasType(StringType), hasType(CharStarType),
|
||||
hasType(CharType)))))),
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
~basic_string();
|
||||
int find(basic_string s, int pos = 0);
|
||||
int find(const C *s, int pos = 0);
|
||||
int find(const C *s, int pos, int n);
|
||||
int find(char c, int pos = 0);
|
||||
static constexpr size_t npos = -1;
|
||||
};
|
||||
|
@ -30,6 +31,7 @@ public:
|
|||
~basic_string_view();
|
||||
int find(basic_string_view s, int pos = 0);
|
||||
int find(const C *s, int pos = 0);
|
||||
int find(const C *s, int pos, int n);
|
||||
int find(char c, int pos = 0);
|
||||
static constexpr size_t npos = -1;
|
||||
};
|
||||
|
@ -48,6 +50,7 @@ public:
|
|||
~string_view();
|
||||
int find(string_view s, int pos = 0);
|
||||
int find(const char *s, int pos = 0);
|
||||
int find(const char *s, int pos, int n);
|
||||
int find(char c, int pos = 0);
|
||||
static constexpr size_t npos = -1;
|
||||
};
|
||||
|
@ -263,6 +266,18 @@ void no_nonzero_pos() {
|
|||
asv.find("a", 3) == std::string_view::npos;
|
||||
}
|
||||
|
||||
// Confirms that it does not match when the count parameter is present.
|
||||
void no_count() {
|
||||
std::string ss;
|
||||
ss.find("a", 0, 1) == std::string::npos;
|
||||
|
||||
std::string_view ssv;
|
||||
ssv.find("a", 0, 1) == std::string_view::npos;
|
||||
|
||||
absl::string_view asv;
|
||||
asv.find("a", 0, 1) == std::string_view::npos;
|
||||
}
|
||||
|
||||
// Confirms that it does not match when it's compared to something other than
|
||||
// npos, even if the value is the same as npos.
|
||||
void no_non_npos() {
|
||||
|
|
Loading…
Reference in New Issue