clean: norm part2 (FINAL)
This commit is contained in:
@ -6,16 +6,30 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/16 16:26:15 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/29 16:53:15 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./format_private.h"
|
||||
|
||||
static int ft_replace(char **str, size_t i)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
temp = ft_strreplace(*str, " ", i, i);
|
||||
free(*str);
|
||||
if (temp == NULL)
|
||||
{
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
return (1);
|
||||
}
|
||||
*str = temp;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static char *ft_spacer_after(const char *str)
|
||||
{
|
||||
char *out;
|
||||
char *temp;
|
||||
size_t i;
|
||||
|
||||
out = ft_strdup(str);
|
||||
@ -32,10 +46,7 @@ static char *ft_spacer_after(const char *str)
|
||||
{
|
||||
while (out[i] == out[i - 1])
|
||||
i++;
|
||||
temp = ft_strreplace(out, " ", i, i);
|
||||
free(out);
|
||||
out = temp;
|
||||
if (out == NULL)
|
||||
if (ft_replace(&out, i))
|
||||
return (NULL);
|
||||
}
|
||||
if (out[i] != '\0')
|
||||
@ -47,14 +58,13 @@ static char *ft_spacer_after(const char *str)
|
||||
static char *ft_spacer_before(const char *str)
|
||||
{
|
||||
char *out;
|
||||
char *temp;
|
||||
size_t i;
|
||||
ssize_t i;
|
||||
|
||||
out = ft_strdup(str);
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (out[i + 1] != '\0')
|
||||
i = -1;
|
||||
while (out[++i] != '\0')
|
||||
{
|
||||
while (ft_is_in_quote(out, i))
|
||||
i++;
|
||||
@ -66,13 +76,9 @@ static char *ft_spacer_before(const char *str)
|
||||
i++;
|
||||
while (out[i] == out[i + 1])
|
||||
i++;
|
||||
temp = ft_strreplace(out, " ", i + 1, i + 1);
|
||||
free(out);
|
||||
out = temp;
|
||||
if (out == NULL)
|
||||
if (ft_replace(&out, i + 1))
|
||||
return (NULL);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
|
Reference in New Issue
Block a user