1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-23 13:12:40 +01:00

Codechange: simplify and move GetArgumentInteger

This commit is contained in:
Rubidium
2025-04-22 21:47:59 +02:00
committed by rubidium42
parent 2bee313642
commit 4149384ebc
3 changed files with 48 additions and 51 deletions

View File

@@ -117,30 +117,6 @@ void IConsolePrint(TextColour colour_code, const std::string &string)
IConsoleGUIPrint(colour_code, str);
}
/**
* Change a string into its number representation. Supports
* decimal and hexadecimal numbers as well as 'on'/'off' 'true'/'false'
* @param *value the variable a successful conversion will be put in
* @param *arg the string to be converted
* @return Return true on success or false on failure
*/
bool GetArgumentInteger(uint32_t *value, const char *arg)
{
char *endptr;
if (strcmp(arg, "on") == 0 || strcmp(arg, "true") == 0) {
*value = 1;
return true;
}
if (strcmp(arg, "off") == 0 || strcmp(arg, "false") == 0) {
*value = 0;
return true;
}
*value = std::strtoul(arg, &endptr, 0);
return arg != endptr;
}
/**
* Creates a copy of a string with underscores removed from it
* @param name String to remove the underscores from.