Misc: Pass string_view by value

This commit is contained in:
Stenzek
2024-05-05 20:21:54 +10:00
parent e4d940a476
commit ca3cfbaa99
111 changed files with 543 additions and 542 deletions

View File

@ -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)