libxcks  0.1.0.1
pathutil.hpp
Go to the documentation of this file.
1 /*
2  * libxcks
3  * Copyright (C) 2022 Julien Couot
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 #ifndef INC_PATHUTIL_HPP_9D26D187_64D9_4224_8014_C7452B64B9EA
26 #define INC_PATHUTIL_HPP_9D26D187_64D9_4224_8014_C7452B64B9EA
27 
28 //---------------------------------------------------------------------------
29 #include <filesystem>
30 //#include <vector> // Included in "libxcks/types.hpp"
31 //#include <string> // Included in "libxcks/types.hpp"
32 
33 #include "libxcks/types.hpp"
34 //---------------------------------------------------------------------------
35 
36 
37 namespace libxcks
38 {
39 // Gets directories of a path.
40 std::vector<std::filesystem::path> getDirectories(const std::filesystem::path& p);
41 
42 // Gets directories of a path.
43 ArrayString getDirectoriesAsArrayString(const std::filesystem::path& p);
44 //---------------------------------------------------------------------------
45 
46 
47 // Compares two file names.
48 int compareFileName(const std::string& fn1, const std::string& fn2);
49 
50 // Compares file names of two paths.
51 int compareFileName(const std::filesystem::path& p1, const std::filesystem::path& p2);
52 //---------------------------------------------------------------------------
53 
54 
55 // Constructs a path from an array of directories and an optional filename.
56 std::filesystem::path constructPath(const ArrayString& dirs, const std::string& filename = std::string());
57 
58 // Ensures the path ends with a path separator.
59 std::filesystem::path ensureEndsWithPathSeparator(const std::filesystem::path& p);
60 //---------------------------------------------------------------------------
61 
62 
63 // Checks if the name of the file is valid.
64 bool isFileNameValid(const std::string& filename);
65 //---------------------------------------------------------------------------
66 } // namespace libxcks
67 //---------------------------------------------------------------------------
68 
69 #endif // INC_PATHUTIL_HPP_9D26D187_64D9_4224_8014_C7452B64B9EA
bool isFileNameValid(const std::string &filename)
Checks if the name of the file is valid.
Definition: pathutil.cpp:266
std::vector< std::filesystem::path > getDirectories(const std::filesystem::path &p)
Gets directories of a path.
Definition: pathutil.cpp:64
int compareFileName(const std::string &fn1, const std::string &fn2)
Compares two file names.
Definition: pathutil.cpp:108
std::filesystem::path constructPath(const ArrayString &dirs, const std::string &filename)
Constructs a path from an array of directories and an optional filename.
Definition: pathutil.cpp:170
ArrayString getDirectoriesAsArrayString(const std::filesystem::path &p)
Gets directories of a path.
Definition: pathutil.cpp:81
std::filesystem::path ensureEndsWithPathSeparator(const std::filesystem::path &p)
Ensures the path ends with a path separator.
Definition: pathutil.cpp:209
Common types for libxcks.
std::vector< std::string > ArrayString
Array of strings.
Definition: types.hpp:44