brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 41a7ab5 Raw
49 lines · plain
1.. title:: clang-tidy - abseil-string-find-startswith2 3abseil-string-find-startswith4=============================5 6Checks whether a ``std::string::find()`` or ``std::string::rfind()`` (and7corresponding ``std::string_view`` methods) result is compared with 0, and8suggests replacing with ``absl::StartsWith()``. This is both a readability and9performance issue.10 11``starts_with`` was added as a built-in function on those types in C++20. If12available, prefer enabling :doc:`modernize-use-starts-ends-with13<../modernize/use-starts-ends-with>` instead of this check.14 15.. code-block:: c++16 17  string s = "...";18  if (s.find("Hello World") == 0) { /* do something */ }19  if (s.rfind("Hello World", 0) == 0) { /* do something */ }20 21becomes22 23 24.. code-block:: c++25 26  string s = "...";27  if (absl::StartsWith(s, "Hello World")) { /* do something */ }28  if (absl::StartsWith(s, "Hello World")) { /* do something */ }29 30 31Options32-------33 34.. option:: StringLikeClasses35 36   Semicolon-separated list of names of string-like classes. By default both37   ``std::basic_string`` and ``std::basic_string_view`` are considered. The list38   of methods to be considered is fixed.39 40.. option:: IncludeStyle41 42   A string specifying which include-style is used, `llvm` or `google`. Default43   is `llvm`.44 45.. option:: AbseilStringsMatchHeader46 47   The location of Abseil's ``strings/match.h``. Defaults to48   ``absl/strings/match.h``.49