From f92541fbd9da5091636aac09fdabd1a5fd0191ce Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Tue, 19 Jul 2022 15:13:26 -0700 Subject: StripSpaces: only strip spaces StripWhitespace maintains old behavior --- Source/Core/Common/StringUtil.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'Source/Core/Common/StringUtil.cpp') diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index c498e261fd..4a5f21ddc2 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -219,20 +219,31 @@ std::string ArrayToString(const u8* data, u32 size, int line_len, bool spaces) return oss.str(); } -// Turns "\n\r\t hello " into "hello" (trims at the start and end but not inside). -std::string_view StripSpaces(std::string_view str) +template +static std::string_view StripEnclosingChars(std::string_view str, T chars) { - const size_t s = str.find_first_not_of(" \t\r\n"); + const size_t s = str.find_first_not_of(chars); if (str.npos != s) - return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); + return str.substr(s, str.find_last_not_of(chars) - s + 1); else return ""; } +// Turns "\n\r\t hello " into "hello" (trims at the start and end but not inside). +std::string_view StripWhitespace(std::string_view str) +{ + return StripEnclosingChars(str, " \t\r\n"); +} + +std::string_view StripSpaces(std::string_view str) +{ + return StripEnclosingChars(str, ' '); +} + // "\"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. +// ends, as done by StripWhitespace above, for example. std::string_view StripQuotes(std::string_view s) { if (!s.empty() && '\"' == s[0] && '\"' == *s.rbegin()) -- cgit v1.2.3