| 1 | /* |
| 2 | * Copyright (C) 2017 Damir Porobic <https://github.com/damirporobic> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include "PathHelper.h" |
| 22 | |
| 23 | bool PathHelper::isPathValid(const QString &path) |
| 24 | { |
| 25 | return !path.isNull() && !path.isEmpty(); |
| 26 | } |
| 27 | |
| 28 | bool PathHelper::isPipePath(const QString &path) |
| 29 | { |
| 30 | return path == QLatin1String("-"); |
| 31 | } |
| 32 | |
| 33 | bool PathHelper::isTempDirectory(const QString &path) |
| 34 | { |
| 35 | return path.startsWith(QDir::tempPath()); |
| 36 | } |
| 37 | |
| 38 | QString PathHelper::extractParentDirectory(const QString& path) |
| 39 | { |
| 40 | return path.section(QLatin1Char('/'), 0, -2); |
| 41 | } |
| 42 | |
| 43 | QString PathHelper::extractFilename(const QString& path) |
| 44 | { |
| 45 | auto filename = extractFilenameWithFormat(path); |
| 46 | if (filename.contains(QLatin1Char('.'))) { |
| 47 | return filename.section(QLatin1Char('.'), 0, -2); |
| 48 | } else { |
| 49 | return filename; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | QString PathHelper::extractFilenameWithFormat(const QString &path) |
| 54 | { |
| 55 | return path.section(QLatin1Char('/'), -1); |
| 56 | } |
| 57 | |
| 58 | QString PathHelper::extractFormat(const QString& path) |
| 59 | { |
| 60 | auto filename = extractFilenameWithFormat(path); |
| 61 | if (filename.contains(QLatin1Char('.'))) { |
| 62 | return path.section(QLatin1Char('.'), -1); |
| 63 | } else { |
| 64 | return {}; |
| 65 | } |
| 66 | } |