Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138461 additions and 70983 deletions
+40 -12
View File
@@ -8,6 +8,7 @@
/** @file stringfilter.cpp Searching and filtering using a stringterm. */
#include "stdafx.h"
#include "core/alloc_func.hpp"
#include "string_func.h"
#include "strings_func.h"
#include "stringfilter_type.h"
@@ -15,10 +16,10 @@
#include "safeguards.h"
static const WChar STATE_WHITESPACE = ' ';
static const WChar STATE_WORD = 'w';
static const WChar STATE_QUOTE1 = '\'';
static const WChar STATE_QUOTE2 = '"';
static const char32_t STATE_WHITESPACE = ' ';
static const char32_t STATE_WORD = 'w';
static const char32_t STATE_QUOTE1 = '\'';
static const char32_t STATE_QUOTE2 = '"';
/**
* Set the term to filter on.
@@ -36,12 +37,12 @@ void StringFilter::SetFilterTerm(const char *str)
char *dest = MallocT<char>(strlen(str) + 1);
this->filter_buffer = dest;
WChar state = STATE_WHITESPACE;
char32_t state = STATE_WHITESPACE;
const char *pos = str;
WordState *word = nullptr;
size_t len;
for (;; pos += len) {
WChar c;
char32_t c;
len = Utf8Decode(&c, pos);
if (c == 0 || (state == STATE_WORD && IsWhitespace(c))) {
@@ -82,6 +83,15 @@ void StringFilter::SetFilterTerm(const char *str)
}
}
/**
* Set the term to filter on.
* @param str Filter term
*/
void StringFilter::SetFilterTerm(const std::string &str)
{
this->SetFilterTerm(str.c_str());
}
/**
* Reset the matching state to process a new item.
*/
@@ -108,14 +118,34 @@ void StringFilter::AddLine(const char *str)
bool match_case = this->case_sensitive != nullptr && *this->case_sensitive;
for (WordState &ws : this->word_index) {
if (!ws.match) {
if ((match_case ? strstr(str, ws.start) : strcasestr(str, ws.start)) != nullptr) {
ws.match = true;
this->word_matches++;
if (this->locale_aware) {
if (match_case ? StrNaturalContains(str, ws.start) : StrNaturalContainsIgnoreCase(str, ws.start)) {
ws.match = true;
this->word_matches++;
}
} else {
if ((match_case ? strstr(str, ws.start) : strcasestr(str, ws.start)) != nullptr) {
ws.match = true;
this->word_matches++;
}
}
}
}
}
/**
* Pass another text line from the current item to the filter.
*
* You can call this multiple times for a single item, if the filter shall apply to multiple things.
* Before processing the next item you have to call ResetState().
*
* @param str Another line from the item.
*/
void StringFilter::AddLine(const std::string &str)
{
AddLine(str.c_str());
}
/**
* Pass another text line from the current item to the filter.
*
@@ -126,7 +156,5 @@ void StringFilter::AddLine(const char *str)
*/
void StringFilter::AddLine(StringID str)
{
char buffer[DRAW_STRING_BUFFER];
GetString(buffer, str, lastof(buffer));
AddLine(buffer);
AddLine(GetString(str));
}