Push sur ta branche

This commit is contained in:
Etienne Rey-bethbeder
2023-02-02 17:40:09 +01:00
27 changed files with 268 additions and 42 deletions

BIN
utils/.ft_is_a_quote.c.swp Normal file

Binary file not shown.

27
utils/ft_getstr.c Normal file
View File

@ -0,0 +1,27 @@
#include "utils.h"
char *ft_getstr(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));
}

BIN
utils/ft_getstr.o Normal file

Binary file not shown.

29
utils/ft_is_in_quote.c Normal file
View File

@ -0,0 +1,29 @@
#include "utils.h"
int ft_is_in_quote(char *str, size_t n)
{
size_t double_quoted;
size_t simple_quoted;
size_t i;
double_quoted = 0;
simple_quoted = 0;
i = 0;
while (str[i] != '\0' && i < n)
{
if (str[i] == '"')
{
if (simple_quoted == 0)
double_quoted = !double_quoted;
}
if (str[i] == '\'')
{
if (double_quoted == 0)
simple_quoted = !simple_quoted;
}
i++;
}
return (simple_quoted == 1 + (double_quoted == 1) * 2);
}

BIN
utils/ft_is_in_quote.o Normal file

Binary file not shown.

15
utils/ft_strnchr.c Normal file
View File

@ -0,0 +1,15 @@
#include "utils.h"
ssize_t ft_strnchr(char *str, char c)
{
size_t i;
i = 0;
while (str[i] != '\0')
{
if (str[i] == c)
return (i);
i++;
}
return (-1);
}

BIN
utils/ft_strnchr.o Normal file

Binary file not shown.

14
utils/ft_strncpy.c Normal file
View File

@ -0,0 +1,14 @@
#include "utils.h"
size_t ft_strncpy(char *dst, char *src, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
dst[i] = src[i];
i++;
}
return (i);
}

BIN
utils/ft_strncpy.o Normal file

Binary file not shown.

17
utils/ft_strreplace.c Normal file
View File

@ -0,0 +1,17 @@
#include "utils.h"
char *ft_strreplace(char *str, char *fill, size_t start, size_t stop)
{
char *out;
size_t sum;
out = malloc((ft_strlen(str) + ft_strlen(fill) - (stop - start) + 1 * sizeof(char)));
if (out == NULL)
return (NULL);
ft_strncpy(out, str, start);
ft_strncpy(out + start, fill, ft_strlen(fill));
sum = start + ft_strlen(fill);
ft_strncpy(out + sum, str + stop, ft_strlen(str) - stop);
out[sum + ft_strlen(str) - stop] = '\0';
return (out);
}

BIN
utils/ft_strreplace.o Normal file

Binary file not shown.

12
utils/utils.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef FT_UTILS
# define FT_UTILS
# include <stdlib.h>
# include "../libftx/libftx.h"
size_t ft_strncpy(char *dst, char *src, size_t n);
int ft_is_in_quote(char *str, size_t n);
char *ft_strreplace(char *str, char *fill, size_t start, size_t stop);
ssize_t ft_strnchr(char *str, char c);
char *ft_getstr(char *str, size_t n);
#endif