fs/Traits: add Apply()

This commit is contained in:
Max Kellermann 2018-07-18 12:54:44 +02:00
parent 2b1d6ad396
commit b168a9d469
3 changed files with 27 additions and 0 deletions

View File

@ -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.

View File

@ -144,6 +144,20 @@ PathTraitsFS::Relative(const_pointer_type base, const_pointer_type other) noexce
return RelativePathImpl<PathTraitsFS>(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

View File

@ -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;
};
/**