aboutsummaryrefslogtreecommitdiff
path: root/src/str
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-14 03:46:08 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-14 03:46:08 +0100
commit9af2885d872de9c60b11159efe0685738031096d (patch)
tree813183555eae5d0a84f11d7be3178d07b3d5f9d9 /src/str
parentadbcf69ed50ea3896d4bbe863ea5d214ae5a0299 (diff)
downloadlibft-9af2885d872de9c60b11159efe0685738031096d.tar.gz
libft-9af2885d872de9c60b11159efe0685738031096d.tar.bz2
libft-9af2885d872de9c60b11159efe0685738031096d.zip
Added documentation for all functions and refactored ft_strjoin_free -> ft_strjoinf
Diffstat (limited to 'src/str')
-rw-r--r--src/str/ft_atoi_strict.c4
-rw-r--r--src/str/ft_itoa.c5
-rw-r--r--src/str/ft_strdup.c4
-rw-r--r--src/str/ft_strjoin.c5
-rw-r--r--src/str/ft_strjoin_free_snd.c26
-rw-r--r--src/str/ft_strjoinf.c (renamed from src/str/ft_strjoin_free.c)17
-rw-r--r--src/str/ft_strndup.c5
-rw-r--r--src/str/ft_strtoupper.c6
-rw-r--r--src/str/ft_substr.c4
9 files changed, 28 insertions, 48 deletions
diff --git a/src/str/ft_atoi_strict.c b/src/str/ft_atoi_strict.c
index f573593..8be4c4b 100644
--- a/src/str/ft_atoi_strict.c
+++ b/src/str/ft_atoi_strict.c
@@ -6,13 +6,13 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/15 10:06:29 by cacharle #+# #+# */
-/* Updated: 2020/02/10 02:20:40 by cacharle ### ########.fr */
+/* Updated: 2020/02/14 02:46:43 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
-int ft_strict_atoi(const char *s)
+int ft_atoi_strict(const char *s)
{
char *end;
long ret;
diff --git a/src/str/ft_itoa.c b/src/str/ft_itoa.c
index 166e278..39b6e12 100644
--- a/src/str/ft_itoa.c
+++ b/src/str/ft_itoa.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:19:56 by cacharle #+# #+# */
-/* Updated: 2019/11/20 03:13:10 by cacharle ### ########.fr */
+/* Updated: 2020/02/14 03:39:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,8 +25,9 @@ char *ft_itoa(int n)
u_nbr /= 10;
len++;
}
- if ((str = ft_strnew(len)) == NULL)
+ if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
return (NULL);
+ str[len] = '\0';
u_nbr = n < 0 ? -n : n;
if (n < 0)
str[0] = '-';
diff --git a/src/str/ft_strdup.c b/src/str/ft_strdup.c
index 65a6ac6..b248272 100644
--- a/src/str/ft_strdup.c
+++ b/src/str/ft_strdup.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:18:07 by cacharle #+# #+# */
-/* Updated: 2019/11/20 03:13:47 by cacharle ### ########.fr */
+/* Updated: 2020/02/14 03:39:56 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,7 +16,7 @@ char *ft_strdup(const char *s)
{
char *clone;
- if ((clone = ft_strnew(ft_strlen(s))) == NULL)
+ if ((clone = (char*)malloc(sizeof(char) * (ft_strlen(s) + 1))) == NULL)
return (NULL);
return (ft_strcpy(clone, s));
}
diff --git a/src/str/ft_strjoin.c b/src/str/ft_strjoin.c
index 2bc4908..b65eaa2 100644
--- a/src/str/ft_strjoin.c
+++ b/src/str/ft_strjoin.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 10:35:26 by cacharle #+# #+# */
-/* Updated: 2019/11/20 04:02:20 by cacharle ### ########.fr */
+/* Updated: 2020/02/14 03:40:39 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,8 @@ char *ft_strjoin(char const *s1, char const *s2)
if (s1 == NULL || s2 == NULL)
return (NULL);
- if ((joined = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) == NULL)
+ if ((joined = (char*)malloc(sizeof(char)
+ * (ft_strlen(s1) + ft_strlen(s2) + 1))) == NULL)
return (NULL);
return (ft_strcat(ft_strcpy(joined, s1), s2));
}
diff --git a/src/str/ft_strjoin_free_snd.c b/src/str/ft_strjoin_free_snd.c
deleted file mode 100644
index 0503211..0000000
--- a/src/str/ft_strjoin_free_snd.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_strjoin_free_snd.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/11/05 22:12:56 by cacharle #+# #+# */
-/* Updated: 2019/11/14 10:07:19 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include <stdlib.h>
-#include "libft.h"
-
-char *ft_strjoin_free_snd(char const *s1, char const *s2)
-{
- char *joined;
-
- if (s1 == NULL || s2 == NULL)
- return (NULL);
- if ((joined = ft_strjoin(s1, s2)) == NULL)
- return (NULL);
- free((void*)s2);
- return (joined);
-}
diff --git a/src/str/ft_strjoin_free.c b/src/str/ft_strjoinf.c
index 4050b77..228a963 100644
--- a/src/str/ft_strjoin_free.c
+++ b/src/str/ft_strjoinf.c
@@ -1,29 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_strjoin_free.c :+: :+: :+: */
+/* ft_strjoinf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/11/05 21:32:48 by cacharle #+# #+# */
-/* Updated: 2019/11/14 10:07:10 by cacharle ### ########.fr */
+/* Created: 2020/02/14 03:41:07 by cacharle #+# #+# */
+/* Updated: 2020/02/14 03:41:25 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
+#include "libft_str.h"
-char *ft_strjoin_free(char const *s1, char const *s2, int free_nb)
+char *ft_strjoinf(char const *s1, char const *s2, t_ftstrjoinf_tag tag)
{
char *joined;
- if (s1 == NULL || s2 == NULL || free_nb < 0 || free_nb > 2)
+ if (s1 == NULL || s2 == NULL)
return (NULL);
if ((joined = ft_strjoin(s1, s2)) == NULL)
return (NULL);
- if (free_nb == 1)
+ if (tag == FT_STRJOINF_FST)
free((void*)s1);
- if (free_nb == 2)
+ else if (tag == FT_STRJOINF_SND)
+ free((void*)s2);
+ else if (tag == FT_STRJOINF_ALL)
{
free((void*)s1);
free((void*)s2);
diff --git a/src/str/ft_strndup.c b/src/str/ft_strndup.c
index 0683dae..894ea4e 100644
--- a/src/str/ft_strndup.c
+++ b/src/str/ft_strndup.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/25 03:28:52 by cacharle #+# #+# */
-/* Updated: 2019/11/20 04:15:44 by cacharle ### ########.fr */
+/* Updated: 2020/02/14 03:43:55 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,7 +16,8 @@ char *ft_strndup(const char *s1, size_t n)
{
char *clone;
- if ((clone = ft_strnew(n)) == NULL)
+ if ((clone = (char*)malloc(sizeof(char) * (n + 1))) == NULL)
return (NULL);
+ clone[n] = '\0';
return (ft_strncpy(clone, s1, n));
}
diff --git a/src/str/ft_strtoupper.c b/src/str/ft_strtoupper.c
index 07c19e5..4a751d3 100644
--- a/src/str/ft_strtoupper.c
+++ b/src/str/ft_strtoupper.c
@@ -6,14 +6,14 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/10 04:12:04 by cacharle #+# #+# */
-/* Updated: 2020/02/10 05:05:38 by cacharle ### ########.fr */
+/* Updated: 2020/02/14 02:49:35 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft_str.h"
#include "libft_ctype.h"
-char *ft_strtolower(char *s)
+char *ft_strtoupper(char *s)
{
int i;
@@ -21,6 +21,6 @@ char *ft_strtolower(char *s)
return (NULL);
i = -1;
while (s[i])
- s[i] = ft_tolower(s[i]);
+ s[i] = ft_toupper(s[i]);
return (s);
}
diff --git a/src/str/ft_substr.c b/src/str/ft_substr.c
index 84d6c58..ad9c706 100644
--- a/src/str/ft_substr.c
+++ b/src/str/ft_substr.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/17 08:28:49 by cacharle #+# #+# */
-/* Updated: 2019/11/20 03:57:58 by cacharle ### ########.fr */
+/* Updated: 2020/02/14 03:44:42 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
if (s == NULL)
return (NULL);
- if ((sub = ft_strnew(len)) == NULL)
+ if ((sub = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
return (NULL);
if (start > ft_strlen(s))
return (sub);