mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 11:46:41 +00:00

Also document cases with two or three arguments (matching default arguments) this check matches. Closes https://github.com/llvm/llvm-project/issues/129498.
26 lines
1.4 KiB
ReStructuredText
26 lines
1.4 KiB
ReStructuredText
.. title:: clang-tidy - modernize-use-starts-ends-with
|
|
|
|
modernize-use-starts-ends-with
|
|
==============================
|
|
|
|
Checks for common roundabout ways to express ``starts_with`` and ``ends_with``
|
|
and suggests replacing with the simpler method when it is available. Notably,
|
|
this will work with ``std::string`` and ``std::string_view``.
|
|
|
|
Covered scenarios:
|
|
|
|
==================================================== =====================
|
|
Expression Replacement
|
|
---------------------------------------------------- ---------------------
|
|
``u.find(v) == 0`` ``u.starts_with(v)``
|
|
``u.find(v, 0) == 0`` ``u.starts_with(v)``
|
|
``u.find(v, 0, v.size()) == 0`` ``u.starts_with(v)``
|
|
``u.rfind(v, 0) != 0`` ``!u.starts_with(v)``
|
|
``u.rfind(v, 0, v.size()) != 0`` ``!u.starts_with(v)``
|
|
``u.compare(0, v.size(), v) == 0`` ``u.starts_with(v)``
|
|
``u.substr(0, v.size()) == v`` ``u.starts_with(v)``
|
|
``v != u.substr(0, v.size())`` ``!u.starts_with(v)``
|
|
``u.compare(u.size() - v.size(), v.size(), v) == 0`` ``u.ends_with(v)``
|
|
``u.rfind(v) == u.size() - v.size()`` ``u.ends_with(v)``
|
|
==================================================== =====================
|