File: path.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (110 lines) | stat: -rw-r--r-- 4,625 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

//=============================================================================
//
// Platform-independent Path functions
//
//=============================================================================

#ifndef AGS_SHARED_UTIL_PATH_H
#define AGS_SHARED_UTIL_PATH_H

#include "ags/shared/util/string.h"

#define PATH_ALT_SEPARATOR ('\\')

namespace AGS3 {
namespace AGS {
namespace Shared {

namespace Path {

// Get a filename from a path
String get_filename(const String &path);
// Get an extension from a filename
String get_extension(const String &path);

// Returns parent directory of the given path;
// returns "." (current dir) if the path does not contain a parent segment
String  GetParent(const String &path);
// Returns parent directory of the given path;
// returns "." (current dir) if the path does not contain a parent segment
String  GetFilename(const String &path);
// Returns file's extension; file may be a fully qualified path too
String  GetFileExtension(const String &path);

// Makes a platform-dependant path comparison.
// This takes into consideration platform's filename case (in)sensivity and
// DOS-compatible 8.3 filenames;
// The result value corresponds to stdlib strcmp function.
int     ComparePaths(const String &path1, const String &path2);

// Returns path to the actual directory, referenced by given path;
// if path is a directory, returns path unchanged, if path is a file, returns
// parent directory containing that file.
String  GetDirectoryPath(const String &path);
// Tells if the path points to the parent path's location or lower directory;
// return FALSE if the path points to outside of the parent location.
bool    IsSameOrSubDir(const String &parent, const String &path);
// Tells if the path is relative.
bool    IsRelativePath(const String &path);

// Makes a path have only '/' slashes; this is to make it easier to work
// with path, knowing it contains only one type of directory separators
void    FixupPath(String &path);
// Fixups path and removes trailing slash
String  MakePathNoSlash(const String &path);
// Fixups path and adds trailing slash if it's missing
String  MakeTrailingSlash(const String &path);
// Converts any path to an absolute path; relative paths are assumed to
// refer to the current working directory.
String  MakeAbsolutePath(const String &path);
// Tries to create a relative path that would point to 'path' location
// if walking out of the 'base'. Returns empty string on failure.
// NOTE: the 'base' is only considered a directory if it has a trailing slash.
String  MakeRelativePath(const String &base, const String &path);
// Creates path by combining directory, file name and extension
String  MakePath(const String &parent, const String &filename, const String &ext);
// Appends another section to existing path
String  &AppendPath(String &path, const String &child);
// Concatenates parent and relative paths
String  ConcatPaths(const String &parent, const String &child);
String  ConcatPaths(String &buf, const String &parent, const String &child);
// Splits path into components, divided by path separator
std::vector<String> Split(const String &path);

// Subsitutes illegal characters with '_'. This function uses a combined set
// of illegal chars from all the supported platforms to make a name that
// could be copied across systems without problems.
String  FixupSharedFilename(const String &filename);

// Converts filepath into ASCII variant; returns empty string on failure
String  GetPathInASCII(const String &path);
// Converts filepath from command line's argument into ASCII variant
String  GetCmdLinePathInASCII(const char *arg, int arg_index);
} // namespace Path

} // namespace Shared
} // namespace AGS
} // namespace AGS3

#endif