From f28f23af1d613670c1ed5fc28e826544f5494333 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Tue, 6 Jun 2017 05:08:51 +0100 Subject: [PATCH] StringUtil: StringPopBackIf added --- Source/Core/Common/StringUtil.cpp | 6 ++++++ Source/Core/Common/StringUtil.h | 1 + Source/Core/Core/HLE/HLE_OS.cpp | 14 ++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 80c74ac8a7..6548205fb0 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -405,6 +405,12 @@ bool StringEndsWith(const std::string& str, const std::string& 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) + s->pop_back(); +} + #ifdef _WIN32 std::string UTF16ToUTF8(const std::wstring& input) diff --git a/Source/Core/Common/StringUtil.h b/Source/Core/Common/StringUtil.h index 3ea288bb4d..86d7ba1e9c 100644 --- a/Source/Core/Common/StringUtil.h +++ b/Source/Core/Common/StringUtil.h @@ -119,6 +119,7 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st bool StringBeginsWith(const std::string& str, const std::string& begin); bool StringEndsWith(const std::string& str, const std::string& end); +void StringPopBackIf(std::string* s, char c); std::string CP1252ToUTF8(const std::string& str); std::string SHIFTJISToUTF8(const std::string& str); diff --git a/Source/Core/Core/HLE/HLE_OS.cpp b/Source/Core/Core/HLE/HLE_OS.cpp index abe2876db4..12a5ec1370 100644 --- a/Source/Core/Core/HLE/HLE_OS.cpp +++ b/Source/Core/Core/HLE/HLE_OS.cpp @@ -33,10 +33,8 @@ void HLE_OSPanic() std::string error = GetStringVA(); std::string msg = GetStringVA(5); - if (!error.empty() && error.back() == '\n') - error.pop_back(); - if (!msg.empty() && msg.back() == '\n') - msg.pop_back(); + StringPopBackIf(&error, '\n'); + StringPopBackIf(&msg, '\n'); PanicAlert("OSPanic: %s: %s", error.c_str(), msg.c_str()); ERROR_LOG(OSREPORT, "%08x->%08x| OSPanic: %s: %s", LR, PC, error.c_str(), msg.c_str()); @@ -77,8 +75,7 @@ void HLE_GeneralDebugPrint(ParameterType parameter_type) } } - if (!report_message.empty() && report_message.back() == '\n') - report_message.pop_back(); + StringPopBackIf(&report_message, '\n'); NPC = LR; @@ -116,8 +113,7 @@ void HLE_write_console() ERROR_LOG(OSREPORT, "__write_console uses an unreachable size pointer"); } - if (!report_message.empty() && report_message.back() == '\n') - report_message.pop_back(); + StringPopBackIf(&report_message, '\n'); NPC = LR; @@ -133,6 +129,7 @@ void HLE_LogDPrint(ParameterType parameter_type) return; std::string report_message = GetStringVA(4, parameter_type); + StringPopBackIf(&report_message, '\n'); NOTICE_LOG(OSREPORT, "%08x->%08x| %s", LR, PC, SHIFTJISToUTF8(report_message).c_str()); } @@ -172,6 +169,7 @@ void HLE_LogFPrint(ParameterType parameter_type) return; std::string report_message = GetStringVA(4, parameter_type); + StringPopBackIf(&report_message, '\n'); NOTICE_LOG(OSREPORT, "%08x->%08x| %s", LR, PC, SHIFTJISToUTF8(report_message).c_str()); }