42_minishell/utils/ft_getstr.c

28 lines
422 B
C
Raw Normal View History

2023-02-01 11:28:38 -05:00
#include "utils.h"
2023-02-14 01:26:18 -05:00
char *ft_getstr(const char *str, size_t n)
2023-02-01 11:28:38 -05:00
{
size_t start;
size_t stop;
char c;
2023-02-14 01:26:18 -05:00
int quote;
2023-02-01 11:28:38 -05:00
start = n;
stop = n;
quote = ft_is_in_quote(str, n);
if (quote == 0)
c = ' ';
else
{
if (quote == 1)
c = '\'';
else
c = '"';
}
while (str[start - 1] != c && start > 0)
start--;
while (str[stop] != c && str[stop] != '\0')
stop++;
return (ft_strndup(str + start, stop - start));
}