26 lines · plain
1.. title:: clang-tidy - modernize-use-starts-ends-with2 3modernize-use-starts-ends-with4==============================5 6Checks for common roundabout ways to express ``starts_with`` and ``ends_with``7and suggests replacing with the simpler method when it is available. Notably,8this will work with ``std::string`` and ``std::string_view``.9 10Covered scenarios:11 12==================================================== =====================13Expression Replacement14---------------------------------------------------- ---------------------15``u.find(v) == 0`` ``u.starts_with(v)``16``u.find(v, 0) == 0`` ``u.starts_with(v)``17``u.find(v, 0, v.size()) == 0`` ``u.starts_with(v)``18``u.rfind(v, 0) != 0`` ``!u.starts_with(v)``19``u.rfind(v, 0, v.size()) != 0`` ``!u.starts_with(v)``20``u.compare(0, v.size(), v) == 0`` ``u.starts_with(v)``21``u.substr(0, v.size()) == v`` ``u.starts_with(v)``22``v != u.substr(0, v.size())`` ``!u.starts_with(v)``23``u.compare(u.size() - v.size(), v.size(), v) == 0`` ``u.ends_with(v)``24``u.rfind(v) == u.size() - v.size()`` ``u.ends_with(v)``25==================================================== =====================26