minishell
ft_strtrim.c File Reference
#include <stddef.h>
#include "ft_string.h"
Include dependency graph for ft_strtrim.c:

Go to the source code of this file.

Functions

char * ft_strtrim (char const *s1, char const *set)
 

Function Documentation

◆ ft_strtrim()

char* ft_strtrim ( char const *  s1,
char const *  set 
)

Definition at line 16 of file ft_strtrim.c.

17 {
18  size_t s1_len;
19  const char *s1_end;
20 
21  if (s1 == NULL)
22  return (NULL);
23  if (set == NULL || *s1 == '\0')
24  return (ft_strdup(s1));
25  s1_len = ft_strlen(s1);
26  s1_end = s1 + s1_len - 1;
27  while (*s1 != '\0' && ft_strchr(set, *s1) != NULL)
28  s1++;
29  if (*s1 == '\0')
30  return (ft_strdup(""));
31  while (ft_strchr(set, *s1_end) != NULL)
32  s1_end--;
33  return (ft_strndup(s1, (size_t)s1_end - (size_t)s1 + 1));
34 }
char * ft_strchr(const char *s, int c)
Definition: ft_strchr.c:15
char * ft_strdup(const char *s1)
Definition: ft_strdup.c:16
char * ft_strndup(const char *s1, size_t n)
Definition: ft_strndup.c:18
size_t ft_strlen(const char *s)
Definition: ft_strlen.c:15
Here is the call graph for this function: