From 83af1b1c5a5f03491bd49f7673fd2ec5e4e68472 Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Fri, 25 Oct 2013 02:42:12 -0700 Subject: [PATCH] Use std::string::substr() instead of adding one character at a time. This patch also removes a few unused util functions that are easily written using substr(). --- include/util.h | 4 +--- src/StringReader.cpp | 22 ++-------------------- src/util.cpp | 15 --------------- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/include/util.h b/include/util.h index 2aa779d..2041601 100644 --- a/include/util.h +++ b/include/util.h @@ -10,8 +10,6 @@ #include std::string intToString(int theInt); -std::string truncateEnd(std::string to_truncate); -std::string removeBeginning(std::string to_remove); std::string replaceExEscape(std::string first, std::string search, std::string replace); -#endif \ No newline at end of file +#endif diff --git a/src/StringReader.cpp b/src/StringReader.cpp index bd1f042..29772b4 100644 --- a/src/StringReader.cpp +++ b/src/StringReader.cpp @@ -85,18 +85,8 @@ std::string StringReader::getTokens(const char *stop_chars, bool truncateEnd) if (rd_string[str_pos] == '\"') found_pos++; - std::string string_section; - - for (; str_pos <= found_pos; str_pos++) - { - string_section += rd_string[str_pos]; - } - - // if (str_pos <= found_pos) { - // string_section = rd_string.substr(str_pos, found_pos+1); - // str_pos = found_pos+1; - // } - // std::cout << string_section << " - " << str_pos << " - " << found_pos << std::endl; + std::string string_section = rd_string.substr(str_pos, found_pos - str_pos + 1); + str_pos = found_pos + 1; if (truncateEnd) //Ok, we didn't add the last char, but str_pos now points at that char. So we move it one ahead. str_pos++; @@ -104,14 +94,6 @@ std::string StringReader::getTokens(const char *stop_chars, bool truncateEnd) } } -std::string StringReader::truncateEnd(std::string to_truncate) -{ - std::string to_return = ""; - for (unsigned int i = 0; i < to_truncate.length()-1; i++) - to_return = to_return + to_truncate[i]; - return to_return; -} - void StringReader::test() { { diff --git a/src/util.cpp b/src/util.cpp index 5b298b5..b71e6b0 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5,21 +5,6 @@ std::string intToString(int theInt) { converter << theInt; return converter.str(); } -std::string truncateEnd(std::string to_truncate) -{ - std::string to_return = ""; - for (unsigned int i = 0; i < to_truncate.length()-1; i++) - to_return = to_return + to_truncate[i]; - return to_return; -} - -std::string removeBeginning(std::string to_remove) -{ - std::string to_return = ""; - for (unsigned int i = 1; i < to_remove.length(); i++) - to_return = to_return + to_remove[i]; - return to_return; -} std::string replaceExEscape(std::string first, std::string search, std::string replace) { size_t pos = 0;