mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use std::strto* variants everywhere (#10720)
This commit is contained in:
parent
997c936893
commit
80bd5ad727
|
@ -1766,7 +1766,7 @@ public:
|
|||
if (str == nullptr) return;
|
||||
/* Set a new company manager face number */
|
||||
if (!StrEmpty(str)) {
|
||||
this->face = strtoul(str, nullptr, 10);
|
||||
this->face = std::strtoul(str, nullptr, 10);
|
||||
ScaleAllCompanyManagerFaceBits(this->face);
|
||||
ShowErrorMessage(STR_FACE_FACECODE_SET, INVALID_STRING_ID, WL_INFO);
|
||||
this->UpdateData();
|
||||
|
@ -2714,7 +2714,7 @@ struct CompanyWindow : Window
|
|||
default: NOT_REACHED();
|
||||
|
||||
case WID_C_GIVE_MONEY: {
|
||||
Money money = (Money)(strtoull(str, nullptr, 10) / _currency->rate);
|
||||
Money money = (Money)(std::strtoull(str, nullptr, 10) / _currency->rate);
|
||||
uint32 money_c = Clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0
|
||||
|
||||
Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money_c, (CompanyID)this->window_number);
|
||||
|
|
|
@ -146,7 +146,7 @@ bool GetArgumentInteger(uint32 *value, const char *arg)
|
|||
return true;
|
||||
}
|
||||
|
||||
*value = strtoul(arg, &endptr, 0);
|
||||
*value = std::strtoul(arg, &endptr, 0);
|
||||
return arg != endptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -1131,7 +1131,7 @@ DEF_CONSOLE_CMD(ConNewGame)
|
|||
return true;
|
||||
}
|
||||
|
||||
StartNewGameWithoutGUI((argc == 2) ? strtoul(argv[1], nullptr, 10) : GENERATE_NEW_SEED);
|
||||
StartNewGameWithoutGUI((argc == 2) ? std::strtoul(argv[1], nullptr, 10) : GENERATE_NEW_SEED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ void SetDebugString(const char *s, void (*error_func)(const std::string &))
|
|||
if (*s >= '0' && *s <= '9') {
|
||||
const DebugLevel *i;
|
||||
|
||||
v = strtoul(s, &end, 0);
|
||||
v = std::strtoul(s, &end, 0);
|
||||
s = end;
|
||||
|
||||
for (i = debug_level; i != endof(debug_level); ++i) {
|
||||
|
@ -201,7 +201,7 @@ void SetDebugString(const char *s, void (*error_func)(const std::string &))
|
|||
}
|
||||
|
||||
if (*s == '=') s++;
|
||||
v = strtoul(s, &end, 0);
|
||||
v = std::strtoul(s, &end, 0);
|
||||
s = end;
|
||||
if (found != nullptr) {
|
||||
new_levels[found->name] = v;
|
||||
|
|
|
@ -538,7 +538,7 @@ bool TarScanner::AddFile(const std::string &filename, size_t basepath_length, co
|
|||
|
||||
/* Calculate the size of the file.. for some strange reason this is stored as a string */
|
||||
strecpy(buf, th.size, lastof(buf));
|
||||
size_t skip = strtoul(buf, &end, 8);
|
||||
size_t skip = std::strtoul(buf, &end, 8);
|
||||
|
||||
switch (th.typeflag) {
|
||||
case '\0':
|
||||
|
|
|
@ -111,7 +111,7 @@ const FiosItem *FileList::FindItem(const char *file)
|
|||
|
||||
/* If no name matches, try to parse it as number */
|
||||
char *endptr;
|
||||
int i = strtol(file, &endptr, 10);
|
||||
int i = std::strtol(file, &endptr, 10);
|
||||
if (file == endptr || *endptr != '\0') i = -1;
|
||||
|
||||
if (IsInsideMM(i, 0, this->size())) return &this->at(i);
|
||||
|
|
|
@ -618,7 +618,7 @@ struct NewGRFInspectWindow : Window {
|
|||
{
|
||||
if (StrEmpty(str)) return;
|
||||
|
||||
NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = strtol(str, nullptr, 16);
|
||||
NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = std::strtol(str, nullptr, 16);
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
|
|
|
@ -286,8 +286,8 @@ static void ParseResolution(Dimension *res, const char *s)
|
|||
return;
|
||||
}
|
||||
|
||||
res->width = std::max(strtoul(s, nullptr, 0), 64UL);
|
||||
res->height = std::max(strtoul(t + 1, nullptr, 0), 64UL);
|
||||
res->width = std::max(std::strtoul(s, nullptr, 0), 64UL);
|
||||
res->height = std::max(std::strtoul(t + 1, nullptr, 0), 64UL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -637,7 +637,7 @@ int openttd_main(int argc, char *argv[])
|
|||
_skip_all_newgrf_scanning += 1;
|
||||
break;
|
||||
}
|
||||
case 'G': scanner->generation_seed = strtoul(mgo.opt, nullptr, 10); break;
|
||||
case 'G': scanner->generation_seed = std::strtoul(mgo.opt, nullptr, 10); break;
|
||||
case 'c': _config_file = mgo.opt; break;
|
||||
case 'x': scanner->save_config = false; break;
|
||||
case 'X': only_local_path = true; break;
|
||||
|
|
|
@ -174,7 +174,7 @@ const uint16 INIFILE_VERSION = (IniFileVersion)(IFV_MAX_VERSION - 1); ///< Curre
|
|||
size_t OneOfManySettingDesc::ParseSingleValue(const char *str, size_t len, const std::vector<std::string> &many)
|
||||
{
|
||||
/* check if it's an integer */
|
||||
if (isdigit(*str)) return strtoul(str, nullptr, 0);
|
||||
if (isdigit(*str)) return std::strtoul(str, nullptr, 0);
|
||||
|
||||
size_t idx = 0;
|
||||
for (auto one : many) {
|
||||
|
@ -245,7 +245,7 @@ static int ParseIntList(const char *p, T *items, int maxitems)
|
|||
default: {
|
||||
if (n == maxitems) return -1; // we don't accept that many numbers
|
||||
char *end;
|
||||
unsigned long v = strtoul(p, &end, 0);
|
||||
unsigned long v = std::strtoul(p, &end, 0);
|
||||
if (p == end) return -1; // invalid character (not a number)
|
||||
if (sizeof(T) < sizeof(v)) v = Clamp<unsigned long>(v, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
|
||||
items[n++] = v;
|
||||
|
@ -377,7 +377,7 @@ void ManyOfManySettingDesc::FormatValue(char *buf, const char *last, const void
|
|||
size_t IntSettingDesc::ParseValue(const char *str) const
|
||||
{
|
||||
char *end;
|
||||
size_t val = strtoul(str, &end, 0);
|
||||
size_t val = std::strtoul(str, &end, 0);
|
||||
if (end == str) {
|
||||
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
|
||||
msg.SetDParamStr(0, str);
|
||||
|
|
|
@ -251,7 +251,6 @@
|
|||
|
||||
# define strcasecmp stricmp
|
||||
# define strncasecmp strnicmp
|
||||
# define strtoull _strtoui64
|
||||
|
||||
/* MSVC doesn't have these :( */
|
||||
# define S_ISDIR(mode) (mode & S_IFDIR)
|
||||
|
|
|
@ -117,7 +117,7 @@ struct FileStringReader : StringReader {
|
|||
void FileStringReader::HandlePragma(char *str)
|
||||
{
|
||||
if (!memcmp(str, "id ", 3)) {
|
||||
this->data.next_string_id = strtoul(str + 3, nullptr, 0);
|
||||
this->data.next_string_id = std::strtoul(str + 3, nullptr, 0);
|
||||
} else if (!memcmp(str, "name ", 5)) {
|
||||
strecpy(_lang.name, str + 5, lastof(_lang.name));
|
||||
} else if (!memcmp(str, "ownname ", 8)) {
|
||||
|
@ -143,14 +143,14 @@ void FileStringReader::HandlePragma(char *str)
|
|||
strecpy(_lang.digit_decimal_separator, strcmp(str, "{NBSP}") == 0 ? NBSP : str, lastof(_lang.digit_decimal_separator));
|
||||
} else if (!memcmp(str, "winlangid ", 10)) {
|
||||
const char *buf = str + 10;
|
||||
long langid = strtol(buf, nullptr, 16);
|
||||
long langid = std::strtol(buf, nullptr, 16);
|
||||
if (langid > (long)UINT16_MAX || langid < 0) {
|
||||
FatalError("Invalid winlangid {}", buf);
|
||||
}
|
||||
_lang.winlangid = (uint16)langid;
|
||||
} else if (!memcmp(str, "grflangid ", 10)) {
|
||||
const char *buf = str + 10;
|
||||
long langid = strtol(buf, nullptr, 16);
|
||||
long langid = std::strtol(buf, nullptr, 16);
|
||||
if (langid >= 0x7F || langid < 0) {
|
||||
FatalError("Invalid grflangid {}", buf);
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ bool ParseRelNum(char **buf, int *value, int *offset)
|
|||
rel = true;
|
||||
s++;
|
||||
}
|
||||
int v = strtol(s, &end, 0);
|
||||
int v = std::strtol(s, &end, 0);
|
||||
if (end == s) return false;
|
||||
if (rel || v < 0) {
|
||||
*value += v;
|
||||
|
@ -319,7 +319,7 @@ bool ParseRelNum(char **buf, int *value, int *offset)
|
|||
if (offset != nullptr && *end == ':') {
|
||||
/* Take the Nth within */
|
||||
s = end + 1;
|
||||
*offset = strtol(s, &end, 0);
|
||||
*offset = std::strtol(s, &end, 0);
|
||||
if (end == s) return false;
|
||||
}
|
||||
*buf = end;
|
||||
|
@ -509,7 +509,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
|
|||
if (*s >= '0' && *s <= '9') {
|
||||
char *end;
|
||||
|
||||
*argno = strtoul(s, &end, 0);
|
||||
*argno = std::strtoul(s, &end, 0);
|
||||
if (*end != ':') StrgenFatal("missing arg #");
|
||||
s = end + 1;
|
||||
}
|
||||
|
|
|
@ -874,7 +874,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
|||
memset(sub_args_need_free, 0, sizeof(sub_args_need_free));
|
||||
|
||||
char *p;
|
||||
uint32 stringid = strtoul(str, &p, 16);
|
||||
uint32 stringid = std::strtoul(str, &p, 16);
|
||||
if (*p != ':' && *p != '\0') {
|
||||
while (*p != '\0') p++;
|
||||
str = p;
|
||||
|
@ -926,7 +926,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
|||
bool lookup = (l == SCC_ENCODED);
|
||||
if (lookup) s += len;
|
||||
|
||||
param = strtoull(s, &p, 16);
|
||||
param = std::strtoull(s, &p, 16);
|
||||
|
||||
if (lookup) {
|
||||
if (param >= TAB_SIZE_GAMESCRIPT) {
|
||||
|
|
|
@ -667,7 +667,7 @@ struct TimetableWindow : Window {
|
|||
if (str == nullptr) return;
|
||||
|
||||
const Vehicle *v = this->vehicle;
|
||||
uint64 val = StrEmpty(str) ? 0 : strtoul(str, nullptr, 10);
|
||||
uint64 val = StrEmpty(str) ? 0 : std::strtoul(str, nullptr, 10);
|
||||
auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, query_widget == WID_VT_CHANGE_SPEED);
|
||||
|
||||
switch (query_widget) {
|
||||
|
|
Loading…
Reference in New Issue