From bf263810b0a47a68fae0681e6e6d2229a488c069 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 3 Apr 2020 15:11:33 +0200 Subject: Added Dynamic string struct (no test, no doc) --- src/dstr/ft_dstrnew.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/dstr/ft_dstrnew.c (limited to 'src/dstr/ft_dstrnew.c') diff --git a/src/dstr/ft_dstrnew.c b/src/dstr/ft_dstrnew.c new file mode 100644 index 0000000..189fc78 --- /dev/null +++ b/src/dstr/ft_dstrnew.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dstrnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/03 13:54:52 by charles #+# #+# */ +/* Updated: 2020/04/03 13:58:17 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_dstr.h" + +t_ftdstr *ft_dstrnew(char *from) +{ + t_ftdstr *dstr; + + if ((dstr = (t_ftdstr*)malloc(sizeof(t_ftdstr))) == NULL || + (dstr->str = ft_strdup(from)) == NULL) + return (NULL); + dstr->length = ft_strlen(from); + dstr->capacity = dstr->length + 1; + return (dstr); +} -- cgit From 42316d8393d32bd88fb8e0cba6825185f78dacd0 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 4 Apr 2020 21:28:21 +0200 Subject: Added test and doc for dynamic string --- src/dstr/ft_dstrnew.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/dstr/ft_dstrnew.c') diff --git a/src/dstr/ft_dstrnew.c b/src/dstr/ft_dstrnew.c index 189fc78..8ae4a64 100644 --- a/src/dstr/ft_dstrnew.c +++ b/src/dstr/ft_dstrnew.c @@ -6,12 +6,19 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/03 13:54:52 by charles #+# #+# */ -/* Updated: 2020/04/03 13:58:17 by charles ### ########.fr */ +/* Updated: 2020/04/04 19:50:38 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft_dstr.h" +/* +** \brief Create a new dynamic string +** \param from Static string to create the dynamic one from +** (will be duplicated) +** \return Created dynamic string or NULL on malloc error +*/ + t_ftdstr *ft_dstrnew(char *from) { t_ftdstr *dstr; -- cgit