aboutsummaryrefslogtreecommitdiff
path: root/src/dstr/ft_dstrerase.c
diff options
context:
space:
mode:
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';
+}