pcsx2/common/Path.h

88 lines
3.6 KiB
C
Raw Normal View History

// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-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);
2023-12-10 15:47:14 +00:00
/// 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);
2024-03-13 09:51:44 +00:00
/// 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);
Common: reformat (#4720) * common: format AlignedMalloc.cpp * common: format AppTrait.h * common: format Assertions.h * common: format CheckedStaticBox * common: format Console * common: format Dependencies.h * common: format EmbeddedImage * common: format EventSource * common: format Exceptions * common: format FastFormatString.cpp * common: format General.h * common: format InitInterface * common: format MathUtils.h * common: format MemsetFast/MemcpyFast * common: format Mutex.cpp * common: format PageFaultSource.h * common: format Path.h * common: format PathUtils.cpp * common: format Pcsx2Types.h * common: format Perf * common: format PersistentThread.h * common: format RwMutex * common: format SafeArray * common: format ScopedAlloc.h * common: format ScopedPtrMT.h * common: format Semaphore.cpp * common: format StringHelpers * common: format ThreadTools.cpp * common: format Threading.h * common: format ThreadingDialogs * common: format ThreadingInternal.h * common: format TraceLog.h * common: format VirtualMemory.cpp * common: format pxCheckBox * common: format pxEvents.h * common: format pxForwardDefs.h * common: format pxRadioPanel * common: format pxStaticText * common: format pxStreams * common: format pxTranslate.cpp * common: format pxWindowTextWriter.cpp * common: format wxAppWithHelpers * common: format wxBaseTools.h * common: format wxGuiTools * common: format wxHelpers.cpp * common: format Darwin directory * common: format Linux directory * common: format Windows directory * common: format LnxCpuDetect.cpp * common: format WinCpuDetect.cpp * common: format bmi.cpp * common: format cpudetect.cpp * common: format cpu_detect_internal.h * common: format fpu.cpp * common: format groups.cpp * common: format instructions.h * common: format internal.h * common: format jmp.cpp * common: format legacy.cpp * common: format legacy_instructions.h * common: format legacy_internal.h * common: format movs.cpp * common: format simd.cpp * common: format tools.h * common: format x86emitter.cpp * common: format x86types.h * common: format bmi.h * common: format dwshift.h * common: format group1.h group2.h group3.h * common: format incdec.h * common: format jmpcall.h * common: format movs.h * common: format simd_arithmetic.h * common: format simd_comparisons.h * common: format simd_helpers.h * common: format simd_moremovs.h * common: format simd_shufflepack.h * common: format simd_templated_helpers.h * common: format test.h
2021-09-06 18:28:26 +00:00
} // namespace Path