mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-20 19:02:41 +01:00
Codechange: return std::string_view for Textbuf::GetText()
This commit is contained in:
@@ -129,7 +129,7 @@ static inline void IConsoleResetHistoryPos()
|
||||
}
|
||||
|
||||
|
||||
static const char *IConsoleHistoryAdd(const char *cmd);
|
||||
static std::optional<std::string_view> IConsoleHistoryAdd(std::string_view cmd);
|
||||
static void IConsoleHistoryNavigate(int direction);
|
||||
|
||||
static constexpr NWidgetPart _nested_console_window_widgets[] = {
|
||||
@@ -276,10 +276,10 @@ struct IConsoleWindow : Window
|
||||
* aligned anyway. So enforce this in all cases by adding a left-to-right marker,
|
||||
* otherwise it will be drawn at the wrong side with right-to-left texts. */
|
||||
IConsolePrint(CC_COMMAND, LRM "] {}", _iconsole_cmdline.GetText());
|
||||
const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.GetText());
|
||||
auto cmd = IConsoleHistoryAdd(_iconsole_cmdline.GetText());
|
||||
IConsoleClearCommand();
|
||||
|
||||
if (cmd != nullptr) IConsoleCmdExec(cmd);
|
||||
if (cmd.has_value()) IConsoleCmdExec(*cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -448,13 +448,13 @@ void IConsoleClose()
|
||||
* @param cmd Text to be entered into the 'history'
|
||||
* @return the command to execute
|
||||
*/
|
||||
static const char *IConsoleHistoryAdd(const char *cmd)
|
||||
static std::optional<std::string_view> IConsoleHistoryAdd(std::string_view cmd)
|
||||
{
|
||||
/* Strip all spaces at the begin */
|
||||
while (IsWhitespace(*cmd)) cmd++;
|
||||
while (IsWhitespace(cmd[0])) cmd.remove_prefix(1);
|
||||
|
||||
/* Do not put empty command in history */
|
||||
if (StrEmpty(cmd)) return nullptr;
|
||||
if (cmd.empty()) return std::nullopt;
|
||||
|
||||
/* Do not put in history if command is same as previous */
|
||||
if (_iconsole_history.empty() || _iconsole_history.front() != cmd) {
|
||||
@@ -464,7 +464,7 @@ static const char *IConsoleHistoryAdd(const char *cmd)
|
||||
|
||||
/* Reset the history position */
|
||||
IConsoleResetHistoryPos();
|
||||
return _iconsole_history.front().c_str();
|
||||
return _iconsole_history.front();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user