1.. title:: clang-tidy - abseil-string-find-str-contains 2 3abseil-string-find-str-contains 4=============================== 5 6Finds ``s.find(...) == string::npos`` comparisons (for various string-like types) 7and suggests replacing with ``absl::StrContains()``. 8 9This improves readability and reduces the likelihood of accidentally mixing 10``find()`` and ``npos`` from different string-like types. 11 12By default, "string-like types" includes ``::std::basic_string``, 13``::std::basic_string_view``, and ``::absl::string_view``. See the 14StringLikeClasses option to change this. 15 16.. code-block:: c++ 17 18 std::string s = "..."; 19 if (s.find("Hello World") == std::string::npos) { /* do something */ } 20 21 absl::string_view a = "..."; 22 if (absl::string_view::npos != a.find("Hello World")) { /* do something */ } 23 24becomes 25 26.. code-block:: c++ 27 28 std::string s = "..."; 29 if (!absl::StrContains(s, "Hello World")) { /* do something */ } 30 31 absl::string_view a = "..."; 32 if (absl::StrContains(a, "Hello World")) { /* do something */ } 33 34 35Options 36------- 37 38.. option:: StringLikeClasses 39 40 Semicolon-separated list of names of string-like classes. By default includes 41 ``::std::basic_string``, ``::std::basic_string_view``, and 42 ``::absl::string_view``. 43 44.. option:: IncludeStyle 45 46 A string specifying which include-style is used, `llvm` or `google`. Default 47 is `llvm`. 48 49.. option:: AbseilStringsMatchHeader 50 51 The location of Abseil's ``strings/match.h``. Defaults to 52 ``absl/strings/match.h``. 53