wordsplit: handle single word with spaces before or after

This commit is contained in:
Khaïs COLIN 2025-02-14 13:30:18 +01:00
parent fc985ea046
commit 8defbf4d13
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
9 changed files with 154 additions and 16 deletions

View file

@ -6,7 +6,7 @@
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 16:06:09 by jguelen #+# #+# */
/* Updated: 2025/02/20 14:44:53 by khais ### ########.fr */
/* Updated: 2025/02/20 14:48:28 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -130,6 +130,8 @@ size_t ft_strlcat(char *dst, const char *src, size_t size);
int ft_toupper(int c);
int ft_tolower(int c);
char *ft_strchr(const char *s, int c);
size_t ft_strchridx(const char *s, char c);
size_t ft_strnchridx(const char *s, char c);
char *ft_strrchr(const char *s, int c);
int ft_strcmp(const char *s1, const char *s2);
int ft_strncmp(const char *s1, const char *s2, size_t n);

View file

@ -4,14 +4,57 @@ ifeq ($(CFLAGS),)
CFLAGS = -Wall -Wextra -Werror -g
endif
NAME = libft.a
SOURCES = free2.c \
ft_atoi.c ft_itoa.c ft_putendl_fd.c ft_strlcat.c ft_substr.c \
ft_bzero.c ft_putnbr_fd.c ft_strlcpy.c ft_tolower.c ft_calloc.c \
ft_memchr.c ft_putstr_fd.c ft_strlen.c ft_toupper.c ft_isalnum.c \
ft_memcmp.c ft_split.c ft_strmapi.c ft_isalpha.c ft_memcpy.c ft_strchr.c \
ft_strcmp.c ft_strncmp.c ft_isascii.c ft_memmove.c ft_strdup.c ft_strnstr.c \
ft_isdigit.c ft_memset.c ft_striteri.c ft_strrchr.c ft_isprint.c \
ft_putchar_fd.c ft_strjoin.c ft_strtrim.c ft_min_max.c ft_strjoin_sepc.c
SOURCES = \
free2.c \
ft_atoi.c \
ft_bzero.c \
ft_calloc.c \
ft_isalnum.c \
ft_isalpha.c \
ft_isascii.c \
ft_isdigit.c \
ft_isprint.c \
ft_itoa.c \
ft_lstadd_back_bonus.c \
ft_lstadd_front_bonus.c \
ft_lstclear_bonus.c \
ft_lstdelone_bonus.c \
ft_lstiter_bonus.c \
ft_lstlast_bonus.c \
ft_lstmap_bonus.c \
ft_lstnew_bonus.c \
ft_lstsize_bonus.c \
ft_memchr.c \
ft_memcmp.c \
ft_memcpy.c \
ft_memmove.c \
ft_memset.c \
ft_min_max.c \
ft_putchar_fd.c \
ft_putendl_fd.c \
ft_putnbr_fd.c \
ft_putstr_fd.c \
ft_split.c \
ft_strchr.c \
ft_strchridx.c \
ft_strcmp.c \
ft_strdup.c \
ft_striteri.c \
ft_strjoin.c \
ft_strjoin_sepc.c \
ft_strlcat.c \
ft_strlcpy.c \
ft_strlen.c \
ft_strmapi.c \
ft_strnchridx.c \
ft_strncmp.c \
ft_strnstr.c \
ft_strrchr.c \
ft_strtrim.c \
ft_substr.c \
ft_tolower.c \
ft_toupper.c \
BONUSSOURCES = ft_lstnew_bonus.c ft_lstadd_back_bonus.c ft_lstsize_bonus.c \
ft_lstadd_front_bonus.c ft_lstclear_bonus.c ft_lstdelone_bonus.c \
ft_lstiter_bonus.c ft_lstlast_bonus.c ft_lstmap_bonus.c

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchridx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/14 14:02:34 by khais #+# #+# */
/* Updated: 2025/02/14 15:12:01 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
/*
** return the index of the character c in the string s, or 0 if s is null, or
** length of s if c is not found.
*/
size_t ft_strchridx(const char *s, char c)
{
size_t i;
if (s == NULL)
return (0);
i = 0;
while (s[i] != c && s[i] != '\0')
i++;
return (i);
}

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnchridx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/14 14:16:32 by khais #+# #+# */
/* Updated: 2025/02/14 15:12:19 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
/*
** return the index of the first character that is not c in the string s, or 0
** if not found or s is null.
*/
size_t ft_strnchridx(const char *s, char c)
{
size_t i;
if (s == NULL)
return (0);
i = 0;
while (s[i] == c && s[i] != '\0')
i++;
if (s[i] == '\0')
return (0);
return (i);
}