aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libft_str.h7
-rw-r--r--src/algo/ft_heapsort.c6
-rw-r--r--src/str/ft_strcasecmp.c24
-rw-r--r--src/str/ft_strcmp.c9
-rw-r--r--src/str/ft_strncasecmp.c26
-rw-r--r--src/str/ft_strncmp.c5
-rw-r--r--src/str/ft_strtolower.c26
-rw-r--r--src/str/ft_strtoupper.c26
8 files changed, 123 insertions, 6 deletions
diff --git a/include/libft_str.h b/include/libft_str.h
index e44c995..ba0b203 100644
--- a/include/libft_str.h
+++ b/include/libft_str.h
@@ -6,13 +6,16 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:39:22 by cacharle #+# #+# */
-/* Updated: 2020/01/31 10:39:26 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 04:23:06 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_STR_H
# define LIBFT_STR_H
+# include <stddef.h>
+# include "libft_ctype.h"
+
/*
** std
*/
@@ -50,6 +53,8 @@ int ft_strcount(char *str, char c);
char *ft_itoa(int n);
int ft_strict_atoi(const char *s);
long ft_strtol(const char *s, char **endptr, int base);
+int strcasecmp(const char *s1, const char *s2);
+int strncasecmp(const char *s1, const char *s2, size_t n);
/*
** bloat ?
diff --git a/src/algo/ft_heapsort.c b/src/algo/ft_heapsort.c
index afd395d..d309624 100644
--- a/src/algo/ft_heapsort.c
+++ b/src/algo/ft_heapsort.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/10 02:59:22 by cacharle #+# #+# */
-/* Updated: 2020/02/10 03:57:50 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 04:22:19 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -35,6 +35,10 @@
int ft_heapsort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *))
{
+ (void)base;
+ (void)nel;
+ (void)width;
+ (void)compar;
/* size_t i; */
/* */
/* if (nel < 2) */
diff --git a/src/str/ft_strcasecmp.c b/src/str/ft_strcasecmp.c
new file mode 100644
index 0000000..45ba592
--- /dev/null
+++ b/src/str/ft_strcasecmp.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcasecmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:08:38 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:22:56 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+#include "libft_types.h"
+
+int strcasecmp(const char *s1, const char *s2)
+{
+ while (*s1 && *s2 && ft_tolower(*s1) == ft_tolower(*s2))
+ {
+ s1++;
+ s2++;
+ }
+ return ((t_ftuchar)ft_tolower(*s1) - (t_ftuchar)ft_tolower(*s2));
+}
diff --git a/src/str/ft_strcmp.c b/src/str/ft_strcmp.c
index 1978286..aced711 100644
--- a/src/str/ft_strcmp.c
+++ b/src/str/ft_strcmp.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:16:07 by cacharle #+# #+# */
-/* Updated: 2019/11/21 01:58:27 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 04:18:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,5 +14,10 @@
int ft_strcmp(const char *s1, const char *s2)
{
- return (ft_memcmp(s1, s2, ft_strlen(s1) + 1));
+ while (*s1 && *s2 && *s1 == *s2)
+ {
+ s1++;
+ s2++;
+ }
+ return (*s1 - *s2);
}
diff --git a/src/str/ft_strncasecmp.c b/src/str/ft_strncasecmp.c
new file mode 100644
index 0000000..1b6308d
--- /dev/null
+++ b/src/str/ft_strncasecmp.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strncasecmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:18:36 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:21:10 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+#include "libft_types.h"
+
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ size_t i;
+
+ if (n == 0)
+ return (0);
+ i = 0;
+ while (i + 1 < n && s1[i] && ft_tolower(s1[i]) == ft_tolower(s2[i]))
+ i++;
+ return ((t_ftuchar)ft_tolower(s1[i]) - (t_ftuchar)ft_tolower(s2[i]));
+}
diff --git a/src/str/ft_strncmp.c b/src/str/ft_strncmp.c
index cd303fc..caa052b 100644
--- a/src/str/ft_strncmp.c
+++ b/src/str/ft_strncmp.c
@@ -6,11 +6,12 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:27:34 by cacharle #+# #+# */
-/* Updated: 2019/11/21 01:56:32 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 04:17:50 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
+#include "libft_types.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
@@ -21,5 +22,5 @@ int ft_strncmp(const char *s1, const char *s2, size_t n)
i = 0;
while (i + 1 < n && s1[i] == s2[i] && s1[i])
i++;
- return ((unsigned char)s1[i] - (unsigned char)s2[i]);
+ return ((t_ftuchar)s1[i] - (t_ftuchar)s2[i]);
}
diff --git a/src/str/ft_strtolower.c b/src/str/ft_strtolower.c
new file mode 100644
index 0000000..2eb34c2
--- /dev/null
+++ b/src/str/ft_strtolower.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strtolower.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:10:01 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:12:21 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+#include "libft_ctype.h"
+
+char *ft_strtolower(char *s)
+{
+ int i;
+
+ if (s == NULL)
+ return (NULL);
+ i = -1;
+ while (s[i])
+ s[i] = ft_tolower(s[i]);
+ return (s);
+}
diff --git a/src/str/ft_strtoupper.c b/src/str/ft_strtoupper.c
new file mode 100644
index 0000000..d4c49d5
--- /dev/null
+++ b/src/str/ft_strtoupper.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strtoupper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:12:04 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:12:17 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+#include "libft_ctype.h"
+
+char *ft_strtolower(char *s)
+{
+ int i;
+
+ if (s == NULL)
+ return (NULL);
+ i = -1;
+ while (s[i])
+ s[i] = ft_tolower(s[i]);
+ return (s);
+}