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().
This commit is contained in:
@@ -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()
|
||||
{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user