From 948c0953527fe3bef28904b38a16a9e4342e7e98 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 3 Apr 2020 00:29:26 +0200 Subject: Added ft_fnmatch function --- src/str/ft_fnmatch.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/str/ft_fnmatch.c (limited to 'src/str') diff --git a/src/str/ft_fnmatch.c b/src/str/ft_fnmatch.c new file mode 100644 index 0000000..5fc35d8 --- /dev/null +++ b/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)); +} -- cgit From d2feec1f97e9f8f201e56ad33662bb663c328a0a Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 3 Apr 2020 07:19:25 +0200 Subject: Changing hash table del function to regular one with a first order internal function, removing a few typedef to instead use standard types --- src/str/ft_strcasecmp.c | 2 +- src/str/ft_strncasecmp.c | 2 +- src/str/ft_strncmp.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/str') diff --git a/src/str/ft_strcasecmp.c b/src/str/ft_strcasecmp.c index 044e6de..6dd86eb 100644 --- a/src/str/ft_strcasecmp.c +++ b/src/str/ft_strcasecmp.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "libft_str.h" -#include "libft_types.h" +#include "libft_def.h" int ft_strcasecmp(const char *s1, const char *s2) { diff --git a/src/str/ft_strncasecmp.c b/src/str/ft_strncasecmp.c index aafdc8c..7153237 100644 --- a/src/str/ft_strncasecmp.c +++ b/src/str/ft_strncasecmp.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "libft.h" -#include "libft_types.h" +#include "libft_def.h" int ft_strncasecmp(const char *s1, const char *s2, size_t n) { diff --git a/src/str/ft_strncmp.c b/src/str/ft_strncmp.c index caa052b..d810e8c 100644 --- a/src/str/ft_strncmp.c +++ b/src/str/ft_strncmp.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "libft.h" -#include "libft_types.h" +#include "libft_def.h" int ft_strncmp(const char *s1, const char *s2, size_t n) { -- cgit From 51b845a6a202b50966f50e166cfb11bcbdccbe33 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 4 Apr 2020 15:58:24 +0200 Subject: Added ft_strsjoin, ft_strsjoinf, ft_compar_str, ft_vecsort, ft_vecpush_safe --- src/str/ft_strsep.c | 15 ++++++++++----- src/str/ft_strsjoin.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/str/ft_strsjoinf.c | 22 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/str/ft_strsjoin.c create mode 100644 src/str/ft_strsjoinf.c (limited to 'src/str') diff --git a/src/str/ft_strsep.c b/src/str/ft_strsep.c index 2000706..50197fb 100644 --- a/src/str/ft_strsep.c +++ b/src/str/ft_strsep.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/10 04:44:11 by cacharle #+# #+# */ -/* Updated: 2020/02/10 04:51:15 by cacharle ### ########.fr */ +/* Updated: 2020/04/04 12:48:24 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,13 +15,18 @@ char *ft_strsep(char **stringp, const char *delim) { char *tmp; + char *origin; - if (stringp == NULL || *stringp == NULL || delim == NULL) + if (*stringp == NULL) return (NULL); + origin = *stringp; tmp = ft_strpbrk(*stringp, delim); if (tmp == NULL) - return (NULL); + { + *stringp = NULL; + return (origin); + } *tmp = '\0'; - *stringp = tmp; - return (tmp); + *stringp = tmp + 1; + return (origin); } diff --git a/src/str/ft_strsjoin.c b/src/str/ft_strsjoin.c new file mode 100644 index 0000000..507903b --- /dev/null +++ b/src/str/ft_strsjoin.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/04 14:30:08 by charles #+# #+# */ +/* Updated: 2020/04/04 14:45:58 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +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 + 1] != NULL) + ft_strcat(join, delim); + } + return (join); +} diff --git a/src/str/ft_strsjoinf.c b/src/str/ft_strsjoinf.c new file mode 100644 index 0000000..f5077c1 --- /dev/null +++ b/src/str/ft_strsjoinf.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsjoinf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/04 14:27:33 by charles #+# #+# */ +/* Updated: 2020/04/04 14:29:49 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +char *ft_strsjoinf(char **strs, char *delim) +{ + char *ret; + + ret = ft_strsjoin(strs, delim); + ft_split_destroy(strs); + return (ret); +} -- cgit From 65cf641e9533b190db870d0cc46f2f852239ebf6 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 4 Apr 2020 23:36:19 +0200 Subject: Added test for ft_strsjoin, ft_strsjoinf, ft_vecpush_safe, Added doc for algo functions, tested functions --- src/str/ft_atoi.c | 7 +++++-- src/str/ft_strsjoin.c | 12 ++++++++++-- src/str/ft_strsjoinf.c | 9 ++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src/str') diff --git a/src/str/ft_atoi.c b/src/str/ft_atoi.c index d6fa5bb..b8f979d 100644 --- a/src/str/ft_atoi.c +++ b/src/str/ft_atoi.c @@ -6,14 +6,17 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 09:46:16 by cacharle #+# #+# */ -/* Updated: 2020/01/15 10:56:06 by cacharle ### ########.fr */ +/* Updated: 2020/04/04 22:34:33 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" /* -** Convert a string to an int +** \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) diff --git a/src/str/ft_strsjoin.c b/src/str/ft_strsjoin.c index 507903b..0923bde 100644 --- a/src/str/ft_strsjoin.c +++ b/src/str/ft_strsjoin.c @@ -6,12 +6,20 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/04 14:30:08 by charles #+# #+# */ -/* Updated: 2020/04/04 14:45:58 by charles ### ########.fr */ +/* 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; @@ -35,7 +43,7 @@ char *ft_strsjoin(char **strs, char *delim) while (strs[++i] != NULL) { ft_strcat(join, strs[i]); - if (strs[i + 1] != NULL) + if (*strs[i] != '\0' && strs[i + 1] != NULL) ft_strcat(join, delim); } return (join); diff --git a/src/str/ft_strsjoinf.c b/src/str/ft_strsjoinf.c index f5077c1..36a2892 100644 --- a/src/str/ft_strsjoinf.c +++ b/src/str/ft_strsjoinf.c @@ -6,12 +6,19 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/04 14:27:33 by charles #+# #+# */ -/* Updated: 2020/04/04 14:29:49 by charles ### ########.fr */ +/* Updated: 2020/04/04 23:24:24 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft_str.h" +/* +** \brief Join null-terminated array of strings and free the array +** \param strs Array of strings +** \param delim String which will be put between each string +** \return Joined string or NULL on error +*/ + char *ft_strsjoinf(char **strs, char *delim) { char *ret; -- cgit From 3a2d19df9e509d0b015c786eb02f8315ff0ad91c Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 5 Apr 2020 14:05:43 +0200 Subject: Renamed ft_substr to ft_strsub, Added ft_strsubf, ft_strcat3 --- src/str/ft_strcat3.c | 26 ++++++++++++++++++++++++++ src/str/ft_strsub.c | 39 +++++++++++++++++++++++++++++++++++++++ src/str/ft_strsubf.c | 30 ++++++++++++++++++++++++++++++ src/str/ft_strtrim.c | 4 ++-- src/str/ft_substr.c | 26 -------------------------- 5 files changed, 97 insertions(+), 28 deletions(-) create mode 100644 src/str/ft_strcat3.c create mode 100644 src/str/ft_strsub.c create mode 100644 src/str/ft_strsubf.c delete mode 100644 src/str/ft_substr.c (limited to 'src/str') diff --git a/src/str/ft_strcat3.c b/src/str/ft_strcat3.c new file mode 100644 index 0000000..1f7c5df --- /dev/null +++ b/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/src/str/ft_strsub.c b/src/str/ft_strsub.c new file mode 100644 index 0000000..77bffb2 --- /dev/null +++ b/src/str/ft_strsub.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsub.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/17 08:28:49 by cacharle #+# #+# */ +/* Updated: 2020/04/05 13:47:55 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +/* +** \brief Extract a substring from a string +** \param s String to extract from +** \param start Starting index of the substring +** \param len Substring length +** \return The created substring or NULL on error +*/ + +char *ft_strsub(char const *s, size_t start, size_t len) +{ + char *sub; + size_t s_len; + + if (s == NULL) + return (NULL); + s_len = ft_strlen(s); + if (start > s_len) + return (NULL); + if (start + len > s_len) + len = s_len - start; + if ((sub = (char*)malloc(sizeof(char) * (len + 1))) == NULL) + return (NULL); + sub[len] = '\0'; + return (ft_strncpy(sub, s + start, len)); +} diff --git a/src/str/ft_strsubf.c b/src/str/ft_strsubf.c new file mode 100644 index 0000000..dc49ba5 --- /dev/null +++ b/src/str/ft_strsubf.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsubf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/05 13:48:13 by charles #+# #+# */ +/* Updated: 2020/04/05 13:51:47 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +/* +** \brief Wrapper around ft_substr which free the original string +** \param s String to extract from (will be free) +** \param start Starting index of the substring +** \param len Substring length +** \return The created substring or NULL on error +*/ + +char *ft_strsubf(char const *s, size_t start, size_t len) +{ + char *ret; + + ret = ft_strsub(s, start, len); + free((void*)s); + return (ret); +} diff --git a/src/str/ft_strtrim.c b/src/str/ft_strtrim.c index aa48826..fa9b192 100644 --- a/src/str/ft_strtrim.c +++ b/src/str/ft_strtrim.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 10:24:16 by cacharle #+# #+# */ -/* Updated: 2019/11/20 03:52:58 by cacharle ### ########.fr */ +/* Updated: 2020/04/05 13:50:43 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,5 +27,5 @@ char *ft_strtrim(char const *s1, char const *set) while (s1[start + len - 1] && ft_strchr(set, s1[start + len - 1]) != NULL) len--; - return (ft_substr(s1, start, len)); + return (ft_strsub(s1, start, len)); } diff --git a/src/str/ft_substr.c b/src/str/ft_substr.c deleted file mode 100644 index ad9c706..0000000 --- a/src/str/ft_substr.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_substr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/17 08:28:49 by cacharle #+# #+# */ -/* Updated: 2020/02/14 03:44:42 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_substr(char const *s, unsigned int start, size_t len) -{ - char *sub; - - if (s == NULL) - return (NULL); - if ((sub = (char*)malloc(sizeof(char) * (len + 1))) == NULL) - return (NULL); - if (start > ft_strlen(s)) - return (sub); - return (ft_strncpy(sub, s + start, len)); -} -- cgit