From 7599c4bb6ed7c2e4fa2fb1242d993a742b7af9b1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 15 Nov 2017 17:19:13 -0800 Subject: [PATCH] ircd: Maintain data pointer of string_view's through various ops. --- include/ircd/stringops.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/ircd/stringops.h b/include/ircd/stringops.h index 0420e1af2..86c320398 100644 --- a/include/ircd/stringops.h +++ b/include/ircd/stringops.h @@ -425,22 +425,28 @@ ircd::rstrip(const string_view &str, return pos != string_view::npos? string_view{str.substr(0, pos + 1)} : str; } -/// Remove leading instances of c from the returned view +/// Remove leading instances of c from the returned view. +/// Note in case the strip results in an empty view, we return a string_view +/// with the original pointer and size 0 so it carries through the defined(). inline ircd::string_view ircd::lstrip(const string_view &str, const char &c) { const auto pos(str.find_first_not_of(c)); - return pos != string_view::npos? string_view{str.substr(pos)} : string_view{}; + return pos != string_view::npos? string_view{str.substr(pos)}: + string_view{str.data(), size_t{0}}; } /// Remove leading instances of c from the returned view +/// Note in case the strip results in an empty view, we return a string_view +/// with the original pointer and size 0 so it carries through the defined(). inline ircd::string_view ircd::lstrip(const string_view &str, const string_view &c) { const auto pos(str.find_first_not_of(c)); - return pos != string_view::npos? string_view{str.substr(pos)} : string_view{}; + return pos != string_view::npos? string_view{str.substr(pos)}: + string_view{str.data(), size_t{0}}; } template