util: annotate Split input lifetime

`Split` can return views into its input, but annotating its old reference warns for lvalue strings.
Take the span by value so Clang follows the backing storage.

`Split<std::string>` copies results but can still warn, while `SplitString` is unaffected.
This commit is contained in:
Lőrinc
2026-09-03 16:02:36 -07:00
parent 34c5dc0583
commit b57b0dbebd

View File

@@ -117,7 +117,7 @@ void ReplaceAll(std::string& in_out, std::string_view search, std::string_view s
* - 3)
*/
template <typename T = std::span<const char>>
std::vector<T> Split(const std::span<const char>& sp, std::string_view separators, bool include_sep = false)
std::vector<T> Split(std::span<const char> sp LIFETIMEBOUND, std::string_view separators, bool include_sep = false)
{
std::vector<T> ret;
auto it = sp.begin();
@@ -145,7 +145,7 @@ std::vector<T> Split(const std::span<const char>& sp, std::string_view separator
* "foo(bar(1),2),3) on ',' will return {"foo(bar(1)", "2)", "3)"}.
*/
template <typename T = std::span<const char>>
std::vector<T> Split(const std::span<const char>& sp, char sep, bool include_sep = false)
std::vector<T> Split(std::span<const char> sp LIFETIMEBOUND, char sep, bool include_sep = false)
{
return Split<T>(sp, std::string_view{&sep, 1}, include_sep);
}