53 lines · plain
1.. title:: clang-tidy - abseil-string-find-str-contains2 3abseil-string-find-str-contains4===============================5 6Finds ``s.find(...) == string::npos`` comparisons (for various string-like7types) and suggests replacing with ``absl::StrContains()``.8 9This improves readability and reduces the likelihood of accidentally mixing10``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 the14StringLikeClasses 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 24becomes25 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 35Options36-------37 38.. option:: StringLikeClasses39 40 Semicolon-separated list of names of string-like classes. By default includes41 ``::std::basic_string``, ``::std::basic_string_view``, and42 ``::absl::string_view``.43 44.. option:: IncludeStyle45 46 A string specifying which include-style is used, `llvm` or `google`. Default47 is `llvm`.48 49.. option:: AbseilStringsMatchHeader50 51 The location of Abseil's ``strings/match.h``. Defaults to52 ``absl/strings/match.h``.53