mirror of https://github.com/OpenTTD/OpenTTD
Codechange: replace some more char*s with std::string_view
parent
a80c11a6e8
commit
855377191e
|
@ -1190,15 +1190,13 @@ static bool ConExec(std::span<std::string_view> argv)
|
||||||
_script_current_depth++;
|
_script_current_depth++;
|
||||||
uint script_depth = _script_current_depth;
|
uint script_depth = _script_current_depth;
|
||||||
|
|
||||||
char cmdline[ICON_CMDLN_SIZE];
|
char buffer[ICON_CMDLN_SIZE];
|
||||||
while (fgets(cmdline, sizeof(cmdline), *script_file) != nullptr) {
|
while (fgets(buffer, sizeof(buffer), *script_file) != nullptr) {
|
||||||
/* Remove newline characters from the executing script */
|
/* Remove newline characters from the executing script */
|
||||||
for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
|
std::string_view cmdline{buffer};
|
||||||
if (*cmdptr == '\n' || *cmdptr == '\r') {
|
auto last_non_newline = cmdline.find_last_not_of("\r\n");
|
||||||
*cmdptr = '\0';
|
if (last_non_newline != std::string_view::npos) cmdline = cmdline.substr(0, last_non_newline + 1);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IConsoleCmdExec(cmdline);
|
IConsoleCmdExec(cmdline);
|
||||||
/* Ensure that we are still on the same depth or that we returned via 'return'. */
|
/* 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);
|
assert(_script_current_depth == script_depth || _script_current_depth == script_depth - 1);
|
||||||
|
|
|
@ -271,9 +271,9 @@ static void WriteSavegameInfo(const std::string &name)
|
||||||
* @param res variable to store the resolution in.
|
* @param res variable to store the resolution in.
|
||||||
* @param s the string to decompose.
|
* @param s the string to decompose.
|
||||||
*/
|
*/
|
||||||
static void ParseResolution(Dimension *res, const char *s)
|
static void ParseResolution(Dimension &res, std::string_view s)
|
||||||
{
|
{
|
||||||
StringConsumer consumer(std::string_view{s});
|
StringConsumer consumer(s);
|
||||||
auto width = consumer.TryReadIntegerBase<uint>(10);
|
auto width = consumer.TryReadIntegerBase<uint>(10);
|
||||||
auto valid = consumer.ReadIf("x");
|
auto valid = consumer.ReadIf("x");
|
||||||
auto height = consumer.TryReadIntegerBase<uint>(10);
|
auto height = consumer.TryReadIntegerBase<uint>(10);
|
||||||
|
@ -282,8 +282,8 @@ static void ParseResolution(Dimension *res, const char *s)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res->width = std::max<uint>(*width, 64);
|
res.width = std::max<uint>(*width, 64);
|
||||||
res->height = std::max<uint>(*height, 64);
|
res.height = std::max<uint>(*height, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -552,7 +552,7 @@ int openttd_main(std::span<char * const> arguments)
|
||||||
case 'p':
|
case 'p':
|
||||||
scanner->join_server_password = mgo.opt;
|
scanner->join_server_password = mgo.opt;
|
||||||
break;
|
break;
|
||||||
case 'r': ParseResolution(&resolution, mgo.opt); break;
|
case 'r': ParseResolution(resolution, mgo.opt); break;
|
||||||
case 't':
|
case 't':
|
||||||
if (auto value = ParseInteger(mgo.opt); value.has_value()) {
|
if (auto value = ParseInteger(mgo.opt); value.has_value()) {
|
||||||
scanner->startyear = TimerGameCalendar::Year(*value);
|
scanner->startyear = TimerGameCalendar::Year(*value);
|
||||||
|
|
|
@ -904,7 +904,7 @@ void *UniquePtrSpriteAllocator::AllocatePtr(size_t size)
|
||||||
*/
|
*/
|
||||||
static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc, SpriteAllocator *allocator)
|
static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc, SpriteAllocator *allocator)
|
||||||
{
|
{
|
||||||
static const char * const sprite_types[] = {
|
static const std::string_view sprite_types[] = {
|
||||||
"normal", // SpriteType::Normal
|
"normal", // SpriteType::Normal
|
||||||
"map generator", // SpriteType::MapGen
|
"map generator", // SpriteType::MapGen
|
||||||
"character", // SpriteType::Font
|
"character", // SpriteType::Font
|
||||||
|
|
|
@ -1835,7 +1835,7 @@ struct StationViewWindow : public Window {
|
||||||
DrawString(text.left, text.right, y, GetString(str, cargo, cd.GetCount(), station));
|
DrawString(text.left, text.right, y, GetString(str, cargo, cd.GetCount(), station));
|
||||||
|
|
||||||
if (column < NUM_COLUMNS - 1) {
|
if (column < NUM_COLUMNS - 1) {
|
||||||
const char *sym = nullptr;
|
std::string_view sym;
|
||||||
if (cd.GetNumChildren() > 0) {
|
if (cd.GetNumChildren() > 0) {
|
||||||
sym = "-";
|
sym = "-";
|
||||||
} else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) {
|
} else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) {
|
||||||
|
@ -1850,7 +1850,7 @@ struct StationViewWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sym != nullptr) DrawString(shrink.left, shrink.right, y, sym, TC_YELLOW);
|
if (!sym.empty()) DrawString(shrink.left, shrink.right, y, sym, TC_YELLOW);
|
||||||
}
|
}
|
||||||
this->SetDisplayedRow(cd);
|
this->SetDisplayedRow(cd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,8 +160,8 @@ static const CmdStruct _cmd_structs[] = {
|
||||||
/** Description of a plural form */
|
/** Description of a plural form */
|
||||||
struct PluralForm {
|
struct PluralForm {
|
||||||
size_t plural_count; ///< The number of plural forms
|
size_t plural_count; ///< The number of plural forms
|
||||||
const char *description; ///< Human readable description of the form
|
std::string_view description; ///< Human readable description of the form
|
||||||
const char *names; ///< Plural names
|
std::string_view names; ///< Plural names
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The maximum number of plurals. */
|
/** The maximum number of plurals. */
|
||||||
|
@ -199,7 +199,7 @@ static const PluralForm _plural_forms[] = {
|
||||||
* a = array, i.e. list of strings
|
* a = array, i.e. list of strings
|
||||||
*/
|
*/
|
||||||
/** All pragmas used */
|
/** All pragmas used */
|
||||||
static const char * const _pragmas[][4] = {
|
static const std::string_view _pragmas[][4] = {
|
||||||
/* name flags default description */
|
/* name flags default description */
|
||||||
{ "name", "0", "", "English name for the language" },
|
{ "name", "0", "", "English name for the language" },
|
||||||
{ "ownname", "t", "", "Localised name for the language" },
|
{ "ownname", "t", "", "Localised name for the language" },
|
||||||
|
|
Loading…
Reference in New Issue