path_help.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib 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 ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 
30 #pragma once
31 
32 #include <vector>
33 
34 namespace clan
35 {
38 
40 class PathHelp
41 {
44 
45 public:
47  enum PathType
48  {
51 
54  };
55 
102  static std::string make_absolute(
103  const std::string &base_path,
104  const std::string &relative_path,
105  PathType path_type = path_type_file);
106 
126  static std::string make_relative(
127  const std::string &base_path,
128  const std::string &absolute_path,
129  PathType path_type = path_type_file);
130 
136  static bool is_absolute(
137  const std::string &path,
138  PathType path_type = path_type_file);
139 
145  static bool is_relative(
146  const std::string &path,
147  PathType path_type = path_type_file);
148 
158  static std::string normalize(
159  const std::string &path,
160  PathType path_type = path_type_file);
161 
169  static std::string add_trailing_slash(
170  const std::string &path,
171  PathType path_type = path_type_file);
172 
179  static std::string remove_trailing_slash(
180  const std::string &path);
181 
188  static std::string get_location(
189  const std::string &fullname,
190  PathType path_type = path_type_file);
191 
199  static std::string get_basepath(
200  const std::string &fullname,
201  PathType path_type = path_type_file);
202 
204 
207  static std::vector<std::string> split_basepath(
208  const std::string &fullname,
209  PathType path_type = path_type_file);
210 
212 
215  static std::string get_fullpath(
216  const std::string &fullname,
217  PathType path_type = path_type_file);
218 
220 
223  static std::string get_filename(
224  const std::string &fullname,
225  PathType path_type = path_type_file);
226 
228 
231  static std::string get_basename(
232  const std::string &fullname,
233  PathType path_type = path_type_file);
234 
236 
240  static std::string get_extension(
241  const std::string &fullname,
242  PathType path_type = path_type_file);
243 
245 
249  static std::string get_fullname(
250  const std::string &fullpath,
251  const std::string &filename,
252  PathType path_type = path_type_file);
253 
255 
260  static std::string get_fullname(
261  const std::string &fullpath,
262  const std::string &filename,
263  const std::string &extension,
264  PathType path_type = path_type_file);
265 
267 
273  static std::string get_fullname(
274  const std::string &location,
275  const std::string &basepath,
276  const std::string &filename,
277  const std::string &extension,
278  PathType path_type = path_type_file);
279 
284  static std::string combine(const std::string &part1, const std::string &part2, PathType path_type = path_type_file);
286 };
287 
288 }
289 
Path helper functions.
Definition: path_help.h:41
static std::string get_fullname(const std::string &fullpath, const std::string &filename, const std::string &extension, PathType path_type=path_type_file)
Create a fullname from parts.
static std::string add_trailing_slash(const std::string &path, PathType path_type=path_type_file)
Add trailing slash or backslash to path.
static std::string get_filename(const std::string &fullname, PathType path_type=path_type_file)
Returns the filename part of a fullname.
static std::string combine(const std::string &part1, const std::string &part2, PathType path_type=path_type_file)
Concatenates two strings into one adding a trailing slash to first string if missing.
static std::string remove_trailing_slash(const std::string &path)
Remove trailing slash or backslash from path.
static bool is_relative(const std::string &path, PathType path_type=path_type_file)
Check if a path is relative.
static std::string get_basename(const std::string &fullname, PathType path_type=path_type_file)
Returns the basename part of a fullname.
static std::string make_absolute(const std::string &base_path, const std::string &relative_path, PathType path_type=path_type_file)
Convert a relative path to an absolute path.
static std::string get_fullpath(const std::string &fullname, PathType path_type=path_type_file)
Returns the path including the location.
static std::string normalize(const std::string &path, PathType path_type=path_type_file)
Normalize a path.
static std::string make_relative(const std::string &base_path, const std::string &absolute_path, PathType path_type=path_type_file)
Converts an absolute path into a path relative to a base path.
static std::string get_location(const std::string &fullname, PathType path_type=path_type_file)
Returns the drive (C:) or share name ( \ \ computer \ share)
static std::string get_basepath(const std::string &fullname, PathType path_type=path_type_file)
Returns the path excluding the location and filename.
@ path_type_virtual
Path using slashes ('/').
Definition: path_help.h:53
Definition: clanapp.h:36
PathType
Path types.
Definition: path_help.h:48
static std::vector< std::string > split_basepath(const std::string &fullname, PathType path_type=path_type_file)
Splits the path, excluding the location, into parts.
static std::string get_fullname(const std::string &fullpath, const std::string &filename, PathType path_type=path_type_file)
Create a fullname from parts.
static std::string get_fullname(const std::string &location, const std::string &basepath, const std::string &filename, const std::string &extension, PathType path_type=path_type_file)
Create a fullname from parts.
static std::string get_extension(const std::string &fullname, PathType path_type=path_type_file)
Returns the extension part of a fullname.
static bool is_absolute(const std::string &path, PathType path_type=path_type_file)
Check if a path is absolute.
@ path_type_file
Native file system path. (On windows, '/' are turned into '\'. On linux, '\' are turned into '/')
Definition: path_help.h:50