1 | /* |
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 2015 Gregor Mi <codestruct@posteo.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KSERVICEUTIL_P_H |
9 | #define KSERVICEUTIL_P_H |
10 | |
11 | #include <QString> |
12 | |
13 | class KServiceUtilPrivate |
14 | { |
15 | public: |
16 | /** |
17 | * Lightweight implementation of QFileInfo::completeBaseName. |
18 | * |
19 | * Returns the complete base name of the file without the path. |
20 | * The complete base name consists of all characters in the file up to (but not including) the last '.' character. |
21 | * |
22 | * Example: "/tmp/archive.tar.gz" --> "archive.tar" |
23 | */ |
24 | static QString completeBaseName(const QString &filepath) |
25 | { |
26 | QString name = filepath; |
27 | int pos = name.lastIndexOf(c: QLatin1Char('/')); |
28 | if (pos != -1) { |
29 | name.remove(i: 0, len: pos + 1); |
30 | } |
31 | pos = name.lastIndexOf(c: QLatin1Char('.')); |
32 | if (pos != -1) { |
33 | name.truncate(pos); |
34 | } |
35 | return name; |
36 | } |
37 | }; |
38 | |
39 | #endif |
40 | |