File: Path.h

package info (click to toggle)
pcsx2 2.6.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 89,232 kB
  • sloc: cpp: 386,254; ansic: 79,847; python: 1,216; perl: 391; javascript: 92; sh: 85; asm: 58; makefile: 20; xml: 13
file content (87 lines) | stat: -rw-r--r-- 3,625 bytes parent folder | download
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
// SPDX-FileCopyrightText: 2002-2025 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+

#pragma once

#include "common/Pcsx2Defs.h"

#include <string>
#include <string_view>
#include <vector>

namespace Path
{
	/// Converts any forward slashes to backslashes on Win32.
	std::string ToNativePath(const std::string_view path);
	void ToNativePath(std::string* path);

	/// Builds a path relative to the specified file
	std::string BuildRelativePath(const std::string_view filename, const std::string_view new_filename);

	/// Joins path components together, producing a new path.
	std::string Combine(const std::string_view base, const std::string_view next);

	/// Removes all .. and . components from a path.
	std::string Canonicalize(const std::string_view path);
	void Canonicalize(std::string* path);

	/// Sanitizes a filename for use in a filesystem.
	std::string SanitizeFileName(const std::string_view str, bool strip_slashes = true);
	void SanitizeFileName(std::string* str, bool strip_slashes = true);

	/// Returns true if the specified filename is valid on this operating system.
	bool IsValidFileName(const std::string_view str, bool allow_slashes = false);

	/// Returns true if the specified path is an absolute path (C:\Path on Windows or /path on Unix).
	bool IsAbsolute(const std::string_view path);

	/// Resolves any symbolic links in the specified path.
	std::string RealPath(const std::string_view path);

	/// Makes the specified path relative to another (e.g. /a/b/c, /a/b -> ../c).
	/// Both paths must be relative, otherwise this function will just return the input path.
	std::string MakeRelative(const std::string_view path, const std::string_view relative_to);

	/// Returns a view of the extension of a filename.
	std::string_view GetExtension(const std::string_view path);

	/// Removes the extension of a filename.
	std::string_view StripExtension(const std::string_view path);

	/// Replaces the extension of a filename with another.
	std::string ReplaceExtension(const std::string_view path, const std::string_view new_extension);

	/// Returns the directory component of a filename.
	std::string_view GetDirectory(const std::string_view path);

	/// Returns the filename component of a filename.
	std::string_view GetFileName(const std::string_view path);

	/// Returns the file title (less the extension and path) from a filename.
	std::string_view GetFileTitle(const std::string_view path);

	/// Changes the filename in a path.
	std::string ChangeFileName(const std::string_view path, const std::string_view new_filename);
	void ChangeFileName(std::string* path, const std::string_view new_filename);

	/// Appends a directory to a path.
	std::string AppendDirectory(const std::string_view path, const std::string_view new_dir);
	void AppendDirectory(std::string* path, const std::string_view new_dir);

	/// Splits a path into its components, handling both Windows and Unix separators.
	std::vector<std::string_view> SplitWindowsPath(const std::string_view path);
	std::string JoinWindowsPath(const std::vector<std::string_view>& components);

	/// Splits a path into its components, only handling native separators.
	std::vector<std::string_view> SplitNativePath(const std::string_view path);
	std::string JoinNativePath(const std::vector<std::string_view>& components);

	/// URL encodes the specified string.
	std::string URLEncode(std::string_view str);

	/// Decodes the specified escaped string.
	std::string URLDecode(std::string_view str);

	/// Returns a URL for a given path. The path should be absolute.
	std::string CreateFileURL(std::string_view path);
} // namespace Path