add tk_strtoll

This commit is contained in:
lixianjing 2021-01-04 17:21:05 +08:00
parent e003ee2f29
commit 85afb0b9fd
2 changed files with 53 additions and 14 deletions

View File

@ -224,6 +224,10 @@ long tk_strtol(const char* str, const char** end, int base) {
return strtol(str, (char**)end, base);
}
int64_t tk_strtoll(const char* str, const char** end, int base) {
return strtoll(str, (char**)end, base);
}
const char* tk_itoa(char* str, int len, int n) {
return_value_if_fail(str != NULL, NULL);
@ -244,6 +248,17 @@ int tk_atoi(const char* str) {
}
}
int64_t tk_atol(const char* str) {
return_value_if_fail(str != NULL, 0);
if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
return tk_strtoll(str + 2, NULL, 16);
} else if (str[0] == '0' && (str[1] == 'b' || str[1] == 'B')) {
return tk_strtoll(str + 2, NULL, 2);
} else {
return tk_strtoll(str, NULL, 10);
}
}
const char* tk_ftoa(char* str, int len, double value) {
tk_snprintf(str, len, "%lf", value);

View File

@ -38,14 +38,25 @@ BEGIN_C_DECLS
/**
* @method tk_atoi
*
*
*
*
* @param {const char*} str
* @param {const char*} str
*
* @return {int}
* @return {int}
*/
int tk_atoi(const char* str);
/**
* @method tk_atol
*
*
*
* @param {const char*} str
*
* @return {int}
*/
int64_t tk_atol(const char* str);
/**
* @method tk_atob
*
@ -95,23 +106,23 @@ int32_t tk_str_icmp(const char* a, const char* b);
/**
* @method tk_watoi
*
*
*
*
* @param {const wchar_t*} str
* @param {const wchar_t*} str
*
* @return {int}
* @return {int}
*/
int tk_watoi(const wchar_t* str);
/**
* @method tk_watoi_n
*
*
*
*
* @param {const wchar_t*} str
* @param {const wchar_t*} str
* @param {uint32_t} len
*
* @return {int}
* @return {int}
*/
int tk_watoi_n(const wchar_t* str, uint32_t len);
@ -151,11 +162,11 @@ const char* tk_skip_to_num(const char* str);
/**
* @method tk_itoa
*
*
*
*
* @param {char*} str
* @param {int} len
* @param {int} n
* @param {int} n
*
* @return {const char*}
*/
@ -177,16 +188,29 @@ const char* tk_ftoa(char* str, int len, double f);
/**
* @method tk_strtol
*
*
*
*
* @param {const char*} str
* @param {const char*} str
* @param {const char**} end char*
* @param {int} base
*
* @return {long}
* @return {long}
*/
long tk_strtol(const char* str, const char** end, int base);
/**
* @method tk_strtoll
*
*
*
* @param {const char*} str
* @param {const char**} end char*
* @param {int} base
*
* @return {int64_t}
*/
int64_t tk_strtoll(const char* str, const char** end, int base);
/**
* @method tk_strcpy
*