From 0b27ac2f5c6a352be733f00e873ceb9d0904e92a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Oct 2013 22:09:02 +0200 Subject: fs/Path: add method RelativeFS() Move code from map_fs_to_utf8(). --- src/fs/Path.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/fs/Path.cxx') diff --git a/src/fs/Path.cxx b/src/fs/Path.cxx index 09616c9f4..1a1f133d0 100644 --- a/src/fs/Path.cxx +++ b/src/fs/Path.cxx @@ -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; +} -- cgit v1.2.3