fix quote je pense ca marche

This commit is contained in:
Camille Chauvet
2023-02-15 20:52:27 +01:00
parent c5467769d9
commit 99fdd578e9
117 changed files with 613 additions and 375 deletions

View File

@ -1,27 +0,0 @@
#include "utils.h"
char *ft_getstr(const char *str, size_t n)
{
size_t start;
size_t stop;
char c;
int quote;
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));
}

Binary file not shown.

43
utils/ft_quote_remover.c Normal file
View File

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_quote_remover.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:12:00 by cchauvet #+# #+# */
/* Updated: 2023/02/15 17:59:50 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
char *ft_quote_remover(char *str)
{
size_t i;
ssize_t start;
ssize_t stop;
start = -1;
i = 0;
while (str[i] != '\0')
{
if ((str[i] == '\"' || str[i] == '\''))
{
if (start == -1)
start = i;
else if (str[i] == str[start])
{
stop = i;
break ;
}
}
i++;
}
if (start != -1)
{
ft_strshift(str, -1);
str[stop] = '\0';
}
return (str);
}

75
utils/ft_split_quoted.c Normal file
View File

@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split_quoted.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 19:04:34 by cchauvet #+# #+# */
/* Updated: 2023/02/15 14:25:56 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
size_t ft_seglen_quoted(const char *str, char c)
{
size_t len;
size_t i;
len = 0;
i = 0;
while (str[i] != 0)
{
while ((str[i] == c || ft_is_in_quote(str, i)) && str[i] != 0)
i++;
if (str[i] != 0)
len++;
while ((str[i] != c || ft_is_in_quote(str, i)) && str[i] != 0)
i++;
}
return (len);
}
static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)
{
size_t tab_index;
size_t let_i;
size_t start;
tab_index = 0;
let_i = 0;
start = 0;
if (tab == NULL || s == NULL)
return (NULL);
while (tab_index < len)
{
while ((s[let_i] == c || ft_is_in_quote(s, let_i)) && s[let_i] != 0)
let_i++;
start = let_i;
while ((s[let_i] != c || ft_is_in_quote(s, let_i)) && s[let_i] != 0)
let_i++;
tab[tab_index] = ft_substr(s, start, let_i - start);
if (tab[tab_index] == NULL)
return (ft_cancel((void *)tab, tab_index));
tab_index++;
}
return (tab);
}
char **ft_split_quoted(const char *s, char c)
{
size_t len;
char **tab;
if (s == NULL)
return (NULL);
len = ft_seglen_quoted(s, c);
tab = malloc((len + 1) * sizeof(char *));
if (tab == NULL)
return (NULL);
tab[len] = NULL;
if (ft_segsplitter(tab, len, s, c) == NULL)
return (NULL);
return (tab);
}

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
#include "utils.h"
char *ft_strreplace(char *str, const char *fill, size_t start, size_t stop)
char *ft_strreplace(const char *str, const char *fill, size_t start, size_t stop)
{
char *out;
size_t sum;

Binary file not shown.

30
utils/ft_strshift.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strshift.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:11:04 by cchauvet #+# #+# */
/* Updated: 2023/02/15 18:16:50 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "utils.h"
void ft_strshift(char *str, int shift)
{
ssize_t i;
if (shift > 0)
return ;
else
{
i = 0;
while (str[i - shift - 1] != '\0')
{
str[i] = str[i - shift];
i++;
}
}
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
/* Updated: 2023/02/14 14:46:41 by cchauvet ### ########.fr */
/* Updated: 2023/02/15 18:00:27 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,10 +17,13 @@
size_t ft_strncpy(char *dst, const char *src, size_t n);
int ft_is_in_quote(const char *str, size_t n);
char *ft_strreplace(char *str, const char *fill,
char *ft_strreplace(const char *str, const char *fill,
size_t start, size_t stop);
ssize_t ft_strnchr(const char *str, char c);
char *ft_getstr(const char *str, size_t n);
void ft_printn(const char *str, size_t n);
char **ft_split_quoted(const char *s, char c);
void ft_strshift(char *str, int shift);
char *ft_quote_remover(char *str);
#endif