From: Joel Rosdahl Date: Fri, 31 Jul 2020 07:43:53 +0000 (+0200) Subject: Inline Util::{starts,ends}_with X-Git-Tag: v4.0~247 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c89821b1aceea726c7da3be7af409da8d2c8d651;p=thirdparty%2Fccache.git Inline Util::{starts,ends}_with --- diff --git a/src/Util.cpp b/src/Util.cpp index 0476bc224..c2cb37b43 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -369,12 +369,6 @@ dir_name(string_view path) } } -bool -ends_with(string_view string, string_view suffix) -{ - return string.ends_with(suffix); -} - std::string expand_environment_variables(const std::string& str) { @@ -1137,20 +1131,6 @@ split_into_strings(string_view input, const char* separators) return split_at(input, separators); } -bool -starts_with(const char* string, nonstd::string_view prefix) -{ - // Optimized version of starts_with(string_view, string_view): avoid computing - // the length of the string argument. - return strncmp(string, prefix.data(), prefix.length()) == 0; -} - -bool -starts_with(string_view string, string_view prefix) -{ - return string.starts_with(prefix); -} - std::string strip_ansi_csi_seqs(string_view string) { diff --git a/src/Util.hpp b/src/Util.hpp index 149d709ff..000f4b855 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -120,8 +120,12 @@ bool create_dir(nonstd::string_view dir); // Get directory name of path. nonstd::string_view dir_name(nonstd::string_view path); -// Return true if suffix is a suffix of string. -bool ends_with(nonstd::string_view string, nonstd::string_view suffix); +// Return true if `suffix` is a suffix of `string`. +inline bool +ends_with(nonstd::string_view string, nonstd::string_view suffix) +{ + return string.ends_with(suffix); +} // Expand all instances of $VAR or ${VAR}, where VAR is an environment variable, // in `str`. Throws `Error` if one of the environment variables. @@ -357,8 +361,20 @@ std::vector split_into_strings(nonstd::string_view input, const char* separators); // Return true if `prefix` is a prefix of `string`. -bool starts_with(const char* string, nonstd::string_view prefix); -bool starts_with(nonstd::string_view string, nonstd::string_view prefix); +inline bool +starts_with(const char* string, nonstd::string_view prefix) +{ + // Optimized version of starts_with(string_view, string_view): avoid computing + // the length of the string argument. + return strncmp(string, prefix.data(), prefix.length()) == 0; +} + +// Return true if `prefix` is a prefix of `string`. +inline bool +starts_with(nonstd::string_view string, nonstd::string_view prefix) +{ + return string.starts_with(prefix); +} // Returns a copy of string with the specified ANSI CSI sequences removed. [[gnu::warn_unused_result]] std::string