File indexing completed on 2024-07-14 03:55:24

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2015 Gregor Mi <codestruct@posteo.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KSERVICEUTIL_P_H
0009 #define KSERVICEUTIL_P_H
0010 
0011 #include <QString>
0012 
0013 class KServiceUtilPrivate
0014 {
0015 public:
0016     /**
0017      * Lightweight implementation of QFileInfo::completeBaseName.
0018      *
0019      * Returns the complete base name of the file without the path.
0020      * The complete base name consists of all characters in the file up to (but not including) the last '.' character.
0021      *
0022      * Example: "/tmp/archive.tar.gz" --> "archive.tar"
0023      */
0024     static QString completeBaseName(const QString &filepath)
0025     {
0026         QString name = filepath;
0027         int pos = name.lastIndexOf(QLatin1Char('/'));
0028         if (pos != -1) {
0029             name.remove(0, pos + 1);
0030         }
0031         pos = name.lastIndexOf(QLatin1Char('.'));
0032         if (pos != -1) {
0033             name.truncate(pos);
0034         }
0035         return name;
0036     }
0037 };
0038 
0039 #endif