wip_parsing
This commit is contained in:
40
libft/str/ft_atoi.c
Normal file
40
libft/str/ft_atoi.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 15:05:03 by madumerg #+# #+# */
|
||||
/* Updated: 2024/03/26 16:17:58 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
int s;
|
||||
|
||||
i = 0;
|
||||
r = 0;
|
||||
s = 1;
|
||||
if (!str)
|
||||
return (0);
|
||||
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
|
||||
i++;
|
||||
if (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
s = -1;
|
||||
i++;
|
||||
}
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
r = r * 10 + str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return (r *= s);
|
||||
}
|
40
libft/str/ft_atoll.c
Normal file
40
libft/str/ft_atoll.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoll.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/09 18:54:27 by madumerg #+# #+# */
|
||||
/* Updated: 2024/03/26 16:18:08 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
long long int ft_atoll(const char *str)
|
||||
{
|
||||
int i;
|
||||
long long int r;
|
||||
int s;
|
||||
|
||||
i = 0;
|
||||
r = 0;
|
||||
s = 1;
|
||||
if (!str)
|
||||
return (0);
|
||||
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
|
||||
i++;
|
||||
if (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
s = -1;
|
||||
i++;
|
||||
}
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
r = r * 10 + str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return (r *= s);
|
||||
}
|
33
libft/str/ft_count_word.c
Normal file
33
libft/str/ft_count_word.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_count_word.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 00:04:58 by madumerg #+# #+# */
|
||||
/* Updated: 2024/05/29 00:05:09 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_count_word(const char *str, char sep)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
count = 0;
|
||||
if (!str || !str[0])
|
||||
return (0);
|
||||
if (str[i++] != sep)
|
||||
count++;
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i - 1] == sep && str[i] != sep)
|
||||
count++;
|
||||
i++;
|
||||
}
|
||||
return (count);
|
||||
}
|
64
libft/str/ft_itoa.c
Normal file
64
libft/str/ft_itoa.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:14:32 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/08 10:22:00 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_len(int n)
|
||||
{
|
||||
int cpt;
|
||||
unsigned int nb;
|
||||
|
||||
cpt = 0;
|
||||
if (n < 0)
|
||||
{
|
||||
cpt++;
|
||||
nb = -n;
|
||||
}
|
||||
else
|
||||
nb = n;
|
||||
while (nb >= 10)
|
||||
{
|
||||
nb /= 10;
|
||||
cpt++;
|
||||
}
|
||||
cpt++;
|
||||
return (cpt);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *str;
|
||||
int cpt;
|
||||
long long int nb;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
nb = n;
|
||||
cpt = ft_len(n);
|
||||
str = ft_calloc((cpt + 1), sizeof(char));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
if (n < 0)
|
||||
{
|
||||
str[0] = '-';
|
||||
i = 1;
|
||||
nb *= -1;
|
||||
}
|
||||
cpt--;
|
||||
while (cpt >= i)
|
||||
{
|
||||
str[cpt] = (nb % 10) + '0';
|
||||
nb /= 10;
|
||||
cpt--;
|
||||
}
|
||||
return (str);
|
||||
}
|
71
libft/str/ft_split.c
Normal file
71
libft/str/ft_split.c
Normal file
@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 12:11:54 by gadelbes #+# #+# */
|
||||
/* Updated: 2024/05/29 00:04:26 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_free(char **s)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
free(s[i]);
|
||||
i++;
|
||||
}
|
||||
free(s);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int ft_count_len(const char *str, char sep)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
|
||||
i = 0;
|
||||
len = 0;
|
||||
while (str[i] && str[i] != sep)
|
||||
{
|
||||
len++;
|
||||
i++;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
char **str;
|
||||
int i;
|
||||
int w;
|
||||
int l;
|
||||
|
||||
i = 0;
|
||||
w = 0;
|
||||
if (!s)
|
||||
return (NULL);
|
||||
str = ft_calloc((ft_count_word((char *)s, c) + 1), sizeof(char *));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (w < ft_count_word(s, c))
|
||||
{
|
||||
while (s[i] == c)
|
||||
i++;
|
||||
l = ft_count_len((s + i), c);
|
||||
str[w] = ft_calloc(l + 1, sizeof(char));
|
||||
if (!str[w])
|
||||
return (ft_free(str));
|
||||
ft_strlcpy(str[w], s + i, l + 1);
|
||||
w++;
|
||||
i += l;
|
||||
}
|
||||
return (str);
|
||||
}
|
31
libft/str/ft_strchr.c
Normal file
31
libft/str/ft_strchr.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 16:16:43 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/07 17:50:18 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *str, int p)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] == (unsigned char)p)
|
||||
return ((char *) &str[i]);
|
||||
i++;
|
||||
}
|
||||
if (str[i] == (unsigned char)p)
|
||||
return ((char *) &str[i]);
|
||||
return (0);
|
||||
}
|
27
libft/str/ft_strcmp.c
Normal file
27
libft/str/ft_strcmp.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/06 12:58:01 by madumerg #+# #+# */
|
||||
/* Updated: 2024/06/24 14:42:39 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] != '\0' || s2[i] != '\0')
|
||||
{
|
||||
if (s2[i] != s1[i])
|
||||
return (s1[i] - s2[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
31
libft/str/ft_strdup.c
Normal file
31
libft/str/ft_strdup.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 10:11:13 by madumerg #+# #+# */
|
||||
/* Updated: 2024/07/11 20:14:23 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *src)
|
||||
{
|
||||
int size;
|
||||
char *dest;
|
||||
|
||||
size = 0;
|
||||
dest = ft_calloc(sizeof(char), (ft_strlen(src) + 1));
|
||||
if (dest == NULL)
|
||||
return (NULL);
|
||||
while (src[size])
|
||||
{
|
||||
dest[size] = src[size];
|
||||
size++;
|
||||
}
|
||||
dest[size] = '\0';
|
||||
return (dest);
|
||||
}
|
27
libft/str/ft_striteri.c
Normal file
27
libft/str/ft_striteri.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:34:05 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/07 18:13:31 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
if (!s || !f)
|
||||
return ;
|
||||
while (s[i])
|
||||
{
|
||||
f(i, &s[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
41
libft/str/ft_strjoin.c
Normal file
41
libft/str/ft_strjoin.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/27 17:26:43 by madumerg #+# #+# */
|
||||
/* Updated: 2024/07/09 15:36:26 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
size_t len;
|
||||
size_t i;
|
||||
size_t j;
|
||||
char *str;
|
||||
|
||||
if (!s1)
|
||||
return (ft_strdup(s2));
|
||||
if (!s2)
|
||||
return (ft_strdup(s1));
|
||||
len = ft_strlen(s1) + ft_strlen(s2);
|
||||
str = malloc(sizeof(char) * (len + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
str[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
j = 0;
|
||||
while (s2[j] != '\0')
|
||||
str[i++] = s2[j++];
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
36
libft/str/ft_strlcat.c
Normal file
36
libft/str/ft_strlcat.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 14:42:26 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/03 14:21:31 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t sdst;
|
||||
size_t ssrc;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
sdst = ft_strlen(dest);
|
||||
ssrc = ft_strlen(src);
|
||||
i = 0;
|
||||
j = sdst;
|
||||
if (sdst > size || size == 0)
|
||||
return (ssrc + size);
|
||||
while (src[i] && (i < size) && (sdst < size - 1))
|
||||
{
|
||||
dest[sdst] = src[i];
|
||||
i++;
|
||||
sdst++;
|
||||
}
|
||||
dest[sdst] = '\0';
|
||||
return (ssrc + j);
|
||||
}
|
30
libft/str/ft_strlcpy.c
Normal file
30
libft/str/ft_strlcpy.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 10:08:10 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/03 12:30:11 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dest, const char *src, size_t destsize)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (destsize > 0)
|
||||
{
|
||||
while (src[i] && i < destsize - 1)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
}
|
||||
return (ft_strlen(src));
|
||||
}
|
23
libft/str/ft_strlen.c
Normal file
23
libft/str/ft_strlen.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 14:07:38 by madumerg #+# #+# */
|
||||
/* Updated: 2024/07/09 17:00:57 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *str)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str && str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
32
libft/str/ft_strmapi.c
Normal file
32
libft/str/ft_strmapi.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:33:40 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/08 09:42:37 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
unsigned int i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
if (!s || !f)
|
||||
return (NULL);
|
||||
str = ft_calloc(ft_strlen(s) + 1, sizeof(char));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (s[i])
|
||||
{
|
||||
str[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
27
libft/str/ft_strncmp.c
Normal file
27
libft/str/ft_strncmp.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 16:12:37 by madumerg #+# #+# */
|
||||
/* Updated: 2024/03/29 11:43:32 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while ((s1[i] != '\0' || s2[i] != '\0') && i < n)
|
||||
{
|
||||
if (s1[i] != s2[i])
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
38
libft/str/ft_strnstr.c
Normal file
38
libft/str/ft_strnstr.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 10:15:03 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/09 16:25:39 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *str, const char *to_find, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (!str)
|
||||
return (NULL);
|
||||
if (to_find[0] == '\0')
|
||||
return ((char *) &str[i]);
|
||||
while (str[i] && i < len)
|
||||
{
|
||||
while (str[i + j] == to_find[j] && i + j < len)
|
||||
{
|
||||
j++;
|
||||
if (to_find[j] == '\0')
|
||||
return ((char *) &str[i]);
|
||||
}
|
||||
j = 0;
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
31
libft/str/ft_strrchr.c
Normal file
31
libft/str/ft_strrchr.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 16:42:24 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/03 15:59:52 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *str, int p)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
i++;
|
||||
while (i > 0)
|
||||
{
|
||||
if (str[i] == (unsigned char)p)
|
||||
return ((char *) &str[i]);
|
||||
i--;
|
||||
}
|
||||
if (str[i] == (unsigned char)p)
|
||||
return ((char *) &str[i]);
|
||||
return (0);
|
||||
}
|
31
libft/str/ft_strtrim.c
Normal file
31
libft/str/ft_strtrim.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:33:52 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/07 17:51:00 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strtrim(char const *s1, char const *set)
|
||||
{
|
||||
size_t start;
|
||||
size_t len;
|
||||
char *str;
|
||||
|
||||
if (!s1)
|
||||
return (NULL);
|
||||
len = ft_strlen(s1);
|
||||
start = 0;
|
||||
while (ft_strchr(set, s1[start]) != 0)
|
||||
start++;
|
||||
while (ft_strrchr(set, s1[len]) != 0)
|
||||
len--;
|
||||
str = ft_substr(s1, start, (len - start) + 1);
|
||||
return (str);
|
||||
}
|
47
libft/str/ft_substr.c
Normal file
47
libft/str/ft_substr.c
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:14:21 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/09 16:27:51 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_min(int lenb, int len)
|
||||
{
|
||||
if (len < lenb)
|
||||
return (len);
|
||||
return (lenb);
|
||||
}
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *str;
|
||||
size_t lenb;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
if (start > ft_strlen(s))
|
||||
return (ft_calloc(1, 1));
|
||||
lenb = ft_strlen(s) - start;
|
||||
str = malloc(sizeof(char) * ft_min(lenb, len) + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
i = start;
|
||||
j = 0;
|
||||
while (s[i] && j < len)
|
||||
{
|
||||
str[j] = s[i];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
str[j] = '\0';
|
||||
return (str);
|
||||
}
|
20
libft/str/ft_tolower.c
Normal file
20
libft/str/ft_tolower.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 14:21:25 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/02 14:59:56 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int i)
|
||||
{
|
||||
if (i >= 'A' && i <= 'Z')
|
||||
i += 32;
|
||||
return (i);
|
||||
}
|
20
libft/str/ft_toupper.c
Normal file
20
libft/str/ft_toupper.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 14:21:13 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/02 15:00:00 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int i)
|
||||
{
|
||||
if (i >= 'a' && i <= 'z')
|
||||
i -= 32;
|
||||
return (i);
|
||||
}
|
Reference in New Issue
Block a user