From 91730ee04c99c6a877cfbc0417cb1fbfe351a99f Mon Sep 17 00:00:00 2001 From: Timo Schmidt Date: Fri, 2 Jun 2023 21:29:42 +0200 Subject: [PATCH] SPLIT --- Makefile | 10 ++++--- a.out | Bin 15912 -> 0 bytes ft_atoi.c | 4 +-- ft_char_in_charset.c | 19 ++++++++++++ ft_memcmp.c | 4 +-- ft_memcpy.c | 6 ++-- ft_memmove.c | 6 ++-- ft_split.c | 70 +++++++++++++++++++++++++++++++++++++++++++ ft_strchr.c | 4 +-- ft_strdup.c | 8 ++--- ft_strjoin.c | 10 +++---- ft_strlcat.c | 29 ++++++++---------- ft_strlcpy.c | 12 ++++---- ft_strlen.c | 4 +-- ft_strncmp.c | 4 +-- ft_strnstr.c | 9 ++---- ft_strrchr.c | 4 +-- ft_strtrim.c | 50 +++++++++++++++++++++++++++++++ ft_substr.c | 6 ++-- libft.h | 33 ++++++++++---------- 20 files changed, 213 insertions(+), 79 deletions(-) delete mode 100755 a.out create mode 100644 ft_char_in_charset.c diff --git a/Makefile b/Makefile index b55e0c2..5cf2fc4 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,6 @@ _SRC += ft_isalpha.c _SRC += ft_isascii.c _SRC += ft_isdigit.c _SRC += ft_isprint.c -_SRC += ft_isspace.c _SRC += ft_memchr.c _SRC += ft_memcmp.c _SRC += ft_memcpy.c @@ -40,10 +39,10 @@ _SRC += ft_toupper.c # _SRC += ft_putstr_fd.c # _SRC += ft_itoa.c -# _SRC += ft_strtrim.c +_SRC += ft_strtrim.c _SRC += ft_substr.c -# _SRC += ft_strjoin.c -# _SRC += ft_split.c +_SRC += ft_strjoin.c +_SRC += ft_split.c # _SRC += ft_striteri.c # _SRC += ft_strmapi.c @@ -57,6 +56,9 @@ _SRC += ft_substr.c # _SRC += ft_lstnew.c # _SRC += ft_lstsize.c +_SRC += ft_char_in_charset.c +_SRC += ft_isspace.c + unexport _DEPS _DEPS += libft.h diff --git a/a.out b/a.out deleted file mode 100755 index 5596ab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:18 by tosuman #+# #+# */ -/* Updated: 2023/05/22 17:28:18 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 19:58:10 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isspace(int c); int ft_isdigit(int c); -int ft_atoi(const char *nptr) +int ft_atoi(char const *nptr) { int res; int sign; diff --git a/ft_char_in_charset.c b/ft_char_in_charset.c new file mode 100644 index 0000000..10e2cf5 --- /dev/null +++ b/ft_char_in_charset.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_char_in_charset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tischmid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/02 19:43:41 by tischmid #+# #+# */ +/* Updated: 2023/06/02 20:38:04 by tischmid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_char_in_charset(char c, char const *charset) +{ + while (*charset) + if (*charset++ == c) + return (1); + return (0); +} diff --git a/ft_memcmp.c b/ft_memcmp.c index 9c5bd86..3afe2bc 100644 --- a/ft_memcmp.c +++ b/ft_memcmp.c @@ -6,13 +6,13 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/22 16:44:15 by tosuman #+# #+# */ -/* Updated: 2023/05/22 16:44:15 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 20:03:03 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include -int ft_memcmp(const void *s1, const void *s2, size_t n) +int ft_memcmp(void const *s1, void const *s2, size_t n) { unsigned char *us1; unsigned char *us2; diff --git a/ft_memcpy.c b/ft_memcpy.c index b1e1f66..f26e9b5 100644 --- a/ft_memcpy.c +++ b/ft_memcpy.c @@ -6,16 +6,16 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/11 13:28:20 by tosuman #+# #+# */ -/* Updated: 2023/05/11 13:28:21 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 20:01:50 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include -void *ft_memcpy(void *dest, const void *src, size_t n) +void *ft_memcpy(void *dest, void const *src, size_t n) { char *d; - const char *s; + char const *s; if (!src && !dest) return (0); diff --git a/ft_memmove.c b/ft_memmove.c index 372c400..682e2d9 100644 --- a/ft_memmove.c +++ b/ft_memmove.c @@ -6,17 +6,17 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/11 16:19:10 by tosuman #+# #+# */ -/* Updated: 2023/05/11 16:19:11 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 20:02:37 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include #include -void *ft_memmove(void *dest, const void *src, size_t n) +void *ft_memmove(void *dest, void const *src, size_t n) { char *d; - const char *s; + char const *s; if (!src && !dest) return (0); diff --git a/ft_split.c b/ft_split.c index e69de29..a8b3c33 100644 --- a/ft_split.c +++ b/ft_split.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tischmid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/02 20:37:07 by tischmid #+# #+# */ +/* Updated: 2023/06/02 21:28:59 by tischmid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +static size_t split_arr_len(char const *s, char c) +{ + size_t len; + + len = 0; + while (*s) + { + while (*s == c) + ++s; + ++len; + while (*s != c && *s) + ++s; + } + return (len); +} + +static int save_strlcpy(char **arr, size_t len, char const *src, size_t size) +{ + if (!arr[len - 1]) + { + while (len--) + free(arr[len]); + free(arr); + return (0); + } + ft_strlcpy(arr[len - 1], src, size); + return (1); +} + +char **ft_split(char const *s, char c) +{ + size_t arr_len; + size_t idx; + char **arr; + char const *start; + + arr_len = split_arr_len(s, c); + arr = malloc(sizeof(char *) * (arr_len + 1)); + if (!arr) + return (0); + idx = 0; + while (*s) + { + while (*s == c) + ++s; + start = s; + while (*s != c && *s) + ++s; + arr[idx] = malloc(sizeof(char) * (s - start + 1)); + if (!save_strlcpy(arr, ++idx, start, s - start + 1)) + return (0); + } + arr[idx] = (void *) 0; + return (arr); +} diff --git a/ft_strchr.c b/ft_strchr.c index 13aec53..a0270fb 100644 --- a/ft_strchr.c +++ b/ft_strchr.c @@ -6,11 +6,11 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/22 16:20:31 by tosuman #+# #+# */ -/* Updated: 2023/05/22 16:20:33 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 19:58:22 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ -char *ft_strchr(const char *s, int c) +char *ft_strchr(char const *s, int c) { while (*s) if (*s++ == (unsigned char) c) diff --git a/ft_strdup.c b/ft_strdup.c index 67f05db..29d3751 100644 --- a/ft_strdup.c +++ b/ft_strdup.c @@ -6,16 +6,14 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/22 19:12:24 by tosuman #+# #+# */ -/* Updated: 2023/05/22 19:15:06 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 20:01:24 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ +#include "libft.h" #include -size_t ft_strlen(const char *s); -size_t ft_strlcpy(char *dst, const char *src, size_t size); - -char *ft_strdup(const char *s) +char *ft_strdup(char const *s) { char *s2; size_t len; diff --git a/ft_strjoin.c b/ft_strjoin.c index 973af94..4170a7f 100644 --- a/ft_strjoin.c +++ b/ft_strjoin.c @@ -6,22 +6,22 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/24 13:43:29 by tosuman #+# #+# */ -/* Updated: 2023/05/24 13:43:30 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 19:39:01 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -char *ft_strjoin(char const *s1, char const s2) +char *ft_strjoin(char const *s1, char const *s2) { size_t total_len; char *joined_str; total_len = ft_strlen(s1) + ft_strlen(s2); - joined_str = ft_calloc(sizeof(char) * (total_len + 1)); + joined_str = ft_calloc(total_len + 1, sizeof(char)); if (!joined_str) return (0); - ft_strlcpy(joined_str, s1, total_len); - ft_strlcat(joined_str, s2, total_len); + ft_strlcat(joined_str, s1, total_len + 1); + ft_strlcat(joined_str, s2, total_len + 1); return (joined_str); } diff --git a/ft_strlcat.c b/ft_strlcat.c index 5be81cc..0746d67 100644 --- a/ft_strlcat.c +++ b/ft_strlcat.c @@ -6,42 +6,39 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/11 16:55:00 by tosuman #+# #+# */ -/* Updated: 2023/05/11 16:55:01 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 20:02:14 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include -size_t ft_strlcat(char *dst, const char *src, size_t size) +size_t ft_strlcat(char *dst, char const *src, size_t size) { size_t idx; + size_t sidx; size_t slen; size_t dlen; + slen = 0; + while (src[slen]) + ++slen; idx = 0; while (dst[idx]) ++idx; dlen = idx; if (dlen > size) - return (size); - slen = 0; - while (src[slen]) - dst[idx++] = src[slen++]; + return (slen + size); + sidx = 0; + size -= dlen; + while (size-- > 1 && src[sidx]) + dst[idx++] = src[sidx++]; + dst[idx] = 0; return (dlen + slen); } -// #include -// #include -// int main() -// { -// printf("%d", ft_strlcat()); -// printf("%d", ft_strlcat()); -// return (0); -// } - /* Alternative implementation -size_t ft_strlcat(char *dst, const char *src, size_t size) +size_t ft_strlcat(char *dst, char const *src, size_t size) { size_t dst_len; size_t src_len; diff --git a/ft_strlcpy.c b/ft_strlcpy.c index 693e972..89390f0 100644 --- a/ft_strlcpy.c +++ b/ft_strlcpy.c @@ -6,24 +6,24 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/11 16:55:00 by tosuman #+# #+# */ -/* Updated: 2023/05/11 16:55:01 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 19:58:55 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include -size_t ft_strlcpy(char *dst, const char *src, size_t size) +size_t ft_strlcpy(char *dst, char const *src, size_t size) { char *d; size_t len; d = dst; len = 0; - while (++len < size && *src) - *d++ = *src++; + while (len + 1 < size && src[len]) + *d++ = src[len++]; if (size) *d = 0; - while (*src && src++) + while (src[len]) len++; - return (len - 1); + return (len); } diff --git a/ft_strlen.c b/ft_strlen.c index 40f6019..c46a154 100644 --- a/ft_strlen.c +++ b/ft_strlen.c @@ -6,13 +6,13 @@ /* By: tischmid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/03 23:07:08 by tischmid #+# #+# */ -/* Updated: 2023/05/03 23:16:02 by tischmid ### ########.fr */ +/* Updated: 2023/06/02 20:02:05 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include -size_t ft_strlen(const char *s) +size_t ft_strlen(char const *s) { size_t length; diff --git a/ft_strncmp.c b/ft_strncmp.c index ecdcfea..353691f 100644 --- a/ft_strncmp.c +++ b/ft_strncmp.c @@ -6,14 +6,14 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/22 16:29:43 by tosuman #+# #+# */ -/* Updated: 2023/05/22 16:29:44 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 19:59:48 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include #include -int ft_strncmp(const char *s1, const char *s2, size_t n) +int ft_strncmp(char const *s1, char const *s2, size_t n) { unsigned char *us1; unsigned char *us2; diff --git a/ft_strnstr.c b/ft_strnstr.c index 4d3b540..c9beb00 100644 --- a/ft_strnstr.c +++ b/ft_strnstr.c @@ -6,16 +6,13 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/22 17:05:27 by tosuman #+# #+# */ -/* Updated: 2023/05/22 17:05:28 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 20:00:04 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ -#include +#include "libft.h" -size_t ft_strlen(const char *s); -int ft_memcmp(const void *s1, const void *s2, size_t n); - -char *ft_strnstr(const char *big, const char *little, size_t len) +char *ft_strnstr(char const *big, char const *little, size_t len) { size_t l_len; size_t b_len; diff --git a/ft_strrchr.c b/ft_strrchr.c index 836b795..c3c98c6 100644 --- a/ft_strrchr.c +++ b/ft_strrchr.c @@ -6,11 +6,11 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/22 16:24:42 by tosuman #+# #+# */ -/* Updated: 2023/05/22 16:24:42 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 20:00:15 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ -char *ft_strrchr(const char *s, int c) +char *ft_strrchr(char const *s, int c) { char *last; diff --git a/ft_strtrim.c b/ft_strtrim.c index e69de29..c2967fd 100644 --- a/ft_strtrim.c +++ b/ft_strtrim.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tischmid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/02 19:38:21 by tischmid #+# #+# */ +/* Updated: 2023/06/02 20:38:50 by tischmid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +static size_t len_after_trim(char const *s1, char const *set) +{ + size_t idx; + size_t start; + size_t end; + + idx = 0; + while (ft_char_in_charset(s1[idx], set)) + ++idx; + if (!s1[idx]) + return (0); + start = idx; + while (s1[idx]) + ++idx; + --idx; + while (ft_char_in_charset(s1[idx], set)) + --idx; + end = idx; + return (end - start + 1); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t trimmed_len; + char *trimmed_str; + + trimmed_len = len_after_trim(s1, set); + trimmed_str = malloc(sizeof(char) * (trimmed_len + 1)); + if (!trimmed_str) + return (0); + while (ft_char_in_charset(*s1, set)) + ++s1; + ft_strlcpy(trimmed_str, s1, trimmed_len + 1); + return (trimmed_str); +} diff --git a/ft_substr.c b/ft_substr.c index 52339e5..b249a65 100644 --- a/ft_substr.c +++ b/ft_substr.c @@ -6,15 +6,13 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/24 13:23:00 by tosuman #+# #+# */ -/* Updated: 2023/05/24 13:23:01 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 20:01:07 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ +#include "libft.h" #include -void *ft_calloc(size_t nmemb, size_t size); -size_t ft_strlcpy(char *dst, const char *src, size_t size); - char *ft_substr(char const *s, unsigned int start, size_t len) { unsigned int idx; diff --git a/libft.h b/libft.h index 41676aa..8f462d7 100644 --- a/libft.h +++ b/libft.h @@ -6,16 +6,15 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/11 11:31:44 by tosuman #+# #+# */ -/* Updated: 2023/05/11 11:31:46 by tosuman ### ########.fr */ +/* Updated: 2023/06/02 21:25:33 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LIBFT_H # define LIBFT_H - # include -int ft_atoi(const char *nptr); +int ft_atoi(char const *nptr); void ft_bzero(void *s, size_t n); void *ft_calloc(size_t nmemb, size_t size); int ft_isalnum(int c); @@ -24,22 +23,26 @@ int ft_isascii(int c); int ft_isdigit(int c); int ft_isprint(int c); int ft_isspace(int c); -void *ft_memchr(const void *s, int c, size_t n); -int ft_memcmp(const void *s1, const void *s2, size_t n); -void *ft_memcpy(void *dest, const void *src, size_t n); -void *ft_memmove(void *dest, const void *src, size_t n); +void *ft_memchr(void const *s, int c, size_t n); +int ft_memcmp(void const *s1, void const *s2, size_t n); +void *ft_memcpy(void *dest, void const *src, size_t n); +void *ft_memmove(void *dest, void const *src, size_t n); void *ft_memset(void *s, int c, size_t n); -char *ft_strchr(const char *s, int c); -char *ft_strdup(const char *s); -size_t ft_strlcat(char *dst, const char *src, size_t size); -size_t ft_strlcpy(char *dst, const char *src, size_t size); -size_t ft_strlen(const char *s); -int ft_strncmp(const char *s1, const char *s2, size_t n); -char *ft_strnstr(const char *big, const char *little, size_t len); -char *ft_strrchr(const char *s, int c); +char *ft_strchr(char const *s, int c); +char *ft_strdup(char const *s); +size_t ft_strlcat(char *dst, char const *src, size_t size); +size_t ft_strlcpy(char *dst, char const *src, size_t size); +size_t ft_strlen(char const *s); +int ft_strncmp(char const *s1, char const *s2, size_t n); +char *ft_strnstr(char const *big, char const *little, size_t len); +char *ft_strrchr(char const *s, int c); int ft_tolower(int c); int ft_toupper(int c); char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(char const *s1, char const *set); +int ft_char_in_charset(char c, char const *charset); +char **ft_split(char const *s, char c); typedef struct s_list {