38 lines
1.2 KiB
C
38 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strtrim.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/10/04 20:21:56 by aortigos #+# #+# */
|
|
/* Updated: 2023/10/19 16:58:30 by aortigos ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strtrim(char const *s1, char const *set)
|
|
{
|
|
size_t len;
|
|
char *x;
|
|
|
|
if (!s1 || !set)
|
|
return (NULL);
|
|
while (ft_strchr(set, *s1) && *s1 != '\0')
|
|
{
|
|
s1++;
|
|
}
|
|
if (*s1 == '\0')
|
|
{
|
|
return (ft_strdup(""));
|
|
}
|
|
len = ft_strlen(s1);
|
|
while (ft_strchr(set, s1[len]))
|
|
{
|
|
len--;
|
|
}
|
|
x = ft_substr(s1, 0, len + 1);
|
|
return (x);
|
|
}
|