Skip to content

Commit c707971

Browse files
committed
up
1 parent b2e82cf commit c707971

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. title:: clang-tidy - modernize-use-starts-ends-with
2+
3+
modernize-use-starts-ends-with
4+
==============================
5+
6+
Checks for common roundabout ways to express ``starts_with`` and ``ends_with``
7+
and suggests replacing with the simpler method when it is available. Notably,
8+
this will work with ``std::string`` and ``std::string_view``.
9+
10+
Covered scenarios:
11+
12+
==================================================== =====================
13+
Expression Replacement
14+
---------------------------------------------------- ---------------------
15+
``u.find(v) == 0`` ``u.starts_with(v)``
16+
``u.rfind(v, 0) != 0`` ``!u.starts_with(v)``
17+
``u.compare(0, v.size(), v) == 0`` ``u.starts_with(v)``
18+
``u.substr(0, v.size()) == v`` ``u.starts_with(v)``
19+
``v != u.substr(0, v.size())`` ``!u.starts_with(v)``
20+
``u.compare(u.size() - v.size(), v.size(), v) == 0`` ``u.ends_with(v)``
21+
``u.rfind(v) == u.size() - v.size()`` ``u.ends_with(v)``
22+
==================================================== =====================

0 commit comments

Comments
 (0)