File indexing completed on 2024-05-12 15:55:34

0001 // SPDX-FileCopyrightText: 2003-2010 Jesper K. Pedersen <blackie@kde.org>
0002 // SPDX-FileCopyrightText: 2021 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 #ifndef KPABASE_FILENAME_UTIL_H
0007 #define KPABASE_FILENAME_UTIL_H
0008 
0009 #include <QString>
0010 
0011 namespace DB
0012 {
0013 class FileName;
0014 }
0015 namespace Utilities
0016 {
0017 /**
0018  * @brief stripEndingForwardSlash removes a trailing '/' from a QString if there is one.
0019  * @param fileName
0020  * @return the \p fileName without ending '/'
0021  * @note The mere usage of this function for actual filename operations seems like a code-smell to me - porting towards robust interfaces as offered by QDir seems prudent.
0022  */
0023 QString stripEndingForwardSlash(const QString &fileName);
0024 
0025 /**
0026  * @brief fileNameFromUserData creates a FileName from an absolute or relative file name string.
0027  * It also recognizes local URLs (starting with "file://").
0028  * @param fileName
0029  * @return a DB::FileName corresponding to the \p fileName, or a default-constructed FileName if the name is not valid.
0030  * @attention Requires an initialized SettingsData singleton.
0031  */
0032 DB::FileName fileNameFromUserData(const QString &fileName);
0033 
0034 /**
0035  * @brief Compute the directory part of a relative or absolute filename.
0036  * @param fileName a filename
0037  * @return the \p fileName up to (but excluding) the last occurrence of '/'
0038  */
0039 QString relativeFolderName(const QString &fileName);
0040 }
0041 
0042 #endif /* KPABASE_FILENAME_UTIL_H */
0043 
0044 // vi:expandtab:tabstop=4 shiftwidth=4: