Refactored handling of relative paths (#213)
This commit is contained in:
@@ -404,6 +404,15 @@ std::filesystem::path ensure_path_is_absolute(
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_relative_to(
|
||||
const std::filesystem::path &child, const std::filesystem::path &parent)
|
||||
{
|
||||
if (child.has_root_directory() != parent.has_root_directory())
|
||||
return false;
|
||||
|
||||
return starts_with(child, parent);
|
||||
}
|
||||
|
||||
std::string format_message_comment(const std::string &comment, unsigned width)
|
||||
{
|
||||
if (width == 0)
|
||||
|
||||
@@ -435,6 +435,17 @@ std::string path_to_url(const std::filesystem::path &p);
|
||||
std::filesystem::path ensure_path_is_absolute(const std::filesystem::path &p,
|
||||
const std::filesystem::path &root = std::filesystem::current_path());
|
||||
|
||||
/**
|
||||
* @brief Check if a given path is relative to another path.
|
||||
*
|
||||
* @param parent The path to be checked for relativity.
|
||||
* @param right The base path against which the relativity is checked.
|
||||
* @return True if the child path is relative to the parent path, false
|
||||
* otherwise.
|
||||
*/
|
||||
bool is_relative_to(
|
||||
const std::filesystem::path &parent, const std::filesystem::path &child);
|
||||
|
||||
std::string format_message_comment(
|
||||
const std::string &c, unsigned width = kDefaultMessageCommentWidth);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user