Debian Codegraph @

llvm-project/clang-tools-extra/docs/clang-tidy/checks/abseil/string-find-startswith.rst

raw
1 .. title:: clang-tidy - abseil-string-find-startswith
2
3 abseil-string-find-startswith
4 =============================
5
6 Checks whether a ``std::string::find()`` or ``std::string::rfind()`` result is
7 compared with 0, and suggests replacing with ``absl::StartsWith()``. This is
8 both a readability and performance issue.
9
10 .. code-block:: c++
11
12 string s = "...";
13 if (s.find("Hello World") == 0) { /* do something */ }
14 if (s.rfind("Hello World", 0) == 0) { /* do something */ }
15
16 becomes
17
18
19 .. code-block:: c++
20
21 string s = "...";
22 if (absl::StartsWith(s, "Hello World")) { /* do something */ }
23 if (absl::StartsWith(s, "Hello World")) { /* do something */ }
24
25
26 Options
27 -------
28
29 .. option:: StringLikeClasses
30
31 Semicolon-separated list of names of string-like classes. By default only
32 ``std::basic_string`` is considered. The list of methods to considered is
33 fixed.
34
35 .. option:: IncludeStyle
36
37 A string specifying which include-style is used, `llvm` or `google`. Default
38 is `llvm`.
39
40 .. option:: AbseilStringsMatchHeader
41
42 The location of Abseil's ``strings/match.h``. Defaults to
43 ``absl/strings/match.h``.