-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
55 lines (50 loc) · 1.73 KB
/
ft_strtrim.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yuske <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/01 20:35:51 by yuske #+# #+# */
/* Updated: 2022/11/26 17:12:14 by yuske ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// while ((s1[i] >= '\t' && s1[i] <= '\r') || s1[i] == ' ')
// i++;
// while ((s1[end] >= 9 && s1[end] <= 13) || s1[end] == 32)
// end--;
//14L
char *ft_strtrim(char const *s1, char const *set)
{
char *trimmed;
size_t head;
size_t tail;
if (!s1 || !set)
return (NULL);
head = 0;
tail = ft_strlen(s1) - 1;
while (ft_strchr(set, s1[head]))
head++;
while (ft_strchr(set, s1[tail]))
tail--;
trimmed = ft_substr(s1, head, tail - head + 1);
return (trimmed);
}
//14L
// char *ft_strtrim(char const *s1, char const *set)
// {
// char *trimmed;
// size_t head;
// size_t tail;
// if (!s1 || !set)
// return (NULL);
// head = 0;
// tail = ft_strlen(s1) - 1;
// while (ft_strrchr(set, s1[head]))
// head++;
// while (ft_strrchr(set, s1[tail]))
// tail--;
// trimmed = ft_substr(s1, head, tail - head + 1);
// return (trimmed);
// }