diff options
Diffstat (limited to 'src/str')
| -rw-r--r-- | src/str/ft_strnlen.c | 25 | ||||
| -rw-r--r-- | src/str/ft_strpbrk.c | 24 | ||||
| -rw-r--r-- | src/str/ft_strsep.c | 27 | ||||
| -rw-r--r-- | src/str/ft_strtoupper.c | 2 |
4 files changed, 77 insertions, 1 deletions
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 */ /* */ /* ************************************************************************** */ |
