From 727529fe0b65e28f6f00c674842405923c77f1b8 Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Fri, 25 Oct 2013 02:32:39 -0700 Subject: [PATCH] Remove one unnecessary backslash-check in StringReader::getTokens(). (This patch looks like it's removing the last backslash-counting loop, but really it removes the first one and then reindents everything.) --- src/StringReader.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/StringReader.cpp b/src/StringReader.cpp index 638e1df..bd1f042 100644 --- a/src/StringReader.cpp +++ b/src/StringReader.cpp @@ -43,36 +43,26 @@ std::string StringReader::getTokens(const char *stop_chars, bool truncateEnd) size_t found_pos = rd_string.find_first_of(stop_chars, str_pos); if (rd_string[str_pos] == '\"') { - //See if we have an even or odd number of backslashes (that is, this quote is not or is escaped) + //Find the next quote + found_pos = rd_string.find("\"", str_pos+1); + //Check to see if the quote is escaped int numBackslashes = 0; int countBack = 1; - while (str_pos-countBack >= 0 && rd_string[str_pos-countBack] == '\\') { + while (found_pos >= countBack && rd_string[found_pos-countBack] == '\\') { numBackslashes++; countBack++; } - //If the quote is not escaped - if (numBackslashes % 2 == 0) { - //Find the next quote - found_pos = rd_string.find("\"", str_pos+1); - //Check to see if the quote is escaped + //While the quote is escaped + while (numBackslashes % 2 == 1) { + //find the next quote + found_pos = rd_string.find("\"", found_pos+1); + //Check to see if it's escaped numBackslashes = 0; countBack = 1; while (found_pos >= countBack && rd_string[found_pos-countBack] == '\\') { numBackslashes++; countBack++; } - //While the quote is escaped - while (numBackslashes % 2 == 1) { - //find the next quote - found_pos = rd_string.find("\"", found_pos+1); - //Check to see if it's escaped - numBackslashes = 0; - countBack = 1; - while (found_pos >= countBack && rd_string[found_pos-countBack] == '\\') { - numBackslashes++; - countBack++; - } - } } }