mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Common: Replace StringBeginsWith/StringEndsWith with std equivalents
Obsoletes these functions in favor of the standard member functions added in C++20.
This commit is contained in:
@ -107,7 +107,7 @@ static std::string ReadCpuinfoField(const std::string& field)
|
||||
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
if (!StringBeginsWith(line, field))
|
||||
if (!line.starts_with(field))
|
||||
continue;
|
||||
auto non_tab = line.find_first_not_of("\t", field.length());
|
||||
if (non_tab == line.npos)
|
||||
|
@ -3,11 +3,11 @@
|
||||
|
||||
#include "Common/Debug/CodeTrace.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <regex>
|
||||
|
||||
#include "Common/Event.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Core/Debugger/PPCDebugInterface.h"
|
||||
#include "Core/HW/CPU.h"
|
||||
#include "Core/PowerPC/PowerPC.h"
|
||||
@ -16,9 +16,8 @@ namespace
|
||||
{
|
||||
bool IsInstructionLoadStore(std::string_view ins)
|
||||
{
|
||||
return (StringBeginsWith(ins, "l") && !StringBeginsWith(ins, "li")) ||
|
||||
StringBeginsWith(ins, "st") || StringBeginsWith(ins, "psq_l") ||
|
||||
StringBeginsWith(ins, "psq_s");
|
||||
return (ins.starts_with('l') && !ins.starts_with("li")) || ins.starts_with("st") ||
|
||||
ins.starts_with("psq_l") || ins.starts_with("psq_s");
|
||||
}
|
||||
|
||||
u32 GetMemoryTargetSize(std::string_view instr)
|
||||
@ -95,7 +94,7 @@ InstructionAttributes CodeTrace::GetInstructionAttributes(const TraceOutput& ins
|
||||
tmp_attributes.memory_target = instruction.memory_target;
|
||||
tmp_attributes.memory_target_size = GetMemoryTargetSize(instr);
|
||||
|
||||
if (StringBeginsWith(instr, "st") || StringBeginsWith(instr, "psq_s"))
|
||||
if (instr.starts_with("st") || instr.starts_with("psq_s"))
|
||||
tmp_attributes.is_store = true;
|
||||
else
|
||||
tmp_attributes.is_load = true;
|
||||
@ -263,9 +262,8 @@ HitType CodeTrace::TraceLogic(const TraceOutput& current_instr, bool first_hit)
|
||||
|
||||
// Checks if the intstruction is a type that needs special handling.
|
||||
const auto CompareInstruction = [](std::string_view instruction, const auto& type_compare) {
|
||||
return std::any_of(
|
||||
type_compare.begin(), type_compare.end(),
|
||||
[&instruction](std::string_view s) { return StringBeginsWith(instruction, s); });
|
||||
return std::any_of(type_compare.begin(), type_compare.end(),
|
||||
[&instruction](std::string_view s) { return instruction.starts_with(s); });
|
||||
};
|
||||
|
||||
// Exclusions from updating tracking logic. mt operations are too complex and specialized.
|
||||
@ -280,12 +278,12 @@ HitType CodeTrace::TraceLogic(const TraceOutput& current_instr, bool first_hit)
|
||||
static const std::array<std::string_view, 2> mover{"mr", "fmr"};
|
||||
|
||||
// Link register for when r0 gets overwritten
|
||||
if (StringBeginsWith(instr.instruction, "mflr") && match_reg0)
|
||||
if (instr.instruction.starts_with("mflr") && match_reg0)
|
||||
{
|
||||
m_reg_autotrack.erase(reg_itr);
|
||||
return HitType::OVERWRITE;
|
||||
}
|
||||
else if (StringBeginsWith(instr.instruction, "mtlr") && match_reg0)
|
||||
if (instr.instruction.starts_with("mtlr") && match_reg0)
|
||||
{
|
||||
// LR is not something tracked
|
||||
return HitType::MOVED;
|
||||
|
@ -171,7 +171,7 @@ bool Delete(const std::string& filename, IfAbsentBehavior behavior)
|
||||
DEBUG_LOG_FMT(COMMON, "Delete: file {}", filename);
|
||||
|
||||
#ifdef ANDROID
|
||||
if (StringBeginsWith(filename, "content://"))
|
||||
if (filename.starts_with("content://"))
|
||||
{
|
||||
const bool success = DeleteAndroidContent(filename);
|
||||
if (!success)
|
||||
@ -1054,7 +1054,7 @@ void SetUserPath(unsigned int dir_index, std::string path)
|
||||
#endif
|
||||
|
||||
// Directories should end with a separator, files should not.
|
||||
while (StringEndsWith(path, "/"))
|
||||
while (path.ends_with('/'))
|
||||
path.pop_back();
|
||||
if (path.empty())
|
||||
return;
|
||||
|
@ -76,7 +76,7 @@ std::string GetMiiDatabasePath(std::optional<FromWhichRoot> from)
|
||||
bool IsTitlePath(const std::string& path, std::optional<FromWhichRoot> from, u64* title_id)
|
||||
{
|
||||
std::string expected_prefix = RootUserPath(from) + "/title/";
|
||||
if (!StringBeginsWith(path, expected_prefix))
|
||||
if (!path.starts_with(expected_prefix))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -431,16 +431,6 @@ std::string ReplaceAll(std::string result, std::string_view src, std::string_vie
|
||||
return result;
|
||||
}
|
||||
|
||||
bool StringBeginsWith(std::string_view str, std::string_view begin)
|
||||
{
|
||||
return str.size() >= begin.size() && std::equal(begin.begin(), begin.end(), str.begin());
|
||||
}
|
||||
|
||||
bool StringEndsWith(std::string_view str, std::string_view end)
|
||||
{
|
||||
return str.size() >= end.size() && std::equal(end.rbegin(), end.rend(), str.rbegin());
|
||||
}
|
||||
|
||||
void StringPopBackIf(std::string* s, char c)
|
||||
{
|
||||
if (!s->empty() && s->back() == c)
|
||||
|
@ -169,8 +169,6 @@ std::string WithUnifiedPathSeparators(std::string path);
|
||||
// This requires forward slashes to be used for the path separators, even on Windows.
|
||||
std::string PathToFileName(std::string_view path);
|
||||
|
||||
bool StringBeginsWith(std::string_view str, std::string_view begin);
|
||||
bool StringEndsWith(std::string_view str, std::string_view end);
|
||||
void StringPopBackIf(std::string* s, char c);
|
||||
size_t StringUTF8CodePointCount(const std::string& str);
|
||||
|
||||
|
Reference in New Issue
Block a user