This repository was archived by the owner on Aug 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
36 lines (32 loc) · 1.3 KB
/
ft_strtrim.c
File metadata and controls
36 lines (32 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: inwagner <inwagner@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/03 18:11:18 by inwagner #+# #+# */
/* Updated: 2023/06/09 15:18:42 by inwagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t i;
size_t j;
size_t size;
if (!s1 || !set)
return (0);
size = ft_strlen(s1);
i = 0;
j = size - 1;
while (ft_strchr(set, s1[i]) && s1[i++])
size--;
while (j > i && ft_strchr(set, s1[j--]))
size--;
return (ft_substr(s1, i, size));
}
/*
Copia `s1` removendo caracteres localizados em `set`.
Retorna a string criada ou nulo caso a alocação falhe.
*/