42 lines · plain
1.. title:: clang-tidy - abseil-faster-strsplit-delimiter2 3abseil-faster-strsplit-delimiter4================================5 6Finds instances of ``absl::StrSplit()`` or ``absl::MaxSplits()`` where the7delimiter is a single character string literal and replaces with a character.8The check will offer a suggestion to change the string literal into a9character. It will also catch code using ``absl::ByAnyChar()`` for just a10single character and will transform that into a single character as well.11 12These changes will give the same result, but using characters rather than13single character string literals is more efficient and readable.14 15Examples:16 17.. code-block:: c++18 19 // Original - the argument is a string literal.20 for (auto piece : absl::StrSplit(str, "B")) {21 22 // Suggested - the argument is a character, which causes the more efficient23 // overload of absl::StrSplit() to be used.24 for (auto piece : absl::StrSplit(str, 'B')) {25 26 27 // Original - the argument is a string literal inside absl::ByAnyChar call.28 for (auto piece : absl::StrSplit(str, absl::ByAnyChar("B"))) {29 30 // Suggested - the argument is a character, which causes the more efficient31 // overload of absl::StrSplit() to be used and we do not need absl::ByAnyChar32 // anymore.33 for (auto piece : absl::StrSplit(str, 'B')) {34 35 36 // Original - the argument is a string literal inside absl::MaxSplits call.37 for (auto piece : absl::StrSplit(str, absl::MaxSplits("B", 1))) {38 39 // Suggested - the argument is a character, which causes the more efficient40 // overload of absl::StrSplit() to be used.41 for (auto piece : absl::StrSplit(str, absl::MaxSplits('B', 1))) {42