mirror of
https://github.com/leejet/stable-diffusion.cpp
synced 2026-03-02 05:00:19 +01: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+`
|
||||
if (is_space(cp)) {
|
||||
std::string token = codepoint_to_utf8(cp);
|
||||
++i;
|
||||
std::string token;
|
||||
bool saw_new_line = false;
|
||||
|
||||
while (i < cps.size() && is_space(cps[i])) {
|
||||
token += codepoint_to_utf8(cps[i]);
|
||||
++i;
|
||||
|
||||
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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user