diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-04 21:28:21 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-04 21:28:21 +0200 |
| commit | 42316d8393d32bd88fb8e0cba6825185f78dacd0 (patch) | |
| tree | e9adbd7e5701f70ecba520bbee41d4b21852a1cb /src/dstr/ft_dstrinsert.c | |
| parent | 51b845a6a202b50966f50e166cfb11bcbdccbe33 (diff) | |
| download | libft-42316d8393d32bd88fb8e0cba6825185f78dacd0.tar.gz libft-42316d8393d32bd88fb8e0cba6825185f78dacd0.tar.bz2 libft-42316d8393d32bd88fb8e0cba6825185f78dacd0.zip | |
Added test and doc for dynamic string
Diffstat (limited to 'src/dstr/ft_dstrinsert.c')
| -rw-r--r-- | src/dstr/ft_dstrinsert.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/dstr/ft_dstrinsert.c b/src/dstr/ft_dstrinsert.c index 6a1486c..931f5d8 100644 --- a/src/dstr/ft_dstrinsert.c +++ b/src/dstr/ft_dstrinsert.c @@ -6,22 +6,29 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/03 14:00:44 by charles #+# #+# */ -/* Updated: 2020/04/03 15:09:52 by charles ### ########.fr */ +/* Updated: 2020/04/04 21:21:19 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft_dstr.h" +/* +** \brief Insert string in dynamic string +** \param dstr Dynamic string where the string will be inserted +** \param inserted Static string to insert +** \param i Index where it should be inserted +** \return Passed dynamic string or NULL on error +*/ + t_ftdstr *ft_dstrinsert(t_ftdstr *dstr, char *inserted, size_t i) { size_t inserted_len; - if (i > dstr->capacity) + if (i > dstr->length) return (NULL); inserted_len = ft_strlen(inserted); - if (dstr->capacity - dstr->length - 1 < inserted_len) - if (ft_dstrgrow(dstr, dstr->capacity + inserted_len + 1) == NULL) - return (NULL); + if (ft_dstrgrow(dstr, dstr->capacity + inserted_len) == NULL) + return (NULL); ft_memmove(dstr->str + i + inserted_len, dstr->str + i, dstr->length - i + 1); |
