[clang-tools-extra] [clang-tidy] Add modernize-substr-to-starts-with check (PR #116033)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 14 07:39:23 PST 2024
================
@@ -7,26 +7,39 @@ 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``.
-.. code-block:: c++
+The check handles the following expressions:
- std::string s = "...";
- if (s.find("prefix") == 0) { /* do something */ }
- if (s.rfind("prefix", 0) == 0) { /* do something */ }
- if (s.compare(0, strlen("prefix"), "prefix") == 0) { /* do something */ }
- if (s.compare(s.size() - strlen("suffix"), strlen("suffix"), "suffix") == 0) {
- /* do something */
- }
- if (s.rfind("suffix") == (s.length() - 6)) {
- /* do something */
- }
-
-becomes
+==================================================== ===========================
----------------
EugeneZelenko wrote:
Length of header lines should be reduced.
https://github.com/llvm/llvm-project/pull/116033
More information about the cfe-commits
mailing list