mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-03-24 02:08:51 +00:00
fix: safely handle whitespace and consecutive newlines (#1288)
This commit is contained in:
parent
c5eb1e4137
commit
c9cd49701a
@ -919,15 +919,21 @@ std::vector<std::string> token_split(const std::string& text) {
|
|||||||
|
|
||||||
// `\s*[\r\n]+|\s+(?!\S)|\s+`
|
// `\s*[\r\n]+|\s+(?!\S)|\s+`
|
||||||
if (is_space(cp)) {
|
if (is_space(cp)) {
|
||||||
std::string token = codepoint_to_utf8(cp);
|
std::string token;
|
||||||
++i;
|
bool saw_new_line = false;
|
||||||
|
|
||||||
while (i < cps.size() && is_space(cps[i])) {
|
while (i < cps.size() && is_space(cps[i])) {
|
||||||
token += codepoint_to_utf8(cps[i]);
|
token += codepoint_to_utf8(cps[i]);
|
||||||
++i;
|
|
||||||
if (cps[i] == U'\r' || cps[i] == U'\n') {
|
if (cps[i] == U'\r' || cps[i] == U'\n') {
|
||||||
break;
|
saw_new_line = true;
|
||||||
|
} else {
|
||||||
|
if (saw_new_line) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens.push_back(token);
|
tokens.push_back(token);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user