ft_strtrim now passes alelievr/libft-unit-test as do all other functions.
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 6 Sep 2023 11:01:47 +0000 (13:01 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Wed, 6 Sep 2023 11:01:47 +0000 (13:01 +0200)
ft_strtrim.c

index 853a6a4d583e97299a1fd4e68b93efc43e080b36..6fbdb92ba074ccdb48b18ed2585ccaa281888416 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/08/15 15:11:52 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/09/05 19:12:36 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/09/06 12:58:04 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -23,11 +23,13 @@ static size_t       size_needed(const char *s1, const char *set)
        whole = ft_strlen(s1);
        at_start = 0;
        at_end = 0;
-       while (ft_strchr(set, *s1))
+       while (ft_strchr(set, *s1) && *s1)
        {
                ++s1;
                ++at_start;
        }
+       if (*s1 == '\0')
+               return (1);
        while (*s1)
                ++s1;
        --s1;
@@ -50,7 +52,7 @@ char  *ft_strtrim(const char *s1, const char *set)
        res = malloc(size * sizeof(char));
        if (res == NULL)
                return (res);
-       while (ft_strchr(set, *s1))
+       while (ft_strchr(set, *s1) && *s1)
                ++s1;
        ft_strlcpy(res, s1, size);
        return (res);