summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-27 19:20:53 +0000
committerDavid Robillard <d@drobilla.net>2012-04-27 19:20:53 +0000
commit1b29f20d73d839c324cf4ce2df61d2e857617383 (patch)
tree53e5d53faac6de9c2e77104131a5dd43a4d99cb8 /src
parent62c10d2abae74e8c45b4ddb182757e934618dd72 (diff)
downloadraul-1b29f20d73d839c324cf4ce2df61d2e857617383.tar.gz
raul-1b29f20d73d839c324cf4ce2df61d2e857617383.tar.bz2
raul-1b29f20d73d839c324cf4ce2df61d2e857617383.zip
Implement connecting via atom interface.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4285 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/Path.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/Path.cpp b/src/Path.cpp
index fff4fbd..1c2f394 100644
--- a/src/Path.cpp
+++ b/src/Path.cpp
@@ -1,5 +1,5 @@
/* This file is part of Raul.
- * Copyright 2007-2011 David Robillard <http://drobilla.net>
+ * Copyright 2007-2012 David Robillard <http://drobilla.net>
*
* Raul is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
@@ -210,5 +210,28 @@ Path::is_parent_of(const Path& child) const
return child.is_child_of(*this);
}
+Path
+Path::lca(const Path& patha, const Path& pathb)
+{
+ const std::string a = patha.chop_scheme();
+ const std::string b = pathb.chop_scheme();
+ size_t len = std::min(a.length(), b.length());
+
+ size_t last_slash = 0;
+ for (size_t i = 0; i < len; ++i) {
+ if (a[i] == '/' && b[i] == '/') {
+ last_slash = i;
+ }
+ if (a[i] != b[i]) {
+ break;
+ }
+ }
+
+ if (last_slash <= 1) {
+ return root();
+ }
+ return Path(a.substr(0, last_slash));
+}
+
} // namespace Raul