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.)

This commit is contained in:
Jason Orendorff
2013-10-25 02:32:39 -07:00
parent 64a405cab1
commit 727529fe0b

View File

@@ -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); size_t found_pos = rd_string.find_first_of(stop_chars, str_pos);
if (rd_string[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 numBackslashes = 0;
int countBack = 1; int countBack = 1;
while (str_pos-countBack >= 0 && rd_string[str_pos-countBack] == '\\') { while (found_pos >= countBack && rd_string[found_pos-countBack] == '\\') {
numBackslashes++; numBackslashes++;
countBack++; countBack++;
} }
//If the quote is not escaped //While the quote is escaped
if (numBackslashes % 2 == 0) { while (numBackslashes % 2 == 1) {
//Find the next quote //find the next quote
found_pos = rd_string.find("\"", str_pos+1); found_pos = rd_string.find("\"", found_pos+1);
//Check to see if the quote is escaped //Check to see if it's escaped
numBackslashes = 0; numBackslashes = 0;
countBack = 1; countBack = 1;
while (found_pos >= countBack && rd_string[found_pos-countBack] == '\\') { while (found_pos >= countBack && rd_string[found_pos-countBack] == '\\') {
numBackslashes++; numBackslashes++;
countBack++; 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++;
}
}
} }
} }