diff --git a/Common/GPU/OpenGL/GLFeatures.cpp b/Common/GPU/OpenGL/GLFeatures.cpp index 32e1aba67d..5a603aabe0 100644 --- a/Common/GPU/OpenGL/GLFeatures.cpp +++ b/Common/GPU/OpenGL/GLFeatures.cpp @@ -162,7 +162,7 @@ bool CheckGLExtensions() { const char *cvendor = (char *)glGetString(GL_VENDOR); // TODO: move this stuff to gpu_features.cpp if (cvendor) { - const std::string vendor = StripSpaces(std::string(cvendor)); + const std::string vendor(StripSpaces(cvendor)); if (vendor == "NVIDIA Corporation" || vendor == "Nouveau" || vendor == "nouveau") { diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 1e54544626..e17565f2c0 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -226,8 +226,10 @@ Client::~Client() { // Ignores line folding (deprecated), but respects field combining. // Don't use for Set-Cookie, which is a special header per RFC 7230. -bool GetHeaderValue(const std::vector &responseHeaders, const std::string &header, std::string *value) { - std::string search = header + ":"; +bool GetHeaderValue(const std::vector &responseHeaders, std::string_view header, std::string *value) { + std::string search(header); + search.push_back(':'); + bool found = false; value->clear(); @@ -242,7 +244,7 @@ bool GetHeaderValue(const std::vector &responseHeaders, const std:: if (!found) *value = stripped.substr(value_pos); else - *value += "," + stripped.substr(value_pos); + *value += "," + std::string(stripped.substr(value_pos)); found = true; } } diff --git a/Common/Net/HTTPClient.h b/Common/Net/HTTPClient.h index bd21c9b0fe..c8a147db56 100644 --- a/Common/Net/HTTPClient.h +++ b/Common/Net/HTTPClient.h @@ -47,7 +47,7 @@ private: namespace http { -bool GetHeaderValue(const std::vector &responseHeaders, const std::string &header, std::string *value); +bool GetHeaderValue(const std::vector &responseHeaders, std::string_view header, std::string *value); class RequestParams { public: diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 6efd728ba1..fea681cf05 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -361,27 +361,7 @@ std::string StringFromInt(int value) { return temp; } -// Turns " hej " into "hej". Also handles tabs. -std::string StripSpaces(const std::string &str) { - const size_t s = str.find_first_not_of(" \t\r\n"); - if (std::string::npos != s) - return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); - else - return ""; -} - -// "\"hello\"" is turned to "hello" -// This one assumes that the string has already been space stripped in both -// ends, as done by StripSpaces above, for example. -std::string StripQuotes(const std::string& s) -{ - if (s.size() && '\"' == s[0] && '\"' == *s.rbegin()) - return s.substr(1, s.size() - 2); - else - return s; -} - -// Turns " hej " into "hej". Also handles tabs. +// Turns " hej " into "hej". Also handles tabs and line breaks. std::string_view StripSpaces(std::string_view str) { const size_t s = str.find_first_not_of(" \t\r\n"); if (std::string::npos != s) diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 92cad2bef9..8e87d66387 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -95,9 +95,6 @@ void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t std::string StringFromFormat(const char* format, ...); std::string StringFromInt(int value); -std::string StripSpaces(const std::string &s); -std::string StripQuotes(const std::string &s); - std::string_view KeepAfterLast(std::string_view s, char c); std::string_view KeepIncludingLast(std::string_view s, char c); diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index c1e81556eb..4ad3332a27 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -521,7 +521,7 @@ void InitLocalhostIP() { g_localhostIP.in.sin_addr.s_addr = htonl(localIP); g_localhostIP.in.sin_port = 0; - std::string serverStr = StripSpaces(g_Config.proAdhocServer); + std::string serverStr(StripSpaces(g_Config.proAdhocServer)); isLocalServer = (!strcasecmp(serverStr.c_str(), "localhost") || serverStr.find("127.") == 0); } diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index a4b2782b2e..c6b296aee5 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -1222,7 +1222,7 @@ void FrameDumpTestScreen::update() { // We rely slightly on nginx listing format here. Not great. SplitString(listingHtml, '\n', lines); for (auto &line : lines) { - std::string trimmed = StripSpaces(line); + std::string trimmed(StripSpaces(line)); if (startsWith(trimmed, "Add(new ItemHeader(se->T("Find settings"))); searchSettings->Add(new PopupTextInputChoice(GetRequesterToken(), &searchFilter_, se->T("Filter"), "", 64, screenManager()))->OnChange.Add([=](UI::EventParams &e) { - System_PostUIMessage(UIMessage::GAMESETTINGS_SEARCH, StripSpaces(searchFilter_)); + System_PostUIMessage(UIMessage::GAMESETTINGS_SEARCH, std::string(StripSpaces(searchFilter_))); return UI::EVENT_DONE; });