Use a string and .reserve for normalizing instead of stringbuf

develop
George Murray 2020-09-24 15:22:58 -07:00
parent f5c3712778
commit 74a3e0eddf
1 changed files with 5 additions and 4 deletions

@ -150,21 +150,22 @@ static const char *normalized_table[256] = {
std::string to_search_normalized(const std::string &str) std::string to_search_normalized(const std::string &str)
{ {
std::stringbuf result; std::string result;
result.reserve(str.size());
for (char c : str) for (char c : str)
{ {
const char *mapped = normalized_table[(uint8_t)c]; const char *mapped = normalized_table[(uint8_t)c];
if (mapped == NULL) if (mapped == NULL)
result.sputc(tolower(c)); result += tolower(c);
else else
while (*mapped != '\0') while (*mapped != '\0')
{ {
result.sputc(tolower(*mapped)); result += tolower(*mapped);
++mapped; ++mapped;
} }
} }
return result.str(); return result;
} }
bool word_wrap(std::vector<std::string> *out, const std::string &str, size_t line_length) bool word_wrap(std::vector<std::string> *out, const std::string &str, size_t line_length)