From 4812f02b69de4a1c3026fb5fb4f7326f92fe4e51 Mon Sep 17 00:00:00 2001 From: nakeee Date: Wed, 25 Feb 2009 13:31:13 +0000 Subject: Revering stringutil (don't you hate it when ector is right?;) And small compile fix on linux git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2434 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/StringUtil.cpp | 63 ++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'Source/Core/Common/Src/StringUtil.cpp') diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index e34bbbafcc..edfbe3a282 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -200,25 +200,33 @@ std::string ArrayToString(const u8 *data, u32 size, u32 offset, int line_len, bo // ================ -// Turns " hej " into "hej". Also handles tabs and newlines. +// Turns " hej " into "hej". Also handles tabs. std::string StripSpaces(const std::string &str) { - std::string temp = str; - - // Find first non space char - u32 firstChar = str.find_first_not_of(" \t\n"); + std::string s = str; + int i; + for (i = 0; i < (int)s.size(); i++) + { + if ((s[i] != ' ') && (s[i] != 9)) + { + break; + } + } - // Last char which is not whitespace - u32 lastChar = str.find_last_not_of(" \t\n"); + s = s.substr(i); - if (firstChar != std::string::npos) - temp.resize(firstChar, lastChar); - else - temp = ""; + for (i = (int)s.size() - 1; i > 0; i--) + { + if ((s[i] != ' ') && (s[i] != 9)) + { + break; + } + } - return temp; + return s.substr(0, i + 1); } + // "\"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. @@ -230,6 +238,19 @@ std::string StripQuotes(const std::string& s) return s; } +// "\"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 StripNewline(const std::string& s) +{ + if (!s.size()) + return s; + else if (s[s.size() - 1] == '\n') + return s.substr(0, s.size() - 1); + else + return s; +} + bool TryParseInt(const char* str, int* outVal) { const char* s = str; @@ -440,21 +461,3 @@ std::string ThS(int Integer, bool Unsigned) } -// Remove trailing whitespaces from begining and end of string -std::string Trim(const std::string& str) -{ - std::string temp = str; - - // Find first non space char - u32 firstChar = str.find_first_not_of(" \t\n"); - - // Last char which is not whitespace - u32 lastChar = str.find_last_not_of(" \t\n"); - - if (firstChar != std::string::npos) - temp.resize(firstChar, lastChar); - else - temp = ""; - - return temp; -} -- cgit v1.2.3