-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
50 lines (46 loc) · 1.71 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ana-lda- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 12:32:41 by ana-lda- #+# #+# */
/* Updated: 2024/04/30 17:20:39 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/** @brief remove os characteres especificados em set de s1 no inicio
e no final da string
@param s1 string a ser aparada
@param set characeres a serem cortados
@return a string aparada
*/
// linha 38 - Extrai a substring de s1 que começa
// no índice first e termina no índice last - 1.
char *ft_strtrim(char const *s1, char const *set)
{
size_t first;
size_t last;
char *final;
final = NULL;
if (s1 && set)
{
first = 0;
last = ft_strlen(s1);
while (s1[first] && first < last && ft_strchr(set, s1[first]) != NULL)
first++;
while (s1[last -1] && first < last && \
ft_strchr(set, s1[last -1]) != NULL)
last--;
final = ft_substr(s1, first, last - first);
}
return (final);
}
/*#include <stdio.h>
int main(void)
{
const char s1[] = "abcdef";
const char set[] = "a";
printf("%s\n", ft_strtrim(s1, set));
}*/