File indexing completed on 2024-04-28 05:49:05

0001 /* This file is part of the KDE project
0002  *
0003  *  SPDX-FileCopyrightText: 2014 Gregor Mi <codestruct@posteo.org>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #include "fileutil.h"
0009 
0010 // code taken from https://stackoverflow.com/questions/15713529/get-common-parent-of-2-qdir
0011 // note that there is unit test
0012 const QString FileUtil::commonParent(const QString &path1, const QString &path2)
0013 {
0014     QString ret = path2;
0015 
0016     while (!path1.startsWith(ret)) {
0017         ret.chop(1);
0018     }
0019 
0020     if (ret.isEmpty()) {
0021         return ret;
0022     }
0023 
0024     while (!ret.endsWith(QLatin1Char('/'))) {
0025         ret.chop(1);
0026     }
0027 
0028     return ret;
0029 }
0030 
0031 // kate: space-indent on; indent-width 4; replace-tabs on;