maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_strtrim.c File Reference
#include "libft.h"
Include dependency graph for ft_strtrim.c:

Go to the source code of this file.

Functions

static int ft_char_in_set (char c, char const *set)
 
char * ft_strtrim (char const *s1, char const *set)
 

Function Documentation

◆ ft_char_in_set()

static int ft_char_in_set ( char  c,
char const *  set 
)
static

Definition at line 25 of file ft_strtrim.c.

26{
27 size_t i;
28
29 i = 0;
30 while (set[i])
31 {
32 if (set[i] == c)
33 return (1);
34 i++;
35 }
36 return (0);
37}

Referenced by ft_strtrim().

Here is the caller graph for this function:

◆ ft_strtrim()

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

Definition at line 39 of file ft_strtrim.c.

40{
41 char *str;
42 size_t i;
43 size_t start;
44 size_t end;
45
46 if (!s1 || !set)
47 return (NULL);
48 start = 0;
49 while (s1[start] && ft_char_in_set(s1[start], set))
50 start++;
51 end = ft_strlen(s1);
52 while (end > start && ft_char_in_set(s1[end - 1], set))
53 end--;
54 str = (char *)malloc(sizeof(*s1) * (end - start + 1));
55 if (!str)
56 return (NULL);
57 i = 0;
58 while (start < end)
59 str[i++] = s1[start++];
60 str[i] = 0;
61 return (str);
62}
static int ft_char_in_set(char c, char const *set)
Definition ft_strtrim.c:25
size_t ft_strlen(const char *s)
Definition ft_strlen.c:15

References ft_char_in_set(), and ft_strlen().

Referenced by trim_input().

Here is the call graph for this function:
Here is the caller graph for this function: