diff --git a/src/fs/AllocatedPath.hxx b/src/fs/AllocatedPath.hxx index 428312206..2168d56cb 100644 --- a/src/fs/AllocatedPath.hxx +++ b/src/fs/AllocatedPath.hxx @@ -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. */ diff --git a/src/fs/Path.hxx b/src/fs/Path.hxx index 0391f2781..c89e12c97 100644 --- a/src/fs/Path.hxx +++ b/src/fs/Path.hxx @@ -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. * diff --git a/src/fs/Path2.cxx b/src/fs/Path2.cxx index 6d45b2cc7..fbbe91bfa 100644 --- a/src/fs/Path2.cxx +++ b/src/fs/Path2.cxx @@ -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 {