aboutsummaryrefslogtreecommitdiff
path: root/src/str
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-11 16:14:38 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-11 16:14:38 +0200
commitb9f000a80cbba38b8f21c9737a42f07573ec7b91 (patch)
tree7068e7188dab0a710ae79d71800b329ab655e3eb /src/str
parenta4b9cda7d6733f2b077f8586e3b3e69351e7dfba (diff)
downloadlibft-b9f000a80cbba38b8f21c9737a42f07573ec7b91.tar.gz
libft-b9f000a80cbba38b8f21c9737a42f07573ec7b91.tar.bz2
libft-b9f000a80cbba38b8f21c9737a42f07573ec7b91.zip
Moved util/ft_split* in str, Added ft_memjoin and ft_memjoinf1, Modified ft_getfile so that it can read non-ascii file
Diffstat (limited to 'src/str')
-rw-r--r--src/str/ft_split.c4
-rw-r--r--src/str/ft_strjoinf.c4
-rw-r--r--src/str/ft_strnew.c19
-rw-r--r--src/str/ft_strsdestroy.c30
-rw-r--r--src/str/ft_strsjoinf.c4
-rw-r--r--src/str/ft_strslen.c23
6 files changed, 74 insertions, 10 deletions
diff --git a/src/str/ft_split.c b/src/str/ft_split.c
index 0cb08e4..5d164d4 100644
--- a/src/str/ft_split.c
+++ b/src/str/ft_split.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/17 08:29:02 by cacharle #+# #+# */
-/* Updated: 2020/05/08 13:39:31 by charles ### ########.fr */
+/* Updated: 2020/05/11 15:54:10 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -55,7 +55,7 @@ char **ft_split(char const *s, char c)
while (s[j + i] && s[j + i] != c)
i++;
if ((strs[tab_counter++] = ft_strndup(&s[j], i)) == NULL)
- return (ft_split_destroy(strs));
+ return (ft_strsdestroy(strs));
j += i - 1;
}
strs[tab_counter] = NULL;
diff --git a/src/str/ft_strjoinf.c b/src/str/ft_strjoinf.c
index 228a963..adf9825 100644
--- a/src/str/ft_strjoinf.c
+++ b/src/str/ft_strjoinf.c
@@ -6,12 +6,10 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 03:41:07 by cacharle #+# #+# */
-/* Updated: 2020/02/14 03:41:25 by cacharle ### ########.fr */
+/* Updated: 2020/05/11 15:20:31 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdlib.h>
-#include "libft.h"
#include "libft_str.h"
char *ft_strjoinf(char const *s1, char const *s2, t_ftstrjoinf_tag tag)
diff --git a/src/str/ft_strnew.c b/src/str/ft_strnew.c
index 1bca6d5..f0d2221 100644
--- a/src/str/ft_strnew.c
+++ b/src/str/ft_strnew.c
@@ -6,13 +6,26 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:17:34 by cacharle #+# #+# */
-/* Updated: 2019/11/20 03:16:14 by cacharle ### ########.fr */
+/* Updated: 2020/05/11 15:28:15 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
-char *ft_strnew(size_t size)
+/*
+** \brief Create a new null-terminated string
+** \param len String length
+** \return Allocated string or NULL is allocation failed
+** \note This implementation doesn't follow the subject
+** because zeroing every byte is too inefficient
+*/
+
+char *ft_strnew(size_t len)
{
- return ((char*)ft_calloc(size + 1, sizeof(char)));
+ char *s;
+
+ if ((s = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
+ return (NULL);
+ s[len] = '\0';
+ return (s);
}
diff --git a/src/str/ft_strsdestroy.c b/src/str/ft_strsdestroy.c
new file mode 100644
index 0000000..bb2204c
--- /dev/null
+++ b/src/str/ft_strsdestroy.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strsdestroy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/27 16:30:55 by cacharle #+# #+# */
+/* Updated: 2020/05/11 15:53:49 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+/*
+** \brief Destroy a NULL-terminated array of malloc'd string
+** \param strs Strings to destroy
+** \return NULL (so that it can be used in return statement)
+*/
+
+void *ft_strsdestroy(char **strs)
+{
+ int i;
+
+ i = -1;
+ while (strs[++i] != NULL)
+ free(strs[i]);
+ free(strs);
+ return (NULL);
+}
diff --git a/src/str/ft_strsjoinf.c b/src/str/ft_strsjoinf.c
index 36a2892..c1a0623 100644
--- a/src/str/ft_strsjoinf.c
+++ b/src/str/ft_strsjoinf.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/04 14:27:33 by charles #+# #+# */
-/* Updated: 2020/04/04 23:24:24 by charles ### ########.fr */
+/* Updated: 2020/05/11 15:54:33 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,6 +24,6 @@ char *ft_strsjoinf(char **strs, char *delim)
char *ret;
ret = ft_strsjoin(strs, delim);
- ft_split_destroy(strs);
+ ft_strsdestroy(strs);
return (ret);
}
diff --git a/src/str/ft_strslen.c b/src/str/ft_strslen.c
new file mode 100644
index 0000000..0268033
--- /dev/null
+++ b/src/str/ft_strslen.c
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strslen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/05/10 20:58:46 by charles #+# #+# */
+/* Updated: 2020/05/11 15:49:40 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_str.h"
+
+size_t ft_strslen(char **strs)
+{
+ size_t count;
+
+ count = 0;
+ while (strs[count] != NULL)
+ count++;
+ return (count);
+}