aboutsummaryrefslogtreecommitdiff
path: root/src/dstr/ft_dstrerase.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-05 01:11:50 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-05 01:11:50 +0200
commit944a236443bacf531085b346d06907b24e3739b1 (patch)
treee49773563c77844944be5b7a75437b9f404d595a /src/dstr/ft_dstrerase.c
parent65cf641e9533b190db870d0cc46f2f852239ebf6 (diff)
downloadlibft-944a236443bacf531085b346d06907b24e3739b1.tar.gz
libft-944a236443bacf531085b346d06907b24e3739b1.tar.bz2
libft-944a236443bacf531085b346d06907b24e3739b1.zip
Added ft_dstrerase, ft_dstrsubstitute
Diffstat (limited to 'src/dstr/ft_dstrerase.c')
-rw-r--r--src/dstr/ft_dstrerase.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/dstr/ft_dstrerase.c b/src/dstr/ft_dstrerase.c
new file mode 100644
index 0000000..3d4732b
--- /dev/null
+++ b/src/dstr/ft_dstrerase.c
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_dstrerase.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/05 00:39:12 by charles #+# #+# */
+/* Updated: 2020/04/05 01:11:07 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_dstr.h"
+
+/*
+** \brief Erase part of a dynamic string
+** \param dstr Dynamic string to erase from
+** \param start Erase starting index
+** \param len Number of character to erase
+*/
+
+void ft_dstrerase(t_ftdstr *dstr, size_t start, size_t len)
+{
+ if (start > dstr->length)
+ return ;
+ if (start + len > dstr->length)
+ len = dstr->length - start;
+ ft_memmove(
+ dstr->str + start,
+ dstr->str + start + len,
+ dstr->length - start - len
+ );
+ dstr->length -= len;
+ dstr->str[dstr->length] = '\0';
+}