namespace util {
+// --- Interface ---
+
// Return whether `path` is absolute.
bool is_absolute_path(nonstd::string_view path);
// Return whether `path` includes at least one directory separator.
+bool is_full_path(nonstd::string_view path);
+
+// Split a list of paths (such as the content of $PATH on Unix platforms or
+// %PATH% on Windows platforms) into paths.
+std::vector<std::string> split_path_list(nonstd::string_view path_list);
+
+// Make `path` an absolute path.
+std::string to_absolute_path(nonstd::string_view path);
+
+// --- Inline implementations ---
+
inline bool
-is_full_path(nonstd::string_view path)
+is_full_path(const nonstd::string_view path)
{
#ifdef _WIN32
if (path.find('\\') != nonstd::string_view::npos) {
return path.find('/') != nonstd::string_view::npos;
}
-// Split a list of paths (such as the content of $PATH on Unix platforms or
-// %PATH% on Windows platforms) into paths.
-std::vector<std::string> split_path_list(nonstd::string_view path_list);
-
-// Make `path` an absolute path.
-std::string to_absolute_path(nonstd::string_view path);
-
} // namespace util
namespace util {
+// --- Interface ---
+
// Return true if `suffix` is a suffix of `string`.
-inline bool
-ends_with(const nonstd::string_view string, const nonstd::string_view suffix)
-{
- return string.ends_with(suffix);
-}
+bool ends_with(nonstd::string_view string, nonstd::string_view suffix);
// Parse a string into a signed integer.
//
split_once(nonstd::string_view string, char split_char);
// Return true if `prefix` is a prefix of `string`.
+bool starts_with(const char* string, nonstd::string_view prefix);
+
+// Return true if `prefix` is a prefix of `string`.
+bool starts_with(nonstd::string_view string, nonstd::string_view prefix);
+
+// Strip whitespace from left and right side of a string.
+[[nodiscard]] std::string strip_whitespace(nonstd::string_view string);
+
+// --- Inline implementations ---
+
inline bool
-starts_with(const char* string, const nonstd::string_view prefix)
+ends_with(const nonstd::string_view string, const nonstd::string_view suffix)
+{
+ return string.ends_with(suffix);
+}
+inline bool
+starts_with(const char* const string, const nonstd::string_view prefix)
{
// Optimized version of starts_with(string_view, string_view): avoid computing
// the length of the string argument.
return std::strncmp(string, prefix.data(), prefix.length()) == 0;
}
-// Return true if `prefix` is a prefix of `string`.
inline bool
starts_with(const nonstd::string_view string, const nonstd::string_view prefix)
{
return string.starts_with(prefix);
}
-// Strip whitespace from left and right side of a string.
-[[nodiscard]] std::string strip_whitespace(nonstd::string_view string);
-
} // namespace util