Misc: Pass string_view by value
This commit is contained in:
@ -976,7 +976,7 @@ bool ByteStream::WriteS64(s64 dest)
|
||||
return Write2(&dest, sizeof(s64));
|
||||
}
|
||||
|
||||
bool ByteStream::WriteSizePrefixedString(const std::string_view& str)
|
||||
bool ByteStream::WriteSizePrefixedString(std::string_view str)
|
||||
{
|
||||
const u32 size = static_cast<u32>(str.size());
|
||||
return (Write2(&size, sizeof(size)) && (size == 0 || Write2(str.data(), size)));
|
||||
@ -1315,7 +1315,7 @@ std::string ByteStream::ReadStreamToString(ByteStream* stream, bool seek_to_star
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ByteStream::WriteStreamToString(const std::string_view& sv, ByteStream* stream)
|
||||
bool ByteStream::WriteStreamToString(std::string_view sv, ByteStream* stream)
|
||||
{
|
||||
if (sv.size() > std::numeric_limits<u32>::max())
|
||||
return false;
|
||||
|
||||
@ -102,7 +102,7 @@ public:
|
||||
bool WriteS16(s16 dest);
|
||||
bool WriteS32(s32 dest);
|
||||
bool WriteS64(s64 dest);
|
||||
bool WriteSizePrefixedString(const std::string_view& str);
|
||||
bool WriteSizePrefixedString(std::string_view str);
|
||||
|
||||
// base byte stream creation functions
|
||||
// opens a local file-based stream. fills in error if passed, and returns false if the file cannot be opened.
|
||||
@ -139,7 +139,7 @@ public:
|
||||
static u32 CopyBytes(ByteStream* pSourceStream, u32 byteCount, ByteStream* pDestinationStream);
|
||||
|
||||
static std::string ReadStreamToString(ByteStream* stream, bool seek_to_start = true);
|
||||
static bool WriteStreamToString(const std::string_view& sv, ByteStream* stream);
|
||||
static bool WriteStreamToString(std::string_view sv, ByteStream* stream);
|
||||
|
||||
static std::vector<u8> ReadBinaryStream(ByteStream* stream, bool seek_to_start = true);
|
||||
static bool WriteBinaryToStream(ByteStream* stream, const void* data, size_t data_length);
|
||||
|
||||
@ -13,7 +13,7 @@ class Error;
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
namespace CocoaTools {
|
||||
NSString* StringViewToNSString(const std::string_view& str);
|
||||
NSString* StringViewToNSString(std::string_view str);
|
||||
|
||||
/// Converts NSError to a human-readable string.
|
||||
std::string NSErrorToString(NSError* error);
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
#error ARC should not be enabled.
|
||||
#endif
|
||||
|
||||
NSString* CocoaTools::StringViewToNSString(const std::string_view& str)
|
||||
NSString* CocoaTools::StringViewToNSString(std::string_view str)
|
||||
{
|
||||
if (str.empty())
|
||||
return nil;
|
||||
|
||||
@ -176,7 +176,7 @@ bool CrashHandler::Install()
|
||||
return (s_veh_handle != nullptr);
|
||||
}
|
||||
|
||||
void CrashHandler::SetWriteDirectory(const std::string_view& dump_directory)
|
||||
void CrashHandler::SetWriteDirectory(std::string_view dump_directory)
|
||||
{
|
||||
if (!s_veh_handle)
|
||||
return;
|
||||
@ -384,7 +384,7 @@ bool CrashHandler::Install()
|
||||
return true;
|
||||
}
|
||||
|
||||
void CrashHandler::SetWriteDirectory(const std::string_view& dump_directory)
|
||||
void CrashHandler::SetWriteDirectory(std::string_view dump_directory)
|
||||
{
|
||||
}
|
||||
|
||||
@ -404,7 +404,7 @@ bool CrashHandler::Install()
|
||||
return false;
|
||||
}
|
||||
|
||||
void CrashHandler::SetWriteDirectory(const std::string_view& dump_directory)
|
||||
void CrashHandler::SetWriteDirectory(std::string_view dump_directory)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
namespace CrashHandler {
|
||||
bool Install();
|
||||
void SetWriteDirectory(const std::string_view& dump_directory);
|
||||
void SetWriteDirectory(std::string_view dump_directory);
|
||||
void WriteDumpForCaller();
|
||||
void Uninstall();
|
||||
} // namespace CrashHandler
|
||||
|
||||
@ -135,7 +135,7 @@ static inline void PathAppendString(std::string& dst, const T& src)
|
||||
}
|
||||
}
|
||||
|
||||
std::string Path::SanitizeFileName(const std::string_view& str, bool strip_slashes /* = true */)
|
||||
std::string Path::SanitizeFileName(std::string_view str, bool strip_slashes /* = true */)
|
||||
{
|
||||
std::string ret;
|
||||
ret.reserve(str.length());
|
||||
@ -283,7 +283,7 @@ std::wstring FileSystem::GetWin32Path(std::string_view str)
|
||||
|
||||
#endif
|
||||
|
||||
bool Path::IsAbsolute(const std::string_view& path)
|
||||
bool Path::IsAbsolute(std::string_view path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return (path.length() >= 3 && ((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z')) &&
|
||||
@ -294,7 +294,7 @@ bool Path::IsAbsolute(const std::string_view& path)
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string Path::RealPath(const std::string_view& path)
|
||||
std::string Path::RealPath(std::string_view path)
|
||||
{
|
||||
// Resolve non-absolute paths first.
|
||||
std::vector<std::string_view> components;
|
||||
@ -472,7 +472,7 @@ std::string Path::RealPath(const std::string_view& path)
|
||||
return realpath;
|
||||
}
|
||||
|
||||
std::string Path::ToNativePath(const std::string_view& path)
|
||||
std::string Path::ToNativePath(std::string_view path)
|
||||
{
|
||||
std::string ret;
|
||||
PathAppendString(ret, path);
|
||||
@ -492,7 +492,7 @@ void Path::ToNativePath(std::string* path)
|
||||
*path = Path::ToNativePath(*path);
|
||||
}
|
||||
|
||||
std::string Path::Canonicalize(const std::string_view& path)
|
||||
std::string Path::Canonicalize(std::string_view path)
|
||||
{
|
||||
std::vector<std::string_view> components = Path::SplitNativePath(path);
|
||||
std::vector<std::string_view> new_components;
|
||||
@ -528,7 +528,7 @@ void Path::Canonicalize(std::string* path)
|
||||
*path = Canonicalize(*path);
|
||||
}
|
||||
|
||||
std::string Path::MakeRelative(const std::string_view& path, const std::string_view& relative_to)
|
||||
std::string Path::MakeRelative(std::string_view path, std::string_view relative_to)
|
||||
{
|
||||
// simple algorithm, we just work on the components. could probably be better, but it'll do for now.
|
||||
std::vector<std::string_view> path_components(SplitNativePath(path));
|
||||
@ -575,7 +575,7 @@ std::string Path::MakeRelative(const std::string_view& path, const std::string_v
|
||||
return JoinNativePath(new_components);
|
||||
}
|
||||
|
||||
std::string_view Path::GetExtension(const std::string_view& path)
|
||||
std::string_view Path::GetExtension(std::string_view path)
|
||||
{
|
||||
const std::string_view::size_type pos = path.rfind('.');
|
||||
if (pos == std::string_view::npos)
|
||||
@ -584,7 +584,7 @@ std::string_view Path::GetExtension(const std::string_view& path)
|
||||
return path.substr(pos + 1);
|
||||
}
|
||||
|
||||
std::string_view Path::StripExtension(const std::string_view& path)
|
||||
std::string_view Path::StripExtension(std::string_view path)
|
||||
{
|
||||
const std::string_view::size_type pos = path.rfind('.');
|
||||
if (pos == std::string_view::npos)
|
||||
@ -593,7 +593,7 @@ std::string_view Path::StripExtension(const std::string_view& path)
|
||||
return path.substr(0, pos);
|
||||
}
|
||||
|
||||
std::string Path::ReplaceExtension(const std::string_view& path, const std::string_view& new_extension)
|
||||
std::string Path::ReplaceExtension(std::string_view path, std::string_view new_extension)
|
||||
{
|
||||
const std::string_view::size_type pos = path.rfind('.');
|
||||
if (pos == std::string_view::npos)
|
||||
@ -604,7 +604,7 @@ std::string Path::ReplaceExtension(const std::string_view& path, const std::stri
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::string_view::size_type GetLastSeperatorPosition(const std::string_view& filename, bool include_separator)
|
||||
static std::string_view::size_type GetLastSeperatorPosition(std::string_view filename, bool include_separator)
|
||||
{
|
||||
std::string_view::size_type last_separator = filename.rfind('/');
|
||||
if (include_separator && last_separator != std::string_view::npos)
|
||||
@ -624,12 +624,12 @@ static std::string_view::size_type GetLastSeperatorPosition(const std::string_vi
|
||||
return last_separator;
|
||||
}
|
||||
|
||||
std::string FileSystem::GetDisplayNameFromPath(const std::string_view& path)
|
||||
std::string FileSystem::GetDisplayNameFromPath(std::string_view path)
|
||||
{
|
||||
return std::string(Path::GetFileName(path));
|
||||
}
|
||||
|
||||
std::string_view Path::GetDirectory(const std::string_view& path)
|
||||
std::string_view Path::GetDirectory(std::string_view path)
|
||||
{
|
||||
const std::string::size_type pos = GetLastSeperatorPosition(path, false);
|
||||
if (pos == std::string_view::npos)
|
||||
@ -638,7 +638,7 @@ std::string_view Path::GetDirectory(const std::string_view& path)
|
||||
return path.substr(0, pos);
|
||||
}
|
||||
|
||||
std::string_view Path::GetFileName(const std::string_view& path)
|
||||
std::string_view Path::GetFileName(std::string_view path)
|
||||
{
|
||||
const std::string_view::size_type pos = GetLastSeperatorPosition(path, true);
|
||||
if (pos == std::string_view::npos)
|
||||
@ -647,7 +647,7 @@ std::string_view Path::GetFileName(const std::string_view& path)
|
||||
return path.substr(pos);
|
||||
}
|
||||
|
||||
std::string_view Path::GetFileTitle(const std::string_view& path)
|
||||
std::string_view Path::GetFileTitle(std::string_view path)
|
||||
{
|
||||
const std::string_view filename(GetFileName(path));
|
||||
const std::string::size_type pos = filename.rfind('.');
|
||||
@ -657,7 +657,7 @@ std::string_view Path::GetFileTitle(const std::string_view& path)
|
||||
return filename.substr(0, pos);
|
||||
}
|
||||
|
||||
std::string Path::ChangeFileName(const std::string_view& path, const std::string_view& new_filename)
|
||||
std::string Path::ChangeFileName(std::string_view path, std::string_view new_filename)
|
||||
{
|
||||
std::string ret;
|
||||
PathAppendString(ret, path);
|
||||
@ -684,12 +684,12 @@ std::string Path::ChangeFileName(const std::string_view& path, const std::string
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Path::ChangeFileName(std::string* path, const std::string_view& new_filename)
|
||||
void Path::ChangeFileName(std::string* path, std::string_view new_filename)
|
||||
{
|
||||
*path = ChangeFileName(*path, new_filename);
|
||||
}
|
||||
|
||||
std::string Path::AppendDirectory(const std::string_view& path, const std::string_view& new_dir)
|
||||
std::string Path::AppendDirectory(std::string_view path, std::string_view new_dir)
|
||||
{
|
||||
std::string ret;
|
||||
if (!new_dir.empty())
|
||||
@ -731,12 +731,12 @@ std::string Path::AppendDirectory(const std::string_view& path, const std::strin
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Path::AppendDirectory(std::string* path, const std::string_view& new_dir)
|
||||
void Path::AppendDirectory(std::string* path, std::string_view new_dir)
|
||||
{
|
||||
*path = AppendDirectory(*path, new_dir);
|
||||
}
|
||||
|
||||
std::vector<std::string_view> Path::SplitWindowsPath(const std::string_view& path)
|
||||
std::vector<std::string_view> Path::SplitWindowsPath(std::string_view path)
|
||||
{
|
||||
std::vector<std::string_view> parts;
|
||||
|
||||
@ -774,7 +774,7 @@ std::string Path::JoinWindowsPath(const std::vector<std::string_view>& component
|
||||
return StringUtil::JoinString(components.begin(), components.end(), '\\');
|
||||
}
|
||||
|
||||
std::vector<std::string_view> Path::SplitNativePath(const std::string_view& path)
|
||||
std::vector<std::string_view> Path::SplitNativePath(std::string_view path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return SplitWindowsPath(path);
|
||||
@ -841,7 +841,7 @@ std::vector<std::string> FileSystem::GetRootDirectoryList()
|
||||
return results;
|
||||
}
|
||||
|
||||
std::string Path::BuildRelativePath(const std::string_view& filename, const std::string_view& new_filename)
|
||||
std::string Path::BuildRelativePath(std::string_view filename, std::string_view new_filename)
|
||||
{
|
||||
std::string new_string;
|
||||
|
||||
@ -852,7 +852,7 @@ std::string Path::BuildRelativePath(const std::string_view& filename, const std:
|
||||
return new_string;
|
||||
}
|
||||
|
||||
std::string Path::Combine(const std::string_view& base, const std::string_view& next)
|
||||
std::string Path::Combine(std::string_view base, std::string_view next)
|
||||
{
|
||||
std::string ret;
|
||||
ret.reserve(base.length() + next.length() + 1);
|
||||
@ -1193,7 +1193,7 @@ bool FileSystem::WriteBinaryFile(const char* filename, const void* data, size_t
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileSystem::WriteStringToFile(const char* filename, const std::string_view& sv)
|
||||
bool FileSystem::WriteStringToFile(const char* filename, std::string_view sv)
|
||||
{
|
||||
ManagedCFilePtr fp = OpenManagedCFile(filename, "wb");
|
||||
if (!fp)
|
||||
|
||||
@ -61,7 +61,7 @@ namespace FileSystem {
|
||||
using FindResultsArray = std::vector<FILESYSTEM_FIND_DATA>;
|
||||
|
||||
/// Returns the display name of a filename. Usually this is the same as the path.
|
||||
std::string GetDisplayNameFromPath(const std::string_view& path);
|
||||
std::string GetDisplayNameFromPath(std::string_view path);
|
||||
|
||||
/// Returns a list of "root directories" (i.e. root/home directories on Linux, drive letters on Windows).
|
||||
std::vector<std::string> GetRootDirectoryList();
|
||||
@ -145,7 +145,7 @@ std::optional<std::vector<u8>> ReadBinaryFile(std::FILE* fp);
|
||||
std::optional<std::string> ReadFileToString(const char* filename, Error* error = nullptr);
|
||||
std::optional<std::string> ReadFileToString(std::FILE* fp);
|
||||
bool WriteBinaryFile(const char* filename, const void* data, size_t data_length);
|
||||
bool WriteStringToFile(const char* filename, const std::string_view& sv);
|
||||
bool WriteStringToFile(const char* filename, std::string_view sv);
|
||||
|
||||
/// creates a directory in the local filesystem
|
||||
/// if the directory already exists, the return value will be true.
|
||||
|
||||
@ -276,7 +276,7 @@ void Log::ConsoleOutputLogCallback(void* pUserParam, const char* channelName, co
|
||||
});
|
||||
#elif !defined(__ANDROID__)
|
||||
FormatLogMessageAndPrint(channelName, functionName, level, message, s_console_output_timestamps, true, true,
|
||||
[level](const std::string_view& message) {
|
||||
[level](std::string_view message) {
|
||||
const int outputFd = (level <= LOGLEVEL_WARNING) ? STDERR_FILENO : STDOUT_FILENO;
|
||||
write(outputFd, message.data(), message.length());
|
||||
});
|
||||
@ -413,9 +413,9 @@ void Log::FileOutputLogCallback(void* pUserParam, const char* channelName, const
|
||||
if (!s_file_output_enabled)
|
||||
return;
|
||||
|
||||
FormatLogMessageAndPrint(
|
||||
channelName, functionName, level, message, true, false, true,
|
||||
[](const std::string_view& message) { std::fwrite(message.data(), 1, message.size(), s_file_handle.get()); });
|
||||
FormatLogMessageAndPrint(channelName, functionName, level, message, true, false, true, [](std::string_view message) {
|
||||
std::fwrite(message.data(), 1, message.size(), s_file_handle.get());
|
||||
});
|
||||
}
|
||||
|
||||
void Log::SetFileOutputParams(bool enabled, const char* filename, bool timestamps /* = true */)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
@ -11,21 +11,21 @@
|
||||
|
||||
namespace Path {
|
||||
/// Converts any forward slashes to backslashes on Win32.
|
||||
std::string ToNativePath(const std::string_view& path);
|
||||
std::string ToNativePath(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);
|
||||
std::string BuildRelativePath(std::string_view filename, 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);
|
||||
std::string Combine(std::string_view base, std::string_view next);
|
||||
|
||||
/// Removes all .. and . components from a path.
|
||||
std::string Canonicalize(const std::string_view& path);
|
||||
std::string Canonicalize(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);
|
||||
std::string SanitizeFileName(std::string_view str, bool strip_slashes = true);
|
||||
void SanitizeFileName(std::string* str, bool strip_slashes = true);
|
||||
|
||||
/// Mutates the path to remove any MAX_PATH limits (for Windows).
|
||||
@ -33,47 +33,47 @@ std::string RemoveLengthLimits(std::string_view str);
|
||||
void RemoveLengthLimits(std::string* path);
|
||||
|
||||
/// 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);
|
||||
bool IsAbsolute(std::string_view path);
|
||||
|
||||
/// Resolves any symbolic links in the specified path.
|
||||
std::string RealPath(const std::string_view& path);
|
||||
std::string RealPath(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);
|
||||
std::string MakeRelative(std::string_view path, std::string_view relative_to);
|
||||
|
||||
/// Returns a view of the extension of a filename.
|
||||
std::string_view GetExtension(const std::string_view& path);
|
||||
std::string_view GetExtension(std::string_view path);
|
||||
|
||||
/// Removes the extension of a filename.
|
||||
std::string_view StripExtension(const std::string_view& path);
|
||||
std::string_view StripExtension(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);
|
||||
std::string ReplaceExtension(std::string_view path, std::string_view new_extension);
|
||||
|
||||
/// Returns the directory component of a filename.
|
||||
std::string_view GetDirectory(const std::string_view& path);
|
||||
std::string_view GetDirectory(std::string_view path);
|
||||
|
||||
/// Returns the filename component of a filename.
|
||||
std::string_view GetFileName(const std::string_view& path);
|
||||
std::string_view GetFileName(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);
|
||||
std::string_view GetFileTitle(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);
|
||||
std::string ChangeFileName(std::string_view path, std::string_view new_filename);
|
||||
void ChangeFileName(std::string* path, 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);
|
||||
std::string AppendDirectory(std::string_view path, std::string_view new_dir);
|
||||
void AppendDirectory(std::string* path, 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::vector<std::string_view> SplitWindowsPath(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::vector<std::string_view> SplitNativePath(std::string_view path);
|
||||
std::string JoinNativePath(const std::vector<std::string_view>& components);
|
||||
|
||||
/// URL encodes the specified string.
|
||||
|
||||
Reference in New Issue
Block a user