wow such function very test

added multiple char test functions as well as
strsplitwhitespace
This commit is contained in:
Tanguy MAZE 2019-02-25 16:30:35 +01:00
parent aeb0181d74
commit a0c3ac75ae
6 changed files with 148 additions and 3 deletions

View File

@ -6,7 +6,7 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/04/07 12:47:06 by tmaze #+# #+# #
# Updated: 2018/10/08 14:33:36 by tmaze ### ########.fr #
# Updated: 2019/02/25 16:28:32 by tmaze ### ########.fr #
# #
#******************************************************************************#
@ -19,7 +19,7 @@ NAME = libft.a
SRCS = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c ft_strdup.c ft_strcpy.c ft_strncpy.c ft_strcat.c ft_strncat.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strstr.c ft_strnstr.c ft_strcmp.c ft_strncmp.c ft_atoi.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c ft_tolower.c \
ft_memalloc.c ft_memdel.c ft_strnew.c ft_strdel.c ft_strclr.c ft_striter.c ft_striteri.c ft_strmap.c ft_strmapi.c ft_strequ.c ft_strnequ.c ft_strsub.c ft_strjoin.c ft_strtrim.c ft_strsplit.c ft_itoa.c ft_putchar.c ft_putstr.c ft_putendl.c ft_putnbr.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c\
ft_lstnew.c ft_lstdelone.c ft_lstdel.c ft_lstadd.c ft_lstiter.c ft_lstmap.c \
ft_isupper.c ft_islower.c ft_str_is_alpha.c ft_str_is_lowercase.c ft_str_is_numeric.c ft_str_is_printable.c ft_str_is_uppercase.c ft_strcapitalize.c ft_strlcpy.c ft_strlowcase.c ft_strupcase.c ft_lstsize.c ft_lstgetat.c ft_lstgetlast.c ft_sort_params.c ft_print_words_tables.c ft_lstaddend.c ft_strndup.c ft_abs.c ft_strnchr.c ft_strrnchr.c get_next_line.c ft_del_words_tables.c ft_putstrn.c ft_nbrlen.c ft_putstrpad.c ft_putnbrpad.c ft_lstsort.c ft_lstaddsort.c ft_round.c
ft_isupper.c ft_islower.c ft_str_is_alpha.c ft_str_is_lowercase.c ft_str_is_numeric.c ft_str_is_printable.c ft_str_is_uppercase.c ft_strcapitalize.c ft_strlcpy.c ft_strlowcase.c ft_strupcase.c ft_lstsize.c ft_lstgetat.c ft_lstgetlast.c ft_sort_params.c ft_print_words_tables.c ft_lstaddend.c ft_strndup.c ft_abs.c ft_strnchr.c ft_strrnchr.c get_next_line.c ft_del_words_tables.c ft_putstrn.c ft_nbrlen.c ft_putstrpad.c ft_putnbrpad.c ft_lstsort.c ft_lstaddsort.c ft_round.c ft_iswhitespace.c ft_issign.c ft_hasdigit.c ft_strsplitwhitespace.c
OBJS = $(SRCS:.c=.o)
INCLS = -I.

23
ft_hasdigit.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hasdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/25 16:16:40 by tmaze #+# #+# */
/* Updated: 2019/02/25 16:17:31 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_hasdigit(char *s)
{
int i;
i = 0;
while (s[i] && !ft_isdigit(s[i]))
i++;
return (ft_isdigit(s[i]));
}

18
ft_issign.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_issign.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/25 16:18:54 by tmaze #+# #+# */
/* Updated: 2019/02/25 16:19:13 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_issign(char c)
{
return (c == '+' || c == '-');
}

19
ft_iswhitespace.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iswhitespace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/25 16:11:19 by tmaze #+# #+# */
/* Updated: 2019/02/25 16:13:25 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_iswhitespace(char c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f'
|| c == '\r');
}

80
ft_strsplitwhitespace.c Normal file
View File

@ -0,0 +1,80 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplitwhitespace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/25 16:25:18 by tmaze #+# #+# */
/* Updated: 2019/02/25 16:26:00 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int count_words_ws(char const *s)
{
int i;
int nb_words;
int in_word;
in_word = 0;
nb_words = 0;
i = -1;
while (++i == 0 || s[i - 1])
if (!in_word && !ft_iswhitespace(s[i]) && s[i] != '\0')
{
in_word = 1;
nb_words++;
}
else if (in_word && (ft_iswhitespace(s[i]) || s[i] == '\0'))
in_word = 0;
return (nb_words);
}
static char **get_table_ws(char const *s, char **tab)
{
int i;
int nb_words;
int in_word;
size_t start;
nb_words = 0;
in_word = 0;
i = -1;
while (++i == 0 || s[i - 1])
if (!in_word && !ft_iswhitespace(s[i]) && (in_word = 1))
start = i;
else if (in_word && (ft_iswhitespace(s[i]) || s[i] == '\0'))
{
if ((tab[nb_words] = ft_strsub(s, start, i - start)) == NULL)
{
while (--nb_words >= 0)
ft_strdel(&tab[nb_words]);
free(tab);
return (NULL);
}
nb_words++;
in_word = 0;
}
return (tab);
}
char **ft_strsplitwhitespace(char *s)
{
int nb_words;
char **tab;
nb_words = 0;
tab = NULL;
if (s != NULL)
{
nb_words = count_words_ws(s);
if ((tab = (char**)malloc(sizeof(char**) * (nb_words + 1))) == NULL)
return (NULL);
tab[nb_words] = NULL;
return (get_table_ws(s, tab));
}
else
return (NULL);
}

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */
/* Updated: 2018/10/24 13:38:20 by tmaze ### ########.fr */
/* Updated: 2019/02/25 16:28:20 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@ -174,4 +174,9 @@ void ft_lstaddsort(t_list **lst, t_list *new,
int ft_round(float x, float ind);
int ft_issign(char c);
int ft_iswhitespace(char c);
int ft_hasdigit(char *s);
char **ft_strsplitwhitespace(char *s);
#endif