1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 01:12:39 +01:00

Codechange: replace some more char*s with std::string_view

This commit is contained in:
Rubidium
2025-04-30 20:56:54 +02:00
committed by rubidium42
parent a80c11a6e8
commit 855377191e
5 changed files with 17 additions and 19 deletions

View File

@@ -1190,15 +1190,13 @@ static bool ConExec(std::span<std::string_view> argv)
_script_current_depth++;
uint script_depth = _script_current_depth;
char cmdline[ICON_CMDLN_SIZE];
while (fgets(cmdline, sizeof(cmdline), *script_file) != nullptr) {
char buffer[ICON_CMDLN_SIZE];
while (fgets(buffer, sizeof(buffer), *script_file) != nullptr) {
/* Remove newline characters from the executing script */
for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
if (*cmdptr == '\n' || *cmdptr == '\r') {
*cmdptr = '\0';
break;
}
}
std::string_view cmdline{buffer};
auto last_non_newline = cmdline.find_last_not_of("\r\n");
if (last_non_newline != std::string_view::npos) cmdline = cmdline.substr(0, last_non_newline + 1);
IConsoleCmdExec(cmdline);
/* Ensure that we are still on the same depth or that we returned via 'return'. */
assert(_script_current_depth == script_depth || _script_current_depth == script_depth - 1);