From fbbe237c14c20972ca22493411dde5b617a0dc7b Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 12 Jan 2017 18:08:26 +0100 Subject: [PATCH] ft_strreplace and stuff --- libft/includes/libft.h | 3 ++- libft/src/lst/ft_lst_delsub.c | 4 ++-- libft/src/str/ft_strappend.c | 2 +- libft/src/str/ft_strbetween.c | 2 +- libft/src/str/ft_strreplace.c | 24 ++++++++++++++++++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 libft/src/str/ft_strreplace.c diff --git a/libft/includes/libft.h b/libft/includes/libft.h index a58ff898..64dfaa0a 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/01/11 16:28:39 by jhalford ### ########.fr */ +/* Updated: 2017/01/12 13:55:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -129,6 +129,7 @@ char *ft_strcatf(char *s1, const char *s2); char *ft_strinsert(char *str, char c, int n); int ft_strappend(char **dst, char *src); char *ft_strbetween(char *start, char *end); +char *ft_strreplace(char **str, char *start, char *end, char *new); char *ft_itoa_base(int nbr, char *base, char *flags); char *ft_lltoa_base(long long nbr, char *base, char *flags); diff --git a/libft/src/lst/ft_lst_delsub.c b/libft/src/lst/ft_lst_delsub.c index 005e9dd2..b3912fc2 100644 --- a/libft/src/lst/ft_lst_delsub.c +++ b/libft/src/lst/ft_lst_delsub.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */ -/* Updated: 2016/11/08 13:36:17 by jhalford ### ########.fr */ +/* Updated: 2017/01/12 14:33:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,8 +28,8 @@ void ft_lst_delsub( { tmp = *indirect; (*indirect) = (*indirect)->next; - ft_lstdelone(&tmp, del); sub = sub->next; + ft_lstdelone(&tmp, del); } indirect = &(*indirect)->next; } diff --git a/libft/src/str/ft_strappend.c b/libft/src/str/ft_strappend.c index 2330a8c6..493f2ec0 100644 --- a/libft/src/str/ft_strappend.c +++ b/libft/src/str/ft_strappend.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 12:16:31 by jhalford #+# #+# */ -/* Updated: 2016/12/13 16:57:31 by jhalford ### ########.fr */ +/* Updated: 2017/01/12 14:07:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/str/ft_strbetween.c b/libft/src/str/ft_strbetween.c index c2ec5935..7492077e 100644 --- a/libft/src/str/ft_strbetween.c +++ b/libft/src/str/ft_strbetween.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:26:44 by jhalford #+# #+# */ -/* Updated: 2017/01/11 16:38:13 by jhalford ### ########.fr */ +/* Updated: 2017/01/12 14:54:17 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/str/ft_strreplace.c b/libft/src/str/ft_strreplace.c new file mode 100644 index 00000000..fad78191 --- /dev/null +++ b/libft/src/str/ft_strreplace.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strreplace.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/12 13:50:21 by jhalford #+# #+# */ +/* Updated: 2017/01/12 13:59:25 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strreplace(char **str, char *start, char *end, char *new) +{ + char *out; + + out = ft_strnew(ft_strlen(*str) - (end - start) + ft_strlen(new) + 1); + ft_strncpy(out, *str, start - *str); + ft_strcat(out, new); + ft_strcat(out, end + 1); + return (out); +}