aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-10 05:24:41 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-10 05:24:41 +0100
commitfe15975761f2dcb52d360a521c5ef912d66d5e1c (patch)
treea94148816bc4f826eab9b18c9010d922d7c280c9
parent8e3c9342ce7e4932c4a59c0823af63d19ade8046 (diff)
downloadlibft-fe15975761f2dcb52d360a521c5ef912d66d5e1c.tar.gz
libft-fe15975761f2dcb52d360a521c5ef912d66d5e1c.tar.bz2
libft-fe15975761f2dcb52d360a521c5ef912d66d5e1c.zip
Added ft_reverse, ft_isblank, ft_strnlen, ft_strpbrk, ft_strsep
-rw-r--r--include/libft_algo.h3
-rw-r--r--include/libft_ctype.h3
-rw-r--r--include/libft_str.h5
-rw-r--r--src/algo/ft_reverse.c27
-rw-r--r--src/ctype/ft_isblank.c16
-rw-r--r--src/str/ft_strnlen.c25
-rw-r--r--src/str/ft_strpbrk.c24
-rw-r--r--src/str/ft_strsep.c27
-rw-r--r--src/str/ft_strtoupper.c2
9 files changed, 128 insertions, 4 deletions
diff --git a/include/libft_algo.h b/include/libft_algo.h
index 14496dd..65308b8 100644
--- a/include/libft_algo.h
+++ b/include/libft_algo.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/19 07:22:57 by cacharle #+# #+# */
-/* Updated: 2020/02/10 03:04:17 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 05:17:39 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,5 +42,6 @@ int ft_mergesort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *));
int ft_heapsort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *));
+void ft_reverse(void *base, size_t nel, size_t width);
#endif
diff --git a/include/libft_ctype.h b/include/libft_ctype.h
index 85e0e05..ad42c64 100644
--- a/include/libft_ctype.h
+++ b/include/libft_ctype.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:35:31 by cacharle #+# #+# */
-/* Updated: 2020/01/31 10:36:34 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 05:18:30 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,6 +23,7 @@ int ft_isalnum(int c);
int ft_isascii(int c);
int ft_isprint(int c);
int ft_isspace(int c);
+int ft_isblank(int c);
/*
** conversion
diff --git a/include/libft_str.h b/include/libft_str.h
index 80fb09f..e3faeab 100644
--- a/include/libft_str.h
+++ b/include/libft_str.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:39:22 by cacharle #+# #+# */
-/* Updated: 2020/02/10 04:32:44 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 05:24:00 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -57,6 +57,9 @@ int ft_strcasecmp(const char *s1, const char *s2);
int ft_strncasecmp(const char *s1, const char *s2, size_t n);
size_t ft_strspn(const char *s, const char *charset);
size_t ft_strcspn(const char *s, const char *charset);
+char *ft_strpbrk(const char *s, const char *charset);
+char *ft_strsep(char **stringp, const char *delim);
+size_t ft_strnlen(const char *s, size_t maxlen);
/*
** bloat ?
diff --git a/src/algo/ft_reverse.c b/src/algo/ft_reverse.c
new file mode 100644
index 0000000..0bc447f
--- /dev/null
+++ b/src/algo/ft_reverse.c
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_reverse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 05:07:13 by cacharle #+# #+# */
+/* Updated: 2020/02/10 05:19:22 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_algo.h"
+
+void ft_reverse(void *base, size_t nel, size_t width)
+{
+ size_t i;
+
+ i = 0;
+ nel--;
+ while (i < nel)
+ {
+ ft_memswap(base + i * width, base + nel * width, width);
+ i++;
+ nel--;
+ }
+}
diff --git a/src/ctype/ft_isblank.c b/src/ctype/ft_isblank.c
new file mode 100644
index 0000000..def106b
--- /dev/null
+++ b/src/ctype/ft_isblank.c
@@ -0,0 +1,16 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_isblank.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 05:17:45 by cacharle #+# #+# */
+/* Updated: 2020/02/10 05:18:34 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+int ft_isblank(int c)
+{
+ return (c == ' ' || c == '\t');
+}
diff --git a/src/str/ft_strnlen.c b/src/str/ft_strnlen.c
new file mode 100644
index 0000000..5e1569c
--- /dev/null
+++ b/src/str/ft_strnlen.c
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strnlen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 05:21:04 by cacharle #+# #+# */
+/* Updated: 2020/02/10 05:23:23 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+/*
+** wrong implementation since it scans beyond maxlen
+*/
+
+size_t ft_strnlen(const char *s, size_t maxlen)
+{
+ size_t len;
+
+ len = ft_strlen(s);
+ return (len > maxlen ? maxlen : len);
+}
diff --git a/src/str/ft_strpbrk.c b/src/str/ft_strpbrk.c
new file mode 100644
index 0000000..753e4d9
--- /dev/null
+++ b/src/str/ft_strpbrk.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strpbrk.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:39:29 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:54:13 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+char *ft_strpbrk(const char *s, const char *charset)
+{
+ if (s == NULL || charset == NULL)
+ return (NULL);
+ while (*s && ft_strchr(charset, *s) == NULL)
+ s++;
+ if (*s == '\0')
+ return (NULL);
+ return ((char*)s);
+}
diff --git a/src/str/ft_strsep.c b/src/str/ft_strsep.c
new file mode 100644
index 0000000..2000706
--- /dev/null
+++ b/src/str/ft_strsep.c
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strsep.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:44:11 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:51:15 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+char *ft_strsep(char **stringp, const char *delim)
+{
+ char *tmp;
+
+ if (stringp == NULL || *stringp == NULL || delim == NULL)
+ return (NULL);
+ tmp = ft_strpbrk(*stringp, delim);
+ if (tmp == NULL)
+ return (NULL);
+ *tmp = '\0';
+ *stringp = tmp;
+ return (tmp);
+}
diff --git a/src/str/ft_strtoupper.c b/src/str/ft_strtoupper.c
index d4c49d5..07c19e5 100644
--- a/src/str/ft_strtoupper.c
+++ b/src/str/ft_strtoupper.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/10 04:12:04 by cacharle #+# #+# */
-/* Updated: 2020/02/10 04:12:17 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 05:05:38 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */