Add str_toint64_base

To convert a string to an `int64_t`.
This commit is contained in:
Robert Müller 2023-06-05 20:57:54 +02:00
parent aea45741a0
commit 2be3ecfd4f
2 changed files with 25 additions and 4 deletions

View file

@ -3430,10 +3430,30 @@ int str_isallnum(const char *str)
return 1;
}
int str_toint(const char *str) { return str_toint_base(str, 10); }
int str_toint_base(const char *str, int base) { return strtol(str, NULL, base); }
unsigned long str_toulong_base(const char *str, int base) { return strtoul(str, NULL, base); }
float str_tofloat(const char *str) { return strtod(str, NULL); }
int str_toint(const char *str)
{
return str_toint_base(str, 10);
}
int str_toint_base(const char *str, int base)
{
return strtol(str, nullptr, base);
}
unsigned long str_toulong_base(const char *str, int base)
{
return strtoul(str, nullptr, base);
}
int64_t str_toint64_base(const char *str, int base)
{
return strtoll(str, nullptr, base);
}
float str_tofloat(const char *str)
{
return strtod(str, nullptr);
}
int str_utf8_comp_nocase(const char *a, const char *b)
{

View file

@ -2133,6 +2133,7 @@ void net_stats(NETSTATS *stats);
int str_toint(const char *str);
int str_toint_base(const char *str, int base);
unsigned long str_toulong_base(const char *str, int base);
int64_t str_toint64_base(const char *str, int base = 10);
float str_tofloat(const char *str);
/**