base struct
This commit is contained in:
31
lib/libft/srcs/str/ft_strchr.c
Normal file
31
lib/libft/srcs/str/ft_strchr.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 09:06:01 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:15:57 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
int i;
|
||||
char ch;
|
||||
|
||||
ch = c;
|
||||
i = 0;
|
||||
if (ch == '\0')
|
||||
return ((char *)&s[ft_strlen(s)]);
|
||||
while (s[i] != 0)
|
||||
{
|
||||
if (s[i] == ch)
|
||||
return ((char *)&s[i]);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
30
lib/libft/srcs/str/ft_strdup.c
Normal file
30
lib/libft/srcs/str/ft_strdup.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 15:38:09 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:02 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_strdup(const char *s1)
|
||||
{
|
||||
char *out;
|
||||
unsigned long int i;
|
||||
|
||||
out = ft_calloc(ft_strlen(s1) + 1, sizeof(char));
|
||||
if (!out || !s1)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s1[i])
|
||||
{
|
||||
out[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
24
lib/libft/srcs/str/ft_striteri.c
Normal file
24
lib/libft/srcs/str/ft_striteri.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 17:17:33 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:05 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!s || !f)
|
||||
return ;
|
||||
i = -1;
|
||||
while (s[++i])
|
||||
f(i, &s[i]);
|
||||
}
|
||||
38
lib/libft/srcs/str/ft_strjoin.c
Normal file
38
lib/libft/srcs/str/ft_strjoin.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 17:14:32 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:11 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_strjoin(const char *s1, const char *s2)
|
||||
{
|
||||
char *out;
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
|
||||
if (!s1 && !s2)
|
||||
return (NULL);
|
||||
if (!s1)
|
||||
return (ft_strdup(s2));
|
||||
if (!s2)
|
||||
return (ft_strdup(s1));
|
||||
out = ft_calloc(ft_strlen(s1) + ft_strlen(s2) + 1, sizeof(char));
|
||||
if (!out)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s1[j])
|
||||
out[i++] = s1[j++];
|
||||
j = 0;
|
||||
while (s2[j])
|
||||
out[i++] = s2[j++];
|
||||
return (out);
|
||||
}
|
||||
32
lib/libft/srcs/str/ft_strlcat.c
Normal file
32
lib/libft/srcs/str/ft_strlcat.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/12 10:07:49 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:15 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
|
||||
{
|
||||
size_t dst_len;
|
||||
size_t src_len;
|
||||
size_t i;
|
||||
|
||||
if (!dst || !src)
|
||||
return (0);
|
||||
dst_len = ft_strlen(dst);
|
||||
src_len = ft_strlen(src);
|
||||
if (dstsize <= dst_len)
|
||||
return (dstsize + src_len);
|
||||
i = -1;
|
||||
while (src[++i] && (dst_len + i) < (dstsize - 1))
|
||||
dst[dst_len + i] = src[i];
|
||||
dst[dst_len + i] = '\0';
|
||||
return (dst_len + src_len);
|
||||
}
|
||||
28
lib/libft/srcs/str/ft_strlcpy.c
Normal file
28
lib/libft/srcs/str/ft_strlcpy.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/12 10:07:49 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:20 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!dst || !src)
|
||||
return (0);
|
||||
if (dstsize == 0)
|
||||
return (ft_strlen(src));
|
||||
i = -1;
|
||||
while (++i < dstsize - 1 && src[i])
|
||||
dst[i] = src[i];
|
||||
dst[i] = 0;
|
||||
return (ft_strlen(src));
|
||||
}
|
||||
25
lib/libft/srcs/str/ft_strlen.c
Normal file
25
lib/libft/srcs/str/ft_strlen.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/10 12:01:43 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:24 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!s)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (s[i] != 0)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
32
lib/libft/srcs/str/ft_strmapi.c
Normal file
32
lib/libft/srcs/str/ft_strmapi.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 16:32:03 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:28 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
size_t len;
|
||||
unsigned int i;
|
||||
char *out;
|
||||
|
||||
if (!s || !f)
|
||||
return (NULL);
|
||||
len = ft_strlen(s);
|
||||
out = (char *)ft_calloc(len + 1, sizeof(char));
|
||||
if (!out)
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (++i < len)
|
||||
out[i] = f(i, s[i]);
|
||||
out[len] = '\0';
|
||||
return (out);
|
||||
}
|
||||
33
lib/libft/srcs/str/ft_strncmp.c
Normal file
33
lib/libft/srcs/str/ft_strncmp.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 10:58:07 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:32 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *ss1;
|
||||
unsigned char *ss2;
|
||||
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
i = 0;
|
||||
ss1 = (unsigned char *)s1;
|
||||
ss2 = (unsigned char *)s2;
|
||||
if (n == 0)
|
||||
return (0);
|
||||
while (i < n && ss1[i] && ss2[i] && ss1[i] == ss2[i])
|
||||
i++;
|
||||
if (i == n)
|
||||
return (0);
|
||||
return (ss1[i] - ss2[i]);
|
||||
}
|
||||
37
lib/libft/srcs/str/ft_strnstr.c
Normal file
37
lib/libft/srcs/str/ft_strnstr.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 12:45:20 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:35 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
if (!haystack || !needle)
|
||||
return (NULL);
|
||||
if (needle[0] == 0)
|
||||
return ((char *)haystack);
|
||||
while (haystack[i] && i < len)
|
||||
{
|
||||
j = 0;
|
||||
while (haystack[i + j] == needle[j] && i + j < len)
|
||||
{
|
||||
j++;
|
||||
if (needle[j] == 0)
|
||||
return ((char *)(haystack + i));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
26
lib/libft/srcs/str/ft_strrchr.c
Normal file
26
lib/libft/srcs/str/ft_strrchr.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 09:06:01 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:38 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
i = ft_strlen(s) + 1;
|
||||
while (--i >= 0)
|
||||
if (s[i] == (char)c)
|
||||
return ((char *)&s[i]);
|
||||
return (NULL);
|
||||
}
|
||||
77
lib/libft/srcs/str/ft_strtrim.c
Normal file
77
lib/libft/srcs/str/ft_strtrim.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 17:42:56 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:44 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
static int ft_instr(int c, char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (str[++i])
|
||||
if (str[i] == c)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ft_gettrimstart(const char *str, const char *set)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (ft_instr(str[i], (char *)set) && str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
static int ft_gettrimend(const char *str, const char *set)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (ft_instr(str[ft_strlen(str) - i - 1], (char *)set))
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
static void trloop(char *cpy, const char *s1, size_t trimstart, size_t trimend)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < ft_strlen(s1) - (trimstart + trimend))
|
||||
{
|
||||
cpy[i] = s1[trimstart + i];
|
||||
i++;
|
||||
}
|
||||
cpy[i] = 0;
|
||||
}
|
||||
|
||||
char *ft_strtrim(const char *s1, const char *set)
|
||||
{
|
||||
char *cpy;
|
||||
size_t trimstart;
|
||||
size_t trimend;
|
||||
|
||||
if (!s1 || !set)
|
||||
return (NULL);
|
||||
cpy = (char *)s1;
|
||||
trimstart = ft_gettrimstart(s1, set);
|
||||
if (trimstart == ft_strlen(s1))
|
||||
return (ft_strdup(""));
|
||||
trimend = ft_gettrimend(s1, set);
|
||||
cpy = ft_calloc(ft_strlen(s1) - (trimstart + trimend) + 1, sizeof(char));
|
||||
if (!cpy)
|
||||
return (NULL);
|
||||
trloop(cpy, s1, trimstart, trimend);
|
||||
return (cpy);
|
||||
}
|
||||
37
lib/libft/srcs/str/ft_substr.c
Normal file
37
lib/libft/srcs/str/ft_substr.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 16:17:16 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:49 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_substr(const char *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *sub;
|
||||
size_t i;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
if (start >= ft_strlen(s))
|
||||
return (ft_strdup(""));
|
||||
if ((size_t)start + len > ft_strlen(s))
|
||||
sub = ft_calloc(ft_strlen(s) - (size_t)start + 1, sizeof(char));
|
||||
else
|
||||
sub = ft_calloc(len + 1, sizeof(char));
|
||||
if (!sub)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (sub && i < len && s[start + i] != 0)
|
||||
{
|
||||
sub[i] = s[start + i];
|
||||
i++;
|
||||
}
|
||||
return (sub);
|
||||
}
|
||||
21
lib/libft/srcs/str/ft_tolower.c
Normal file
21
lib/libft/srcs/str/ft_tolower.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/12 12:07:21 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/27 12:58:25 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 65 && c <= 90)
|
||||
return (c + 32);
|
||||
else
|
||||
return (c);
|
||||
}
|
||||
21
lib/libft/srcs/str/ft_toupper.c
Normal file
21
lib/libft/srcs/str/ft_toupper.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/12 12:01:30 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/27 12:58:24 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 97 && c <= 122)
|
||||
return (c - 32);
|
||||
else
|
||||
return (c);
|
||||
}
|
||||
Reference in New Issue
Block a user