fs/Path: add method RelativeFS()
Move code from map_fs_to_utf8().
This commit is contained in:
@@ -184,3 +184,25 @@ void Path::GlobalInit()
|
||||
SetFSCharset("ISO-8859-1");
|
||||
}
|
||||
}
|
||||
|
||||
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 (!G_IS_DIR_SEPARATOR(*other_fs))
|
||||
/* mismatch */
|
||||
return nullptr;
|
||||
|
||||
/* skip remaining path separators */
|
||||
do {
|
||||
++other_fs;
|
||||
} while (G_IS_DIR_SEPARATOR(*other_fs));
|
||||
}
|
||||
|
||||
return other_fs;
|
||||
}
|
||||
|
@@ -223,6 +223,15 @@ public:
|
||||
*/
|
||||
gcc_pure
|
||||
Path GetDirectoryName() const;
|
||||
|
||||
/**
|
||||
* Determine the relative part of the given path to this
|
||||
* object, not including the directory separator. Returns an
|
||||
* empty string if the given path equals this object or
|
||||
* nullptr on mismatch.
|
||||
*/
|
||||
gcc_pure
|
||||
const char *RelativeFS(const char *other_fs) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user