diff --git a/src/fs/AllocatedPath.hxx b/src/fs/AllocatedPath.hxx index 2a6277e40..e15460e9a 100644 --- a/src/fs/AllocatedPath.hxx +++ b/src/fs/AllocatedPath.hxx @@ -124,6 +124,11 @@ public: b.value.c_str(), b.value.size()); } + gcc_pure + static AllocatedPath Apply(Path base, Path path) noexcept { + return Traits::Apply(base.c_str(), path.c_str()); + } + /** * Convert a C string that is already in the filesystem * character set to a #Path instance. diff --git a/src/fs/Traits.cxx b/src/fs/Traits.cxx index 64698996c..4be5c1193 100644 --- a/src/fs/Traits.cxx +++ b/src/fs/Traits.cxx @@ -144,6 +144,20 @@ PathTraitsFS::Relative(const_pointer_type base, const_pointer_type other) noexce return RelativePathImpl(base, other); } +PathTraitsFS::string +PathTraitsFS::Apply(const_pointer_type base, const_pointer_type path) noexcept +{ + // TODO: support the Windows syntax (absolute path with or without drive, drive with relative path) + + if (base == nullptr) + return path; + + if (IsAbsolute(path)) + return path; + + return Build(base, path); +} + PathTraitsUTF8::string PathTraitsUTF8::Build(const_pointer_type a, size_t a_size, const_pointer_type b, size_t b_size) noexcept diff --git a/src/fs/Traits.hxx b/src/fs/Traits.hxx index e41ae1030..73339e444 100644 --- a/src/fs/Traits.hxx +++ b/src/fs/Traits.hxx @@ -158,6 +158,14 @@ struct PathTraitsFS { static string Build(const_pointer_type a, const_pointer_type b) noexcept { return Build(a, GetLength(a), b, GetLength(b)); } + + /** + * Interpret the given path as being relative to the given + * base, and return the concatenated path. + */ + gcc_pure + static string Apply(const_pointer_type base, + const_pointer_type path) noexcept; }; /**