StringUtil: StringPopBackIf added

This commit is contained in:
Sepalani 2017-06-06 05:08:51 +01:00
parent 1209959012
commit f28f23af1d
3 changed files with 13 additions and 8 deletions

View File

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

View File

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

View File

@ -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());
}