From kde-commits Tue May 31 22:11:56 2005 From: Daniel Teske Date: Tue, 31 May 2005 22:11:56 +0000 To: kde-commits Subject: KDE/kdelibs/kio/bookmarks Message-Id: <1117577516.630697.8723.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=111757753615965 SVN commit 420377 by teske: Add the (static) methods int KBookmark::depth( const QString & address ) QString KBookmark::commonParent( QString A, QString B) M +14 -0 kbookmark.cc M +15 -0 kbookmark.h --- trunk/KDE/kdelibs/kio/bookmarks/kbookmark.cc #420376:420377 @@ -357,6 +357,20 @@ return grp.first(); } +QString KBookmark::commonParent(QString A, QString B) +{ + while(depth(A) > depth(B)) + A = parentAddress(A); + while(depth(B) > depth(A)) + B = parentAddress(B); + while(A != B) + { + A = parentAddress(A); + B = parentAddress(B); + } + return A; +} + static QDomNode cd_or_create(QDomNode node, QString name) { QDomNode subnode = node.namedItem(name); --- trunk/KDE/kdelibs/kio/bookmarks/kbookmark.h #420376:420377 @@ -156,6 +156,21 @@ { return parentAddress(address) + '/' + QString::number(positionInParent(address)+1); } /** + * @return depth of the address, depth of root is 0 + * This doesn't check whether the adress actually exists + * @since 3.5 + */ + static int depth( const QString & address ) + { return address.contains('/'); } + + /** + * @return the common parent of both addresses which + * has the greatest depth + * @since 3.5 + */ + static QString commonParent(QString A, QString B); + + /** * Get the value of a specific metadata item. * @param key Name of the metadata item * @return Value of the metadata item. QString::null is returned in case