This commit is contained in:
2021-12-16 22:13:30 +08:00
parent 751373e0e4
commit 556ab106f4
9 changed files with 345 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
#include <malloc.h>
#include <string.h>
#include <ctype.h>
int cstr_util_copy_str(char** dest, const char* str) {
if (!dest || !str) return 1;
@@ -15,3 +16,14 @@ int cstr_util_copy_str(char** dest, const char* str) {
*dest = temp;
return 0;
}
int cstr_is_integer(const char* str, int allow_sign) {
if (!str) return 0;
size_t le = strlen(str), i = 0;
if (!le) return 0;
if (allow_sign && le > 1 && (str[0] == '+' || str[0] == '-')) i++;
for (; i < le; i++) {
if (!isdigit(str[i])) return 0;
}
return 1;
}