Push libft

125/100 corrected the 14/11/23
This commit is contained in:
Raphaël 2023-11-14 13:31:56 +01:00 committed by GitHub
commit 7bd66aee5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 1462 additions and 0 deletions

40
ft_strtrim.c Normal file
View file

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 13:55:44 by rparodi #+# #+# */
/* Updated: 2023/11/13 20:08:51 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t i;
size_t j;
size_t k;
char *str;
if (!s1)
return (NULL);
i = 0;
while (ft_strchr(set, s1[i]) != NULL && s1[i])
i++;
if (i == ft_strlen(s1))
return (ft_strdup(""));
j = ft_strlen(s1);
while (ft_strrchr(set, s1[j - 1]) != NULL && j > i)
j--;
str = (char *)malloc(j - i + 1);
if (!str)
return (NULL);
k = 0;
while (i < j)
str[k++] = s1[i++];
str[k] = '\0';
return (str);
}