path_help.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries UICore may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 #pragma once
30 
31 #include <vector>
32 
33 namespace uicore
34 {
36  enum class FilePathType
37  {
40 
42  slashes
43  };
44 
46  class FilePath
47  {
48  public:
50  static std::string make_absolute(const std::string &base_path, const std::string &relative_path, FilePathType path_type = FilePathType::file_system);
51 
54 
57 
59  static std::string location(const std::string &path);
60 
66  static bool is_absolute(const std::string &path, FilePathType path_type = FilePathType::file_system);
67 
73  static bool is_relative(const std::string &path, FilePathType path_type = FilePathType::file_system);
74 
85 
94 
101  static std::string remove_trailing_slash(const std::string &path);
102 
104  static std::string basepath(const std::string &path, FilePathType path_type = FilePathType::file_system);
105 
107  static std::string filename(const std::string &path, FilePathType path_type = FilePathType::file_system);
108 
111 
114 
116  static bool has_extension(const std::string &path, const std::string &extension, FilePathType path_type = FilePathType::file_system);
117 
122  static std::string combine(const std::string &part1, const std::string &part2, FilePathType path_type = FilePathType::file_system);
123  };
124 }
static std::string make_relative(const std::string &base_path, const std::string &absolute_path, FilePathType path_type=FilePathType::file_system)
Changes a path to be relative to the specified base path, if possible.
Native file system path. (On windows, '/' are turned into '\'. On linux, '\' are turned into '/') ...
static std::string add_trailing_slash(const std::string &path, FilePathType path_type=FilePathType::file_system)
Add trailing slash or backslash to path.
static std::string basepath(const std::string &path, FilePathType path_type=FilePathType::file_system)
Returns a new path with the last path component removed.
static std::string remove_trailing_slash(const std::string &path)
Remove trailing slash or backslash from path.
static std::string location(const std::string &path)
Returns the drive (C:) or share name ( \ \ computer \ share)
FilePathType
File path types.
Definition: path_help.h:36
Path helper functions.
Definition: path_help.h:46
static std::string combine(const std::string &part1, const std::string &part2, FilePathType path_type=FilePathType::file_system)
Concatenates two strings into one adding a trailing slash to first string if missing.
Path using slashes ('/').
static std::string extension(const std::string &path, FilePathType path_type=FilePathType::file_system)
Returns the extension part (includes the dot) of a path.
static bool has_extension(const std::string &path, const std::string &extension, FilePathType path_type=FilePathType::file_system)
Checks if the path has the specified extension.
static std::string filename(const std::string &path, FilePathType path_type=FilePathType::file_system)
Returns the filename part of a path.
static std::string absolute_path(std::string path)
Returns the absolute file system path for the given path.
static std::string filename_without_extension(const std::string &path, FilePathType path_type=FilePathType::file_system)
Returns the filename part without the extension.
static bool is_absolute(const std::string &path, FilePathType path_type=FilePathType::file_system)
Check if a path is absolute.
static std::string make_absolute(const std::string &base_path, const std::string &relative_path, FilePathType path_type=FilePathType::file_system)
Changes a path to be relative to the specified base path, if possible.
static std::string normalize(const std::string &path, FilePathType path_type=FilePathType::file_system)
Normalize a path.
Definition: Application/application.h:35
static bool is_relative(const std::string &path, FilePathType path_type=FilePathType::file_system)
Check if a path is relative.