fs/Traits: add function Relative()

Move code from Path::RelativeFS() and make it generic.
This commit is contained in:
Max Kellermann
2014-02-07 18:58:37 +01:00
parent 6b421cc354
commit d744c997d8
4 changed files with 61 additions and 23 deletions

View File

@@ -26,25 +26,3 @@ Path::ToUTF8() const
{
return ::PathToUTF8(c_str());
}
const char *
Path::RelativeFS(const char *other_fs) const
{
const size_t l = length();
if (memcmp(data(), other_fs, l) != 0)
return nullptr;
other_fs += l;
if (*other_fs != 0) {
if (!PathTraitsFS::IsSeparator(*other_fs))
/* mismatch */
return nullptr;
/* skip remaining path separators */
do {
++other_fs;
} while (PathTraitsFS::IsSeparator(*other_fs));
}
return other_fs;
}