File indexing completed on 2024-05-05 05:50:42

0001 /*
0002     SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004     SPDX-License-Identifier: BSD-2-Clause
0005 */
0006 
0007 #ifndef KERFUFFLE_UTILS_H
0008 #define KERFUFFLE_UTILS_H
0009 
0010 namespace Kerfuffle
0011 {
0012 namespace Util
0013 {
0014 // Get the name segment from a path
0015 // e.g. /foo/bar/bla -> bla
0016 //      /foo/bar/ -> bar
0017 QString lastPathSegment(const QString &path)
0018 {
0019     if (path == QLatin1String("/")) {
0020         return path;
0021     } else if (path.endsWith(QLatin1Char('/'))) {
0022         const int index = path.lastIndexOf(QLatin1Char('/'), -2);
0023         return path.mid(index + 1).chopped(1);
0024     } else {
0025         const int index = path.lastIndexOf(QLatin1Char('/'));
0026         return path.mid(index + 1);
0027     }
0028 }
0029 }
0030 }
0031 #endif