diff --git a/userspace/engine/falco_utils.cpp b/userspace/engine/falco_utils.cpp index 3502e7cf..44922e65 100644 --- a/userspace/engine/falco_utils.cpp +++ b/userspace/engine/falco_utils.cpp @@ -68,19 +68,11 @@ void readfile(const std::string& filename, std::string& data) return; } - -bool starts_with(const std::string& text, const std::string& prefix) -{ - return prefix.empty() || - (text.size() >= prefix.size() && - std::memcmp(text.data(), prefix.data(), prefix.size()) == 0); -} - namespace network { -bool url_is_unix_scheme(const std::string& url) +bool is_unix_scheme(nonstd::string_view url) { - return starts_with(url, UNIX_SCHEME); + return url.starts_with(UNIX_SCHEME); } } // namespace network } // namespace utils diff --git a/userspace/engine/falco_utils.h b/userspace/engine/falco_utils.h index dc1fd85e..25def9ad 100644 --- a/userspace/engine/falco_utils.h +++ b/userspace/engine/falco_utils.h @@ -21,6 +21,7 @@ limitations under the License. #include #include #include +#include #pragma once @@ -33,11 +34,10 @@ namespace utils std::string wrap_text(const std::string& str, uint32_t initial_pos, uint32_t indent, uint32_t line_len); void readfile(const std::string& filename, std::string& data); -bool starts_with(const std::string& text, const std::string& prefix); namespace network { -static const std::string UNIX_SCHEME{"unix://"}; -bool url_is_unix_scheme(const std::string& url); +static const std::string UNIX_SCHEME("unix://"); +bool is_unix_scheme(nonstd::string_view url); } // namespace network } // namespace utils } // namespace falco