3 Commits

Author SHA1 Message Date
Nicolas van Kempen
f1367a473d
[clang-tidy][modernize-use-starts-ends-with] Add support for two ends_with patterns (#110448)
Add support for the following two patterns:
```
haystack.compare(haystack.length() - needle.length(), needle.length(), needle) == 0;
haystack.rfind(needle) == (haystack.size() - needle.size());
```
2024-10-11 21:00:38 -04:00
Nicolas van Kempen
ef5906989a
[clang-tidy][modernize-use-starts-ends-with] Add support for compare() (#89530)
Using `compare` is the next most common roundabout way to express
`starts_with` before it was added to the standard. In this case, using
`starts_with` is a readability improvement. Extend existing
`modernize-use-starts-ends-with` to cover this case.

```
// The following will now be replaced by starts_with().
string.compare(0, strlen("prefix"), "prefix") == 0;
string.compare(0, 6, "prefix") == 0;
string.compare(0, prefix.length(), prefix) == 0;
string.compare(0, prefix.size(), prefix) == 0;
```
2024-04-23 23:35:05 +02:00
Nicolas van Kempen
bc8cff1d7f
[clang-tidy] Add new modernize-use-starts-ends-with check (#72385)
Make a modernize version of abseil-string-find-startswith using the
available C++20 `std::string::starts_with` and
`std::string_view::starts_with`. Following up from
https://github.com/llvm/llvm-project/pull/72283.
2023-12-04 15:39:28 +01:00