fs/AllocatedPath: use PathTraitsFS::Relative()
Eliminate duplicate code.
This commit is contained in:
parent
cdd0ccc67a
commit
a6dd998d31
|
@ -61,28 +61,6 @@ AllocatedPath::ToUTF8() const
|
||||||
return ::PathToUTF8(c_str());
|
return ::PathToUTF8(c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
|
||||||
AllocatedPath::Relative(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AllocatedPath::ChopSeparators()
|
AllocatedPath::ChopSeparators()
|
||||||
{
|
{
|
||||||
|
|
|
@ -249,7 +249,9 @@ public:
|
||||||
* nullptr on mismatch.
|
* nullptr on mismatch.
|
||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
const char *Relative(const char *other_fs) const;
|
const char *Relative(const char *other_fs) const {
|
||||||
|
return PathTraitsFS::Relative(c_str(), other_fs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chop trailing directory separators.
|
* Chop trailing directory separators.
|
||||||
|
|
Loading…
Reference in New Issue