From c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 11 Oct 2020 15:52:52 +0200 Subject: Removing libft/minishell_test submodules, Removing subject/README/etc --- libft/src/str/ft_atoi.c | 25 ++++++++++++ libft/src/str/ft_atoi_strict.c | 38 ++++++++++++++++++ libft/src/str/ft_fnmatch.c | 37 ++++++++++++++++++ libft/src/str/ft_itoa.c | 40 +++++++++++++++++++ libft/src/str/ft_itoa_cpy.c | 44 +++++++++++++++++++++ libft/src/str/ft_split.c | 63 ++++++++++++++++++++++++++++++ libft/src/str/ft_splitf.c | 22 +++++++++++ libft/src/str/ft_strcasecmp.c | 24 ++++++++++++ libft/src/str/ft_strcat.c | 19 +++++++++ libft/src/str/ft_strcat3.c | 26 ++++++++++++ libft/src/str/ft_strchr.c | 18 +++++++++ libft/src/str/ft_strclr.c | 20 ++++++++++ libft/src/str/ft_strcmp.c | 23 +++++++++++ libft/src/str/ft_strcount.c | 24 ++++++++++++ libft/src/str/ft_strcpy.c | 18 +++++++++ libft/src/str/ft_strcspn.c | 23 +++++++++++ libft/src/str/ft_strdel.c | 18 +++++++++ libft/src/str/ft_strdup.c | 22 +++++++++++ libft/src/str/ft_strequ.c | 20 ++++++++++ libft/src/str/ft_striter.c | 21 ++++++++++ libft/src/str/ft_striteri.c | 27 +++++++++++++ libft/src/str/ft_strjoin.c | 25 ++++++++++++ libft/src/str/ft_strjoin3.c | 36 +++++++++++++++++ libft/src/str/ft_strjoinf.c | 42 ++++++++++++++++++++ libft/src/str/ft_strlcat.c | 32 +++++++++++++++ libft/src/str/ft_strlcpy.c | 28 +++++++++++++ libft/src/str/ft_strlen.c | 41 +++++++++++++++++++ libft/src/str/ft_strmap.c | 34 ++++++++++++++++ libft/src/str/ft_strmapi.c | 34 ++++++++++++++++ libft/src/str/ft_strncasecmp.c | 26 ++++++++++++ libft/src/str/ft_strncat.c | 29 ++++++++++++++ libft/src/str/ft_strncmp.c | 26 ++++++++++++ libft/src/str/ft_strncpy.c | 24 ++++++++++++ libft/src/str/ft_strndup.c | 23 +++++++++++ libft/src/str/ft_strnequ.c | 20 ++++++++++ libft/src/str/ft_strnew.c | 18 +++++++++ libft/src/str/ft_strnlen.c | 25 ++++++++++++ libft/src/str/ft_strnstr.c | 29 ++++++++++++++ libft/src/str/ft_strpbrk.c | 24 ++++++++++++ libft/src/str/ft_strrchr.c | 24 ++++++++++++ libft/src/str/ft_strsep.c | 32 +++++++++++++++ libft/src/str/ft_strsjoin.c | 50 ++++++++++++++++++++++++ libft/src/str/ft_strsjoinf.c | 29 ++++++++++++++ libft/src/str/ft_strspn.c | 23 +++++++++++ libft/src/str/ft_strstr.c | 29 ++++++++++++++ libft/src/str/ft_strsub.c | 39 ++++++++++++++++++ libft/src/str/ft_strsubf.c | 30 ++++++++++++++ libft/src/str/ft_strtol.c | 89 ++++++++++++++++++++++++++++++++++++++++++ libft/src/str/ft_strtolower.c | 26 ++++++++++++ libft/src/str/ft_strtoupper.c | 26 ++++++++++++ libft/src/str/ft_strtrim.c | 31 +++++++++++++++ 51 files changed, 1516 insertions(+) create mode 100644 libft/src/str/ft_atoi.c create mode 100644 libft/src/str/ft_atoi_strict.c create mode 100644 libft/src/str/ft_fnmatch.c create mode 100644 libft/src/str/ft_itoa.c create mode 100644 libft/src/str/ft_itoa_cpy.c create mode 100644 libft/src/str/ft_split.c create mode 100644 libft/src/str/ft_splitf.c create mode 100644 libft/src/str/ft_strcasecmp.c create mode 100644 libft/src/str/ft_strcat.c create mode 100644 libft/src/str/ft_strcat3.c create mode 100644 libft/src/str/ft_strchr.c create mode 100644 libft/src/str/ft_strclr.c create mode 100644 libft/src/str/ft_strcmp.c create mode 100644 libft/src/str/ft_strcount.c create mode 100644 libft/src/str/ft_strcpy.c create mode 100644 libft/src/str/ft_strcspn.c create mode 100644 libft/src/str/ft_strdel.c create mode 100644 libft/src/str/ft_strdup.c create mode 100644 libft/src/str/ft_strequ.c create mode 100644 libft/src/str/ft_striter.c create mode 100644 libft/src/str/ft_striteri.c create mode 100644 libft/src/str/ft_strjoin.c create mode 100644 libft/src/str/ft_strjoin3.c create mode 100644 libft/src/str/ft_strjoinf.c create mode 100644 libft/src/str/ft_strlcat.c create mode 100644 libft/src/str/ft_strlcpy.c create mode 100644 libft/src/str/ft_strlen.c create mode 100644 libft/src/str/ft_strmap.c create mode 100644 libft/src/str/ft_strmapi.c create mode 100644 libft/src/str/ft_strncasecmp.c create mode 100644 libft/src/str/ft_strncat.c create mode 100644 libft/src/str/ft_strncmp.c create mode 100644 libft/src/str/ft_strncpy.c create mode 100644 libft/src/str/ft_strndup.c create mode 100644 libft/src/str/ft_strnequ.c create mode 100644 libft/src/str/ft_strnew.c create mode 100644 libft/src/str/ft_strnlen.c create mode 100644 libft/src/str/ft_strnstr.c create mode 100644 libft/src/str/ft_strpbrk.c create mode 100644 libft/src/str/ft_strrchr.c create mode 100644 libft/src/str/ft_strsep.c create mode 100644 libft/src/str/ft_strsjoin.c create mode 100644 libft/src/str/ft_strsjoinf.c create mode 100644 libft/src/str/ft_strspn.c create mode 100644 libft/src/str/ft_strstr.c create mode 100644 libft/src/str/ft_strsub.c create mode 100644 libft/src/str/ft_strsubf.c create mode 100644 libft/src/str/ft_strtol.c create mode 100644 libft/src/str/ft_strtolower.c create mode 100644 libft/src/str/ft_strtoupper.c create mode 100644 libft/src/str/ft_strtrim.c (limited to 'libft/src/str') 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:39:14 by cacharle #+# #+# */ +/* Updated: 2019/11/20 01:58:27 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_strdel(char **as) +{ + ft_memdel((void*)as); +} diff --git a/libft/src/str/ft_strdup.c b/libft/src/str/ft_strdup.c new file mode 100644 index 0000000..b248272 --- /dev/null +++ b/libft/src/str/ft_strdup.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:18:07 by cacharle #+# #+# */ +/* Updated: 2020/02/14 03:39:56 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *s) +{ + char *clone; + + if ((clone = (char*)malloc(sizeof(char) * (ft_strlen(s) + 1))) == NULL) + return (NULL); + return (ft_strcpy(clone, s)); +} diff --git a/libft/src/str/ft_strequ.c b/libft/src/str/ft_strequ.c new file mode 100644 index 0000000..75ccb81 --- /dev/null +++ b/libft/src/str/ft_strequ.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:18:34 by cacharle #+# #+# */ +/* Updated: 2019/11/20 02:00:22 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strequ(char const *s1, char const *s2) +{ + if (s1 == NULL || s2 == NULL) + return (0); + return (ft_strcmp(s1, s2) == 0); +} diff --git a/libft/src/str/ft_striter.c b/libft/src/str/ft_striter.c new file mode 100644 index 0000000..f410d24 --- /dev/null +++ b/libft/src/str/ft_striter.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:38:16 by cacharle #+# #+# */ +/* Updated: 2019/11/20 02:01:32 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striter(char *s, void (*f)(char *)) +{ + if (s == NULL || f == NULL) + return ; + while (*s) + (*f)(s++); +} diff --git a/libft/src/str/ft_striteri.c b/libft/src/str/ft_striteri.c new file mode 100644 index 0000000..05f15d4 --- /dev/null +++ b/libft/src/str/ft_striteri.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:33:09 by cacharle #+# #+# */ +/* Updated: 2019/11/20 02:01:41 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char *)) +{ + unsigned int i; + + if (s == NULL || f == NULL) + return ; + i = 0; + while (s[i]) + { + (*f)(i, &s[i]); + i++; + } +} diff --git a/libft/src/str/ft_strjoin.c b/libft/src/str/ft_strjoin.c new file mode 100644 index 0000000..b65eaa2 --- /dev/null +++ b/libft/src/str/ft_strjoin.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:35:26 by cacharle #+# #+# */ +/* Updated: 2020/02/14 03:40:39 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *joined; + + if (s1 == NULL || s2 == NULL) + return (NULL); + if ((joined = (char*)malloc(sizeof(char) + * (ft_strlen(s1) + ft_strlen(s2) + 1))) == NULL) + return (NULL); + return (ft_strcat(ft_strcpy(joined, s1), s2)); +} diff --git a/libft/src/str/ft_strjoin3.c b/libft/src/str/ft_strjoin3.c new file mode 100644 index 0000000..e5e5530 --- /dev/null +++ b/libft/src/str/ft_strjoin3.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin3.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/01 18:00:49 by charles #+# #+# */ +/* Updated: 2020/04/01 18:01:43 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* +** \brief Join 3 strings in a new malloc'd one +** \param s1 String 1 +** \param s2 String 2 +** \param s3 String 3 +** \return The joined string +*/ + +char *ft_strjoin3(char const *s1, char const *s2, char const *s3) +{ + char *joined; + + if (s1 == NULL || s2 == NULL || s3 == NULL) + return (NULL); + if ((joined = (char*)malloc(sizeof(char) + * (ft_strlen(s1) + ft_strlen(s2) + ft_strlen(s3) + 1))) == NULL) + return (NULL); + ft_strcpy(joined, s1); + ft_strcat(joined, s2); + ft_strcat(joined, s3); + return (joined); +} diff --git a/libft/src/str/ft_strjoinf.c b/libft/src/str/ft_strjoinf.c new file mode 100644 index 0000000..7c96e13 --- /dev/null +++ b/libft/src/str/ft_strjoinf.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoinf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 03:41:07 by cacharle #+# #+# */ +/* Updated: 2020/10/08 09:40:22 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +char *ft_strjoinf(char const *s1, char const *s2, t_ftstrjoinf_tag tag) +{ + char *joined; + + if (s1 == NULL || s2 == NULL) + return (NULL); + joined = ft_strjoin(s1, s2); + if (tag == FT_STRJOINF_FST) + free((void*)s1); + else if (tag == FT_STRJOINF_SND) + free((void*)s2); + else if (tag == FT_STRJOINF_ALL) + { + free((void*)s1); + free((void*)s2); + } + return (joined); +} + +char *ft_strjoinf_fst(char const *s1, char const *s2) +{ + return (ft_strjoinf(s1, s2, FT_STRJOINF_FST)); +} + +char *ft_strjoinf_snd(char const *s1, char const *s2) +{ + return (ft_strjoinf(s1, s2, FT_STRJOINF_SND)); +} diff --git a/libft/src/str/ft_strlcat.c b/libft/src/str/ft_strlcat.c new file mode 100644 index 0000000..ce7fa0b --- /dev/null +++ b/libft/src/str/ft_strlcat.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:31:37 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:31:08 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dst, const char *src, size_t size) +{ + size_t i; + size_t j; + size_t dst_len; + size_t src_len; + + dst_len = ft_strlen(dst); + src_len = ft_strlen(src); + if (size <= dst_len) + return (src_len + size); + i = 0; + j = dst_len; + while (src[i] && j < size - 1) + dst[j++] = src[i++]; + dst[j] = '\0'; + return (dst_len + src_len); +} diff --git a/libft/src/str/ft_strlcpy.c b/libft/src/str/ft_strlcpy.c new file mode 100644 index 0000000..6afb8f5 --- /dev/null +++ b/libft/src/str/ft_strlcpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 12:28:47 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:31:16 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dst, const char *src, size_t size) +{ + unsigned int i; + + if (dst == NULL || src == NULL) + return (0); + if (size == 0) + return (ft_strlen(src)); + i = -1; + while (++i < size - 1 && src[i] != '\0') + dst[i] = src[i]; + dst[i] = '\0'; + return (ft_strlen(src)); +} diff --git a/libft/src/str/ft_strlen.c b/libft/src/str/ft_strlen.c new file mode 100644 index 0000000..0d593e1 --- /dev/null +++ b/libft/src/str/ft_strlen.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:32:48 by cacharle #+# #+# */ +/* Updated: 2020/01/17 11:13:43 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *s) +{ + unsigned long int *ptr; + const char *cpy; + + ptr = (unsigned long int*)s; + while (TRUE) + { + cpy = (const char*)ptr++; + if (cpy[0] == '\0') + return (cpy - s); + if (cpy[1] == '\0') + return (cpy + 1 - s); + if (cpy[2] == '\0') + return (cpy + 2 - s); + if (cpy[3] == '\0') + return (cpy + 3 - s); + if (cpy[4] == '\0') + return (cpy + 4 - s); + if (cpy[5] == '\0') + return (cpy + 5 - s); + if (cpy[6] == '\0') + return (cpy + 6 - s); + if (cpy[7] == '\0') + return (cpy + 7 - s); + } +} diff --git a/libft/src/str/ft_strmap.c b/libft/src/str/ft_strmap.c new file mode 100644 index 0000000..61d16f1 --- /dev/null +++ b/libft/src/str/ft_strmap.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:29:52 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:02:11 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmap(char const *s, char (*f)(char)) +{ + size_t i; + size_t len; + char *mapped; + + if (s == NULL || f == NULL) + return (NULL); + len = ft_strlen(s); + if ((mapped = (char*)malloc(sizeof(char) * (len + 1))) == NULL) + return (NULL); + i = 0; + while (i < len) + { + mapped[i] = (*f)(s[i]); + i++; + } + mapped[i] = '\0'; + return (mapped); +} diff --git a/libft/src/str/ft_strmapi.c b/libft/src/str/ft_strmapi.c new file mode 100644 index 0000000..71d77e4 --- /dev/null +++ b/libft/src/str/ft_strmapi.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:29:32 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:02:15 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char *s, char (*f)(unsigned int, char)) +{ + size_t i; + size_t len; + char *mapped; + + if (s == NULL || f == NULL) + return (NULL); + len = ft_strlen(s); + if ((mapped = (char*)malloc(sizeof(char) * (len + 1))) == NULL) + return (NULL); + i = 0; + while (i < len) + { + mapped[i] = (*f)((unsigned int)i, s[i]); + i++; + } + mapped[i] = '\0'; + return (mapped); +} diff --git a/libft/src/str/ft_strncasecmp.c b/libft/src/str/ft_strncasecmp.c new file mode 100644 index 0000000..7153237 --- /dev/null +++ b/libft/src/str/ft_strncasecmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncasecmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 04:18:36 by cacharle #+# #+# */ +/* Updated: 2020/02/10 04:31:38 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_def.h" + +int ft_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/libft/src/str/ft_strncat.c b/libft/src/str/ft_strncat.c new file mode 100644 index 0000000..d68db0a --- /dev/null +++ b/libft/src/str/ft_strncat.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:28:37 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:33:22 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strncat(char *dest, const char *src, size_t n) +{ + size_t i; + size_t j; + + i = ft_strlen(dest); + j = 0; + while (j < n && src[j]) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = '\0'; + return (dest); +} diff --git a/libft/src/str/ft_strncmp.c b/libft/src/str/ft_strncmp.c new file mode 100644 index 0000000..d810e8c --- /dev/null +++ b/libft/src/str/ft_strncmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:27:34 by cacharle #+# #+# */ +/* Updated: 2020/02/10 04:17:50 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_def.h" + +int ft_strncmp(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] == s2[i] && s1[i]) + i++; + return ((t_ftuchar)s1[i] - (t_ftuchar)s2[i]); +} diff --git a/libft/src/str/ft_strncpy.c b/libft/src/str/ft_strncpy.c new file mode 100644 index 0000000..07a4927 --- /dev/null +++ b/libft/src/str/ft_strncpy.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:26:59 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:40:21 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strncpy(char *dest, const char *src, size_t n) +{ + size_t len; + + len = ft_strlen(src); + ft_memcpy(dest, src, n < len ? n : len); + if (len < n) + ft_bzero(dest + len, n - len); + return (dest); +} diff --git a/libft/src/str/ft_strndup.c b/libft/src/str/ft_strndup.c new file mode 100644 index 0000000..894ea4e --- /dev/null +++ b/libft/src/str/ft_strndup.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strndup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/25 03:28:52 by cacharle #+# #+# */ +/* Updated: 2020/02/14 03:43:55 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strndup(const char *s1, size_t n) +{ + char *clone; + + if ((clone = (char*)malloc(sizeof(char) * (n + 1))) == NULL) + return (NULL); + clone[n] = '\0'; + return (ft_strncpy(clone, s1, n)); +} diff --git a/libft/src/str/ft_strnequ.c b/libft/src/str/ft_strnequ.c new file mode 100644 index 0000000..e242ee7 --- /dev/null +++ b/libft/src/str/ft_strnequ.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:30:27 by cacharle #+# #+# */ +/* Updated: 2019/11/20 02:00:42 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strnequ(char const *s1, char const *s2, size_t n) +{ + if (s1 == NULL || s2 == NULL) + return (0); + return (ft_strncmp(s1, s2, n) == 0); +} diff --git a/libft/src/str/ft_strnew.c b/libft/src/str/ft_strnew.c new file mode 100644 index 0000000..1bca6d5 --- /dev/null +++ b/libft/src/str/ft_strnew.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:17:34 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:16:14 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnew(size_t size) +{ + return ((char*)ft_calloc(size + 1, sizeof(char))); +} diff --git a/libft/src/str/ft_strnlen.c b/libft/src/str/ft_strnlen.c new file mode 100644 index 0000000..5e1569c --- /dev/null +++ b/libft/src/str/ft_strnlen.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/libft/src/str/ft_strnstr.c b/libft/src/str/ft_strnstr.c new file mode 100644 index 0000000..4995637 --- /dev/null +++ b/libft/src/str/ft_strnstr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:25:13 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:58:42 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *haystack, const char *needle, size_t len) +{ + size_t needle_len; + + needle_len = ft_strlen(needle); + if (needle_len == 0) + return ((char*)haystack); + while (*haystack && len-- >= needle_len) + { + if (ft_strnequ(haystack, needle, needle_len)) + return ((char*)haystack); + haystack++; + } + return (NULL); +} diff --git a/libft/src/str/ft_strpbrk.c b/libft/src/str/ft_strpbrk.c new file mode 100644 index 0000000..753e4d9 --- /dev/null +++ b/libft/src/str/ft_strpbrk.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strpbrk.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/libft/src/str/ft_strrchr.c b/libft/src/str/ft_strrchr.c new file mode 100644 index 0000000..4cedb76 --- /dev/null +++ b/libft/src/str/ft_strrchr.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:26:24 by cacharle #+# #+# */ +/* Updated: 2019/11/21 18:46:27 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *s, int c) +{ + size_t i; + + i = ft_strlen(s) + 1; + while (s[--i] != (char)c) + if (i == 0) + return (NULL); + return ((char*)s + i); +} diff --git a/libft/src/str/ft_strsep.c b/libft/src/str/ft_strsep.c new file mode 100644 index 0000000..50197fb --- /dev/null +++ b/libft/src/str/ft_strsep.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsep.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 04:44:11 by cacharle #+# #+# */ +/* Updated: 2020/04/04 12:48:24 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +char *ft_strsep(char **stringp, const char *delim) +{ + char *tmp; + char *origin; + + if (*stringp == NULL) + return (NULL); + origin = *stringp; + tmp = ft_strpbrk(*stringp, delim); + if (tmp == NULL) + { + *stringp = NULL; + return (origin); + } + *tmp = '\0'; + *stringp = tmp + 1; + return (origin); +} diff --git a/libft/src/str/ft_strsjoin.c b/libft/src/str/ft_strsjoin.c new file mode 100644 index 0000000..0923bde --- /dev/null +++ b/libft/src/str/ft_strsjoin.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/04 14:30:08 by charles #+# #+# */ +/* Updated: 2020/04/04 23:34:30 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +/* +** \brief Join null-terminated array of strings +** \param strs Array of strings +** \param delim String iterspersed between strings +** \return Joined string or NULL on error +** \note Empty strings are ignored +*/ + +char *ft_strsjoin(char **strs, char *delim) +{ + int i; + size_t join_len; + size_t delim_len; + char *join; + + delim_len = ft_strlen(delim); + join_len = 0; + i = -1; + while (strs[++i] != NULL) + { + join_len += ft_strlen(strs[i]); + if (strs[i + 1] != NULL) + join_len += delim_len; + } + if ((join = (char*)malloc(sizeof(char) * (join_len + 1))) == NULL) + return (NULL); + join[0] = '\0'; + i = -1; + while (strs[++i] != NULL) + { + ft_strcat(join, strs[i]); + if (*strs[i] != '\0' && strs[i + 1] != NULL) + ft_strcat(join, delim); + } + return (join); +} diff --git a/libft/src/str/ft_strsjoinf.c b/libft/src/str/ft_strsjoinf.c new file mode 100644 index 0000000..36a2892 --- /dev/null +++ b/libft/src/str/ft_strsjoinf.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsjoinf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/04 14:27:33 by charles #+# #+# */ +/* Updated: 2020/04/04 23:24:24 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +/*