return n == std::string::npos ? path : path.substr(n + 1);
}
+std::string
+change_extension(string_view path, string_view new_ext)
+{
+ string_view without_ext = Util::remove_extension(path);
+ return std::string(without_ext).append(new_ext.data(), new_ext.length());
+}
+
bool
create_dir(string_view dir)
{
return n == 0 ? "/" : path.substr(0, n);
}
-string_view
-get_extension(string_view path)
-{
-#ifndef _WIN32
- const char stop_at_chars[] = "./";
-#else
- const char stop_at_chars[] = "./\\";
-#endif
- size_t pos = path.find_last_of(stop_at_chars);
- if (pos == string_view::npos || path.at(pos) == '/') {
- return {};
-#ifdef _WIN32
- } else if (path.at(pos) == '\\') {
- return {};
-#endif
- } else {
- return path.substr(pos);
- }
-}
-
-string_view
-remove_extension(string_view path)
-{
- return path.substr(0, path.length() - get_extension(path).length());
-}
-
-std::string
-change_extension(string_view path, string_view new_ext)
-{
- string_view without_ext = Util::remove_extension(path);
- return std::string(without_ext).append(new_ext.data(), new_ext.length());
-}
-
-string_view
-get_truncated_base_name(string_view path, size_t max_length)
-{
- string_view input_base = Util::base_name(path);
- size_t dot_pos = input_base.find('.');
- size_t truncate_pos =
- std::min(max_length, std::min(input_base.size(), dot_pos));
- return input_base.substr(0, truncate_pos);
-}
-
bool
ends_with(string_view string, string_view suffix)
{
progress_receiver(1.0);
}
+string_view
+get_extension(string_view path)
+{
+#ifndef _WIN32
+ const char stop_at_chars[] = "./";
+#else
+ const char stop_at_chars[] = "./\\";
+#endif
+ size_t pos = path.find_last_of(stop_at_chars);
+ if (pos == string_view::npos || path.at(pos) == '/') {
+ return {};
+#ifdef _WIN32
+ } else if (path.at(pos) == '\\') {
+ return {};
+#endif
+ } else {
+ return path.substr(pos);
+ }
+}
+
void
get_level_1_files(const std::string& dir,
const ProgressReceiver& progress_receiver,
return path;
}
+string_view
+get_truncated_base_name(string_view path, size_t max_length)
+{
+ string_view input_base = Util::base_name(path);
+ size_t dot_pos = input_base.find('.');
+ size_t truncate_pos =
+ std::min(max_length, std::min(input_base.size(), dot_pos));
+ return input_base.substr(0, truncate_pos);
+}
+
int
parse_int(const std::string& value)
{
std::istreambuf_iterator<char>());
}
+string_view
+remove_extension(string_view path)
+{
+ return path.substr(0, path.length() - get_extension(path).length());
+}
+
bool
starts_with(string_view string, string_view prefix)
{
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
// Get base name of path.
nonstd::string_view base_name(nonstd::string_view path);
-// Return the file extension (including the dot) as a view into `path`. If
-// `path` has no file extension, an empty string_view is returned.
-nonstd::string_view get_extension(nonstd::string_view path);
-
-// Return a view into `path` containing the given path without the filename
-// extension as determined by `get_extension()`.
-nonstd::string_view remove_extension(nonstd::string_view path);
-
-// Remove the extension via `remove_extension()`, then add `new_ext`. `new_ext`
-// should start with a dot, no extra dot is inserted.
-std::string change_extension(nonstd::string_view path,
- nonstd::string_view new_ext);
-
-// Return a shortened view into the base name of `path`. This view starts at the
-// beginning of the base name and ends at either the position the first dot, or
-// `max_length`, or the length of the base name, whichever is the shortest.
-nonstd::string_view get_truncated_base_name(nonstd::string_view path,
- size_t max_length);
-
// Get an integer value from bytes in big endian order.
//
// Parameters:
value = buffer[0];
}
+// Remove the extension via `remove_extension()`, then add `new_ext`. `new_ext`
+// should start with a dot, no extra dot is inserted.
+std::string change_extension(nonstd::string_view path,
+ nonstd::string_view new_ext);
+
// Create a directory if needed, including its parents if needed.
//
// Returns true if the directory exists or could be created, otherwise false.
const SubdirVisitor& visitor,
const ProgressReceiver& progress_receiver);
+// Return the file extension (including the dot) as a view into `path`. If
+// `path` has no file extension, an empty string_view is returned.
+nonstd::string_view get_extension(nonstd::string_view path);
+
// Get a list of files in a level 1 subdirectory of the cache.
//
// The function works under the assumption that directory entries with one
uint32_t levels,
nonstd::string_view name,
nonstd::string_view suffix);
+// Return a shortened view into the base name of `path`. This view starts at the
+// beginning of the base name and ends at either the position the first dot, or
+// `max_length`, or the length of the base name, whichever is the shortest.
+nonstd::string_view get_truncated_base_name(nonstd::string_view path,
+ size_t max_length);
// Write bytes in big endian order from an integer value.
//
// Throws Error on error.
std::string read_file(const std::string& path);
+// Return a view into `path` containing the given path without the filename
+// extension as determined by `get_extension()`.
+nonstd::string_view remove_extension(nonstd::string_view path);
+
// Return true if prefix is a prefix of string.
bool starts_with(nonstd::string_view string, nonstd::string_view prefix);