-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
107 lines (96 loc) · 2.38 KB
/
get_next_line_utils_bonus.c
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebouabba <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/05 19:52:02 by ebouabba #+# #+# */
/* Updated: 2021/12/05 19:53:23 by ebouabba ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
int ft_strlen_bs(char *s)
{
int i;
i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}
int ft_backslash_bs(char *s)
{
int i;
i = 0;
if (s)
while (s[i++])
if (s[i] == '\n')
return (1);
return (0);
}
char *ft_strjoin_bs(char *var_static, char *var)
{
size_t i;
size_t j;
char *nv_var;
if (!var_static)
var_static = ft_strdup_bs("");
if (!var_static || !var)
return (NULL);
nv_var = malloc(sizeof(char)
* (ft_strlen_bs(var) + ft_strlen_bs(var_static) + 1));
if (!nv_var)
return (NULL);
i = -1;
if (var_static)
while (var_static[++i] != '\0')
nv_var[i] = var_static[i];
j = 0;
while (var[j] != '\0')
nv_var[i++] = var[j++];
nv_var[i] = '\0';
free(var_static);
return (nv_var);
}
char *ft_strdup_bs(const char *s1)
{
size_t i;
size_t len;
char *s2;
len = ft_strlen_bs((char *)s1);
s2 = (char *)malloc(sizeof(char) * (len + 1));
if (!s2)
return (NULL);
i = 0;
while (s1[i] != '\0')
{
s2[i] = s1[i];
i++;
}
s2[i] = '\0';
return (s2);
}
char *ft_substr_bs(char *var_static, int start, int len)
{
char *nev_var;
int i;
i = -1;
if (start >= ft_strlen_bs(var_static))
{
nev_var = malloc(sizeof(char));
nev_var[0] = 0;
return (nev_var);
}
if (len > (ft_strlen_bs(var_static) - start))
nev_var = malloc(ft_strlen_bs(var_static) - start + 1);
else
nev_var = malloc(len + 1);
if (!nev_var)
return (NULL);
while (var_static[start + ++i] && i < len)
nev_var[i] = var_static[start + i];
nev_var[i] = 0;
return (nev_var);
}