-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_str6.c
82 lines (71 loc) · 1.84 KB
/
ft_str6.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str6.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lgillot- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/19 01:55:48 by lgillot- #+# #+# */
/* Updated: 2015/11/19 01:59:41 by lgillot- ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include <stdbool.h>
#include <ft_str.h>
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
unsigned int i;
i = 0;
while (*s)
f(i++, s++);
}
char *ft_strmap(char const *s, char (*f)(char))
{
size_t len;
char *new_str;
unsigned int i;
len = ft_strlen(s);
new_str = ft_strnew(len);
if (new_str)
{
i = 0;
while (i < len)
{
new_str[i] = f(s[i]);
i++;
}
}
return (new_str);
}
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
size_t len;
char *new_str;
unsigned int i;
len = ft_strlen(s);
new_str = ft_strnew(len);
if (new_str)
{
i = 0;
while (i < len)
{
new_str[i] = f(i, s[i]);
i++;
}
}
return (new_str);
}
static bool is_space(char c)
{
return (c == ' ' || c == '\n' || c == '\t');
}
char *ft_strtrim(char const *s)
{
size_t size;
while (is_space(*s))
s++;
size = ft_strlen(s);
while (is_space(s[size - 1]) && size > 0)
size--;
return (ft_strsub(s, 0, size));
}