1
0
Fork 0

Fix: StringFilter included quotes in the search and failed.

pull/13983/head
frosch 2025-04-04 20:32:43 +02:00 committed by frosch
parent 1d879f3043
commit 9b87f306ca
1 changed files with 9 additions and 18 deletions

View File

@ -10,6 +10,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "string_func.h" #include "string_func.h"
#include "strings_func.h" #include "strings_func.h"
#include "core/utf8.hpp"
#include "core/string_builder.hpp"
#include "stringfilter_type.h" #include "stringfilter_type.h"
#include "gfx_func.h" #include "gfx_func.h"
@ -31,22 +33,14 @@ void StringFilter::SetFilterTerm(std::string_view str)
this->word_matches = 0; this->word_matches = 0;
char32_t state = STATE_WHITESPACE; char32_t state = STATE_WHITESPACE;
auto pos = str.begin(); std::string word;
auto word_begin = str.end(); StringBuilder builder(word);
auto word_end = pos; auto add_word = [this, &word]() {
if (!word.empty()) this->word_index.emplace_back(std::move(word), false);
/* Helper to prevent duplicating code. */ word.clear();
auto add_word = [&] () {
if (word_begin != str.end()) {
this->word_index.emplace_back(std::string(word_begin, word_end + 1), false);
word_begin = str.end();
}
}; };
for (size_t len; pos < str.end(); pos += len) { for (char32_t c : Utf8View(str)) {
char32_t c;
len = Utf8Decode(&c, pos);
if (state == STATE_WORD && IsWhitespace(c)) { if (state == STATE_WORD && IsWhitespace(c)) {
/* Finish word */ /* Finish word */
add_word(); add_word();
@ -73,10 +67,7 @@ void StringFilter::SetFilterTerm(std::string_view str)
} }
/* Add to word */ /* Add to word */
if (word_begin == str.end()) { builder.PutUtf8(c);
word_begin = pos;
}
word_end = pos;
} }
/* Add the last word of the string. */ /* Add the last word of the string. */