-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_aux.ino
76 lines (66 loc) · 1.34 KB
/
ft_aux.ino
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
74
75
76
#include "BlueTest.h"
//When you need to waste some time
void ft_wasteTime(unsigned int t) {
for (long int refTime = millis(); millis() - refTime < t;);
}
// Useful function when debugging.
// Prints a char* in hexadecimal on SerialUSB
void ft_USBputStr(char *str) {
int len;
len = strlen(str);
for (int i = 0; i < len; i++)
SerialUSB.print(str[i], HEX);
SerialUSB.println("");
}
void ft_strfree(char *str) {
if (str) {
free(str);
str = NULL;
}
}
char *ft_strnew(size_t size) {
size_t i;
char *res;
i = 0;
if (!(res = (char *)malloc(size + 1))){
return (NULL);
}
while (i <= size)
{
res[i] = '\0';
i++;
}
return (res);
}
char *ft_strsub(char *s, size_t start, size_t len)
{
char *sub;
int i = 0;
if (!s)
return (NULL);
s = s + start;
if (len == 0)
len = strlen(s);
if (!(sub = ft_strnew(len)))
return (NULL);
while (i < len && (sub[i] = s[i]) && s[i] != '\0')
i++;
return (sub);
}
char *ft_scj(char *s, char c)
{
int i;
char *res;
i = 0;
if (!s && !(s = ft_strnew(0)))
return (NULL);
if (!(res = ft_strnew(strlen(s) + 1)))
return (NULL);
while (s[i] != '\0' && (res[i] = s[i]))
i++;
res[i] = c;
free(s);
s = NULL;
res[i + 1] = '\0';
return (res);
}