From 1b29f20d73d839c324cf4ce2df61d2e857617383 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 27 Apr 2012 19:20:53 +0000 Subject: Implement connecting via atom interface. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4285 a436a847-0d15-0410-975c-d299462d15a1 --- src/Path.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src') 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 + * Copyright 2007-2012 David Robillard * * 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 -- cgit v1.2.1