diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2023-01-24 21:51:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-24 21:51:15 +0100 |
| commit | 4b2c00e239f44e79190cc156e4557ea4aaf64bd2 (patch) | |
| tree | 09ec8ac31ff935d63aa9c06004802156ac96ebf5 /Source/Core/Common | |
| parent | ba6ee9d7ba9730e5b2165ff0ee18cbc23762b129 (diff) | |
| parent | e5b91f00b0688d5cba6870da6d6ad3300097b07f (diff) | |
Merge pull request #11487 from lioncash/str
Common: Replace StringBeginsWith/StringEndsWith with std equivalents
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/ArmCPUDetect.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Common/Debug/CodeTrace.cpp | 18 | ||||
| -rw-r--r-- | Source/Core/Common/FileUtil.cpp | 4 | ||||
| -rw-r--r-- | Source/Core/Common/NandPaths.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Common/StringUtil.cpp | 10 | ||||
| -rw-r--r-- | Source/Core/Common/StringUtil.h | 2 |
6 files changed, 12 insertions, 26 deletions
diff --git a/Source/Core/Common/ArmCPUDetect.cpp b/Source/Core/Common/ArmCPUDetect.cpp index 43c0063f78..b55952cf2b 100644 --- a/Source/Core/Common/ArmCPUDetect.cpp +++ b/Source/Core/Common/ArmCPUDetect.cpp @@ -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) diff --git a/Source/Core/Common/Debug/CodeTrace.cpp b/Source/Core/Common/Debug/CodeTrace.cpp index 3eea7a72fc..d1cb913356 100644 --- a/Source/Core/Common/Debug/CodeTrace.cpp +++ b/Source/Core/Common/Debug/CodeTrace.cpp @@ -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; diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 983e7d21a0..dfb82712d7 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -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; diff --git a/Source/Core/Common/NandPaths.cpp b/Source/Core/Common/NandPaths.cpp index 00f5eb235a..9b08cd263d 100644 --- a/Source/Core/Common/NandPaths.cpp +++ b/Source/Core/Common/NandPaths.cpp @@ -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; } diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index c8d862e424..1bfb54e9f9 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -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) diff --git a/Source/Core/Common/StringUtil.h b/Source/Core/Common/StringUtil.h index 620d437f35..cb58f9fa25 100644 --- a/Source/Core/Common/StringUtil.h +++ b/Source/Core/Common/StringUtil.h @@ -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); |
