forked from netblock/yaabe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandard.c
More file actions
73 lines (69 loc) · 1.05 KB
/
standard.c
File metadata and controls
73 lines (69 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "standard.h"
int64_t
strtoll_2(
char const* str
) {
// TODO it seems the C2X's changes for the strto* hasn't landed yet
uint8_t base = 0; // 0 = auto
if ((str[0] == '0') && (str[1] == 'b')) {
base = 2;
str += 2;
}
return strtoll(str, NULL, base);
}
uint64_t
strtoull_2(
char const* str
) {
// TODO it seems the C2X's changes for the strto* hasn't landed yet
uint8_t base = 0; // 0 = auto
if ((str[0] == '0') && (str[1] == 'b')) {
base = 2;
str += 2;
}
return strtoull(str, NULL, base);
}
bool
is_number(
char const* str
) {
// test string if it's a decimal integer
if (str) {
do {
if (0 == isdigit(*str)) {
return false;
}
str++;
} while (*str);
return true;
} else {
return false;
}
}
char*
stopcopy(
char* restrict dest,
char const* restrict src
) {
// custom stpcpy
while(*src) {
*dest = *src;
dest++;
src++;
}
*dest = '\0';
return dest;
}
bool
char_in_string(
char const ch,
char const* str
) {
while (*str) {
if (ch == *str) {
return true;
}
str++;
}
return false;
}