Codechange: use std::string to store script GUI's break string

This commit is contained in:
Rubidium 2023-05-06 12:49:28 +02:00 committed by rubidium42
parent 48825e1a8e
commit 20ff0bccd7
3 changed files with 13 additions and 3 deletions

View File

@ -696,7 +696,7 @@ struct ScriptDebugWindow : public Window {
bool autoscroll; ///< Whether automatically scrolling should be enabled or not.
bool show_break_box; ///< Whether the break/debug box is visible.
static bool break_check_enabled; ///< Stop an AI when it prints a matching string
static char break_string[MAX_BREAK_STR_STRING_LENGTH]; ///< The string to match to the AI output
static std::string break_string; ///< The string to match to the AI output
QueryString break_editbox; ///< Break editbox
static StringFilter break_string_filter; ///< Log filter for break.
static bool case_sensitive_break_check; ///< Is the matching done case-sensitive
@ -1022,7 +1022,7 @@ struct ScriptDebugWindow : public Window {
if (wid != WID_SCRD_BREAK_STR_EDIT_BOX) return;
/* Save the current string to static member so it can be restored next time the window is opened. */
strecpy(this->break_string, this->break_editbox.text.buf, lastof(this->break_string));
this->break_string = this->break_editbox.text.buf;
break_string_filter.SetFilterTerm(this->break_string);
}
@ -1098,7 +1098,7 @@ struct ScriptDebugWindow : public Window {
};
CompanyID ScriptDebugWindow::script_debug_company = INVALID_COMPANY;
char ScriptDebugWindow::break_string[MAX_BREAK_STR_STRING_LENGTH] = "";
std::string ScriptDebugWindow::break_string;
bool ScriptDebugWindow::break_check_enabled = true;
bool ScriptDebugWindow::case_sensitive_break_check = false;
StringFilter ScriptDebugWindow::break_string_filter(&ScriptDebugWindow::case_sensitive_break_check);

View File

@ -83,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.
*/

View File

@ -51,6 +51,7 @@ public:
~StringFilter() { free(this->filter_buffer); }
void SetFilterTerm(const char *str);
void SetFilterTerm(const std::string &str);
/**
* Check whether any filter words were entered.