fs/Path: add operator+

This commit is contained in:
Max Kellermann 2022-07-14 18:36:22 +02:00
parent 150e8f78bf
commit c344403bed
3 changed files with 25 additions and 0 deletions

View File

@ -85,6 +85,18 @@ public:
return Path::FromFS(c_str());
}
/**
* Concatenate two paths.
*/
[[gnu::pure]]
static AllocatedPath Concat(string_view a, string_view b) noexcept {
AllocatedPath result{nullptr};
result.value.reserve(a.size() + b.size());
result.value.assign(a);
result.value.append(b);
return result;
}
/**
* Join two path components with the path separator.
*/

View File

@ -191,6 +191,13 @@ public:
const_pointer GetExtension() const noexcept;
};
/**
* Concatenate a string to a #Path object.
*/
[[gnu::pure]]
AllocatedPath
operator+(Path path, PathTraitsFS::string_view other) noexcept;
/**
* Concatenate two path components using the directory separator.
*

View File

@ -34,6 +34,12 @@ Path::WithSuffix(const_pointer new_suffix) const noexcept
return result;
}
AllocatedPath
operator+(Path a, PathTraitsFS::string_view b) noexcept
{
return AllocatedPath::Concat(a.c_str(), b);
}
AllocatedPath
operator/(Path a, Path b) noexcept
{