aboutsummaryrefslogtreecommitdiff
path: root/libft/src/str
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-11 15:52:52 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-11 15:52:52 +0200
commitc98de126d2252fe47dc2a9094a5f9a8fa6b4b60a (patch)
tree12f1c827ee063ed3e7038f6a704014e611e4f388 /libft/src/str
parenta4ceb5974d1b7dcdd12cc81b7eb07893ea16c8ad (diff)
downloadminishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.tar.gz
minishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.tar.bz2
minishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.zip
Removing libft/minishell_test submodules, Removing subject/README/etc
Diffstat (limited to 'libft/src/str')
-rw-r--r--libft/src/str/ft_atoi.c25
-rw-r--r--libft/src/str/ft_atoi_strict.c38
-rw-r--r--libft/src/str/ft_fnmatch.c37
-rw-r--r--libft/src/str/ft_itoa.c40
-rw-r--r--libft/src/str/ft_itoa_cpy.c44
-rw-r--r--libft/src/str/ft_split.c63
-rw-r--r--libft/src/str/ft_splitf.c22
-rw-r--r--libft/src/str/ft_strcasecmp.c24
-rw-r--r--libft/src/str/ft_strcat.c19
-rw-r--r--libft/src/str/ft_strcat3.c26
-rw-r--r--libft/src/str/ft_strchr.c18
-rw-r--r--libft/src/str/ft_strclr.c20
-rw-r--r--libft/src/str/ft_strcmp.c23
-rw-r--r--libft/src/str/ft_strcount.c24
-rw-r--r--libft/src/str/ft_strcpy.c18
-rw-r--r--libft/src/str/ft_strcspn.c23
-rw-r--r--libft/src/str/ft_strdel.c18
-rw-r--r--libft/src/str/ft_strdup.c22
-rw-r--r--libft/src/str/ft_strequ.c20
-rw-r--r--libft/src/str/ft_striter.c21
-rw-r--r--libft/src/str/ft_striteri.c27
-rw-r--r--libft/src/str/ft_strjoin.c25
-rw-r--r--libft/src/str/ft_strjoin3.c36
-rw-r--r--libft/src/str/ft_strjoinf.c42
-rw-r--r--libft/src/str/ft_strlcat.c32
-rw-r--r--libft/src/str/ft_strlcpy.c28
-rw-r--r--libft/src/str/ft_strlen.c41
-rw-r--r--libft/src/str/ft_strmap.c34
-rw-r--r--libft/src/str/ft_strmapi.c34
-rw-r--r--libft/src/str/ft_strncasecmp.c26
-rw-r--r--libft/src/str/ft_strncat.c29
-rw-r--r--libft/src/str/ft_strncmp.c26
-rw-r--r--libft/src/str/ft_strncpy.c24
-rw-r--r--libft/src/str/ft_strndup.c23
-rw-r--r--libft/src/str/ft_strnequ.c20
-rw-r--r--libft/src/str/ft_strnew.c18
-rw-r--r--libft/src/str/ft_strnlen.c25
-rw-r--r--libft/src/str/ft_strnstr.c29
-rw-r--r--libft/src/str/ft_strpbrk.c24
-rw-r--r--libft/src/str/ft_strrchr.c24
-rw-r--r--libft/src/str/ft_strsep.c32
-rw-r--r--libft/src/str/ft_strsjoin.c50
-rw-r--r--libft/src/str/ft_strsjoinf.c29
-rw-r--r--libft/src/str/ft_strspn.c23
-rw-r--r--libft/src/str/ft_strstr.c29
-rw-r--r--libft/src/str/ft_strsub.c39
-rw-r--r--libft/src/str/ft_strsubf.c30
-rw-r--r--libft/src/str/ft_strtol.c89
-rw-r--r--libft/src/str/ft_strtolower.c26
-rw-r--r--libft/src/str/ft_strtoupper.c26
-rw-r--r--libft/src/str/ft_strtrim.c31
51 files changed, 1516 insertions, 0 deletions
diff --git a/libft/src/str/ft_atoi.c b/libft/src/str/ft_atoi.c
new file mode 100644
index 0000000..b8f979d
--- /dev/null
+++ b/libft/src/str/ft_atoi.c
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_atoi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/07 09:46:16 by cacharle #+# #+# */
+/* Updated: 2020/04/04 22:34:33 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+/*
+** \brief Extract first int in a string
+** (takes as much digits has possible)
+** \param str String to convert
+** \return Extracted int
+*/
+
+int ft_atoi(const char *str)
+{
+ return ((int)ft_strtol(str, (char**)NULL, 10));
+}
diff --git a/libft/src/str/ft_atoi_strict.c b/libft/src/str/ft_atoi_strict.c
new file mode 100644
index 0000000..8be4c4b
--- /dev/null
+++ b/libft/src/str/ft_atoi_strict.c
@@ -0,0 +1,38 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strict_atoi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/15 10:06:29 by cacharle #+# #+# */
+/* Updated: 2020/02/14 02:46:43 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_atoi_strict(const char *s)
+{
+ char *end;
+ long ret;
+
+ if (*s != '-' && !ft_isdigit(*s))
+ {
+ errno = EINVAL;
+ return (0);
+ }
+ errno = 0;
+ ret = ft_strtol(s, &end, 10);
+ if (errno == ERANGE || ret > INT_MAX || ret < INT_MIN)
+ {
+ errno = ERANGE;
+ return (0);
+ }
+ if (*end != '\0')
+ {
+ errno = EINVAL;
+ return (0);
+ }
+ return (ret);
+}
diff --git a/libft/src/str/ft_fnmatch.c b/libft/src/str/ft_fnmatch.c
new file mode 100644
index 0000000..5fc35d8
--- /dev/null
+++ b/libft/src/str/ft_fnmatch.c
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_fnmatch.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/02 23:24:16 by charles #+# #+# */
+/* Updated: 2020/04/03 00:28:46 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+/*
+** \brief Search a glob pattern in a string
+** \param pattern Glob pattern '*' are interpreted as zero or more character
+** \param string String to search in
+** \return True if pattern was found, false otherwise
+*/
+
+bool ft_fnmatch(const char *pattern, const char *string)
+{
+ if (*pattern == '\0')
+ return (*string == '\0');
+ if (*string == '\0')
+ return (*pattern == '\0' || (*pattern == '*' && pattern[1] == '\0'));
+ if (*pattern == '*')
+ {
+ if (ft_fnmatch(pattern + 1, string))
+ return (true);
+ return (ft_fnmatch(pattern, string + 1));
+ }
+ if (*pattern != *string)
+ return (false);
+ return (ft_fnmatch(pattern + 1, string + 1));
+}
diff --git a/libft/src/str/ft_itoa.c b/libft/src/str/ft_itoa.c
new file mode 100644
index 0000000..39b6e12
--- /dev/null
+++ b/libft/src/str/ft_itoa.c
@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_itoa.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/07 10:19:56 by cacharle #+# #+# */
+/* Updated: 2020/02/14 03:39:11 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+char *ft_itoa(int n)
+{
+ char *str;
+ int len;
+ unsigned int u_nbr;
+
+ len = n < 0 || n == 0 ? 1 : 0;
+ u_nbr = n < 0 ? -n : n;
+ while (u_nbr > 0)
+ {
+ u_nbr /= 10;
+ len++;
+ }
+ if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
+ return (NULL);
+ str[len] = '\0';
+ u_nbr = n < 0 ? -n : n;
+ if (n < 0)
+ str[0] = '-';
+ while (--len >= (n < 0 ? 1 : 0))
+ {
+ str[len] = (u_nbr % 10) | 0x30;
+ u_nbr /= 10;
+ }
+ return (str);
+}
diff --git a/libft/src/str/ft_itoa_cpy.c b/libft/src/str/ft_itoa_cpy.c
new file mode 100644
index 0000000..a66d016
--- /dev/null
+++ b/libft/src/str/ft_itoa_cpy.c
@@ -0,0 +1,44 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_itoa_cpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/07 10:19:56 by cacharle #+# #+# */
+/* Updated: 2020/09/14 15:59:28 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+/*
+** \brief itoa but cpy number in a buffer instead of allocating memory
+** \param dst Buffer where to put the string representation of the number
+** \param n Number to convert
+** \return Always dst
+*/
+
+char *ft_itoa_cpy(char *dst, int n)
+{
+ int len;
+ unsigned int u_nbr;
+
+ len = n < 0 || n == 0 ? 1 : 0;
+ u_nbr = n < 0 ? -n : n;
+ while (u_nbr > 0)
+ {
+ u_nbr /= 10;
+ len++;
+ }
+ dst[len] = '\0';
+ u_nbr = n < 0 ? -n : n;
+ if (n < 0)
+ dst[0] = '-';
+ while (--len >= (n < 0 ? 1 : 0))
+ {
+ dst[len] = (u_nbr % 10) | 0x30;
+ u_nbr /= 10;
+ }
+ return (dst);
+}
diff --git a/libft/src/str/ft_split.c b/libft/src/str/ft_split.c
new file mode 100644
index 0000000..b61b09f
--- /dev/null
+++ b/libft/src/str/ft_split.c
@@ -0,0 +1,63 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_split.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/17 08:29:02 by cacharle #+# #+# */
+/* Updated: 2020/06/09 17:14:58 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+static size_t count_segment(char const *s, char c)
+{
+ size_t counter;
+ int i;
+
+ counter = 0;
+ i = 0;
+ while (s[i])
+ {
+ if (s[i] == c)
+ {
+ i++;
+ continue ;
+ }
+ counter++;
+ while (s[i] && s[i] != c)
+ i++;
+ }
+ return (counter);
+}
+
+char **ft_split(char const *s, char c)
+{
+ char **strs;
+ size_t tab_counter;
+ size_t i;
+ size_t j;
+
+ if (s == NULL)
+ return (NULL);
+ tab_counter = count_segment(s, c);
+ if ((strs = (char**)malloc(sizeof(char*) * (tab_counter + 1))) == NULL)
+ return (NULL);
+ tab_counter = 0;
+ j = -1;
+ while (s[++j])
+ {
+ if (s[j] == c)
+ continue ;
+ i = 0;
+ while (s[j + i] && s[j + i] != c)
+ i++;
+ if ((strs[tab_counter++] = ft_strndup(&s[j], i)) == NULL)
+ return (ft_split_destroy(strs));
+ j += i - 1;
+ }
+ strs[tab_counter] = NULL;
+ return (strs);
+}
diff --git a/libft/src/str/ft_splitf.c b/libft/src/str/ft_splitf.c
new file mode 100644
index 0000000..2a1afab
--- /dev/null
+++ b/libft/src/str/ft_splitf.c
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_splitf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/06/09 17:45:52 by charles #+# #+# */
+/* Updated: 2020/06/09 17:47:17 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+char **ft_splitf(char *s, char delim)
+{
+ char **ret;
+
+ ret = ft_split(s, delim);
+ free(s);
+ return (ret);
+}
diff --git a/libft/src/str/ft_strcasecmp.c b/libft/src/str/ft_strcasecmp.c
new file mode 100644
index 0000000..6dd86eb
--- /dev/null
+++ b/libft/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:31:33 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+#include "libft_def.h"
+
+int ft_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/libft/src/str/ft_strcat.c b/libft/src/str/ft_strcat.c
new file mode 100644
index 0000000..d5bc7e0
--- /dev/null
+++ b/libft/src/str/ft_strcat.c
@@ -0,0 +1,19 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcat.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/07 10:09:41 by cacharle #+# #+# */
+/* Updated: 2019/11/21 01:03:38 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+char *ft_strcat(char *dest, const char *src)
+{
+ ft_memcpy(dest + ft_strlen(dest), src, ft_strlen(src) + 1);
+ return (dest);
+}
diff --git a/libft/src/str/ft_strcat3.c b/libft/src/str/ft_strcat3.c
new file mode 100644
index 0000000..1f7c5df
--- /dev/null
+++ b/libft/src/str/ft_strcat3.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcat3.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/05 12:53:05 by charles #+# #+# */
+/* Updated: 2020/04/05 12:55:49 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+/*
+** \brief Wrapper around ft_strcat to concatenate 3 strings
+** \param dest Destination of the concatenation
+** \param src1 First concatenation
+** \param src2 Second concatenation
+** \return Pointer to destination
+*/
+
+char *ft_strcat3(char *dest, const char *src1, const char *src2)
+{
+ return (ft_strcat(ft_strcat(dest, src1), src2));
+}
diff --git a/libft/src/str/ft_strchr.c b/libft/src/str/ft_strchr.c
new file mode 100644
index 0000000..50bfc0a
--- /dev/null
+++ b/libft/src/str/ft_strchr.c
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/07 10:14:47 by cacharle #+# #+# */
+/* Updated: 2019/11/21 01:04:52 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+char *ft_strchr(const char *s, int c)
+{
+ return (ft_memchr(s, c, ft_strlen(s) + 1));
+}
diff --git a/libft/src/str/ft_strclr.c b/libft/src/str/ft_strclr.c
new file mode 100644
index 0000000..7e412fe
--- /dev/null
+++ b/libft/src/str/ft_strclr.c
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strclr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/07 10:15:18 by cacharle #+# #+# */
+/* Updated: 2019/11/21 01:11:51 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+void ft_strclr(char *s)
+{
+ if (s == NULL)
+ return ;
+ ft_bzero(s, ft_strlen(s));
+}
diff --git a/libft/src/str/ft_strcmp.c b/libft/src/str/ft_strcmp.c
new file mode 100644
index 0000000..aced711
--- /dev/null
+++ b/libft/src/str/ft_strcmp.c
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/07 10:16:07 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:18:11 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_strcmp(const char *s1, const char *s2)
+{
+ while (*s1 && *s2 && *s1 == *s2)
+ {
+ s1++;
+ s2++;
+ }
+ return (*s1 - *s2);
+}
diff --git a/libft/src/str/ft_strcount.c b/libft/src/str/ft_strcount.c
new file mode 100644
index 0000000..87e756d
--- /dev/null
+++ b/libft/src/str/ft_strcount.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcount.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/15 09:17:48 by cacharle #+# #+# */
+/* Updated: 2019/11/15 09:19:36 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+int ft_strcount(char *str, char c)
+{
+ int counter;
+
+ if (c == '\0')
+ return (1);
+ counter = 0;
+ while (*str)
+ if (*str++ == c)
+ counter++;
+ return (counter);
+}
diff --git a/libft/src/str/ft_strcpy.c b/libft/src/str/ft_strcpy.c
new file mode 100644
index 0000000..ee6ff0d
--- /dev/null
+++ b/libft/src/str/ft_strcpy.c
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/07 10:38:36 by cacharle #+# #+# */
+/* Updated: 2020/01/17 11:36:19 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+char *ft_strcpy(char *dest, const char *src)
+{
+ return (ft_memcpy(dest, src, ft_strlen(src) + 1));
+}
diff --git a/libft/src/str/ft_strcspn.c b/libft/src/str/ft_strcspn.c
new file mode 100644
index 0000000..7cc06a5
--- /dev/null
+++ b/libft/src/str/ft_strcspn.c
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcspn.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 04:30:59 by cacharle #+# #+# */
+/* Updated: 2020/02/10 04:32:15 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+size_t ft_strcspn(const char *s, const char *charset)
+{
+ int i;
+
+ i = 0;
+ while (ft_strchr(charset, s[i]) == NULL)
+ i++;
+ return (i);
+}
diff --git a/libft/src/str/ft_strdel.c b/libft/src/str/ft_strdel.c
new file mode 100644
index 0000000..05cf064
--- /dev/null
+++ b/libft/src/str/ft_strdel.c
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strdel.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr>