|
|
@ -168,15 +168,15 @@ std::string to_search_normalized(const std::string &str)
|
|
|
|
return result;
|
|
|
|
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,
|
|
|
|
word_wrap_whitespace_mode mode)
|
|
|
|
size_t line_length, bool collapse_whitespace)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (line_length == 0)
|
|
|
|
if (line_length == 0)
|
|
|
|
line_length = SIZE_MAX;
|
|
|
|
line_length = SIZE_MAX;
|
|
|
|
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
std::string line;
|
|
|
|
size_t break_pos = 0;
|
|
|
|
size_t break_pos = 0;
|
|
|
|
|
|
|
|
bool ignore_whitespace = false;
|
|
|
|
|
|
|
|
|
|
|
|
for (auto &c : str)
|
|
|
|
for (auto &c : str)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -185,19 +185,22 @@ bool word_wrap(std::vector<std::string> *out, const std::string &str,
|
|
|
|
out->push_back(line);
|
|
|
|
out->push_back(line);
|
|
|
|
line.clear();
|
|
|
|
line.clear();
|
|
|
|
break_pos = 0;
|
|
|
|
break_pos = 0;
|
|
|
|
|
|
|
|
ignore_whitespace = (mode == WSMODE_TRIM_LEADING);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isspace(c))
|
|
|
|
if (isspace(c))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (break_pos == line.length() && collapse_whitespace)
|
|
|
|
if (ignore_whitespace || (mode == WSMODE_COLLAPSE_ALL && break_pos == line.length()))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
line.push_back(collapse_whitespace ? ' ' : c);
|
|
|
|
line.push_back((mode == WSMODE_COLLAPSE_ALL) ? ' ' : c);
|
|
|
|
break_pos = line.length();
|
|
|
|
break_pos = line.length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
line.push_back(c);
|
|
|
|
line.push_back(c);
|
|
|
|
|
|
|
|
ignore_whitespace = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (line.length() > line_length)
|
|
|
|
if (line.length() > line_length)
|
|
|
@ -215,6 +218,7 @@ bool word_wrap(std::vector<std::string> *out, const std::string &str,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line = line.substr(break_pos);
|
|
|
|
line = line.substr(break_pos);
|
|
|
|
break_pos = 0;
|
|
|
|
break_pos = 0;
|
|
|
|
|
|
|
|
ignore_whitespace = (mode == WSMODE_TRIM_LEADING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (line.length())
|
|
|
|
if (line.length())
|
|
|
|