mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Exp : Quick logic fix
This commit is contained in:
parent
ed1d8b18fe
commit
2dd54e2827
2 changed files with 10 additions and 9 deletions
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* replace_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/25 13:02:59 by jguelen #+# #+# */
|
||||
/* Updated: 2025/02/25 18:50:00 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/02/26 10:55:00 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ char *replace_in_str(const char *text, size_t index_start, size_t index_end,
|
|||
/*
|
||||
** word is presumed not to be NULL
|
||||
*/
|
||||
int *better_prefix_array(char *word, size_t word_len)
|
||||
static int *better_prefix_array(char *word, size_t word_len)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
|
@ -60,7 +60,7 @@ int *better_prefix_array(char *word, size_t word_len)
|
|||
return (NULL);
|
||||
better_prefix[0] = -1;
|
||||
j = 0;
|
||||
while (++j < m)
|
||||
while (++j < word_len)
|
||||
{
|
||||
if (word[i] == word[j])
|
||||
better_prefix[j] = better_prefix[i];
|
||||
|
|
@ -81,7 +81,7 @@ int *better_prefix_array(char *word, size_t word_len)
|
|||
** Return the index at which the word needle begins in haystack if found,
|
||||
** -1 if needle is not to be found in haystack.
|
||||
*/
|
||||
ssize_t find_word_index(const char *haystack, char *needle)
|
||||
ssize_t find_word_byprefix(const char *haystack, char *needle)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
|
@ -124,7 +124,7 @@ char *replace_substr(const char *text, char *to_replace, char *replacement)
|
|||
{
|
||||
start_index = find_word_index(text, to_replace);
|
||||
if (start_index != -1)
|
||||
return (replace_in_str(text, index_start,
|
||||
return (replace_in_str(text, start_index,
|
||||
(size_t)start_index + len_torep - 1, replacement));
|
||||
}
|
||||
return (ft_strdup(text));
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/25 12:48:39 by jguelen #+# #+# */
|
||||
/* Updated: 2025/02/25 13:03:51 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/02/26 10:56:30 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *replace_in_str(char *text, size_t index_start, size_t index_end,
|
||||
ssize_t find_word_byprefix(const char *haystack, char *needle);
|
||||
char *replace_in_str(const char *text, size_t index_start, size_t index_end,
|
||||
char *replacement);
|
||||
char *replace_substr(char *text, char *to_replace, char *replacement);
|
||||
char *replace_substr(const char *text, char *to_replace, char *replacement);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue