mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-23 12:16:53 +08:00
Update
This commit is contained in:
12
cstr_util.c
12
cstr_util.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user