update: fixed issues of empty args getting eaten
This commit is contained in:
parent
7d3e0a6a49
commit
77fa234f41
1 changed files with 16 additions and 15 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/24 23:05:59 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/27 19:37:59 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ t_error list_files_in_current_directory(t_vec_str *out);
|
||||||
t_error _word_into_str_inner(struct s_word_str_args args);
|
t_error _word_into_str_inner(struct s_word_str_args args);
|
||||||
|
|
||||||
t_error _word_split_loop_expand(\
|
t_error _word_split_loop_expand(\
|
||||||
t_expandable_str val, t_vec_str *append, t_string *tmp)
|
t_expandable_str val, t_vec_str *append, t_string *tmp, bool *exist)
|
||||||
{
|
{
|
||||||
t_vec_str split;
|
t_vec_str split;
|
||||||
t_str stmp;
|
t_str stmp;
|
||||||
|
|
@ -43,17 +43,10 @@ t_error _word_split_loop_expand(\
|
||||||
vec_str_free(split);
|
vec_str_free(split);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
string_push(tmp, val.value);
|
string_push(tmp, val.value);
|
||||||
return (NO_ERROR);
|
*exist = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _word_split_loop(\
|
|
||||||
bool do_split, t_expandable_str val, t_vec_str *append, t_string *tmp)
|
|
||||||
{
|
|
||||||
if (do_split)
|
|
||||||
return (_word_split_loop_expand(val, append, tmp));
|
|
||||||
else
|
|
||||||
string_push(tmp, val.value);
|
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,15 +55,23 @@ t_error _word_split(\
|
||||||
{
|
{
|
||||||
t_string tmp;
|
t_string tmp;
|
||||||
t_usize i;
|
t_usize i;
|
||||||
|
bool exist;
|
||||||
|
|
||||||
tmp = string_new(64);
|
tmp = string_new(64);
|
||||||
i = 0;
|
i = 0;
|
||||||
|
exist = false;
|
||||||
while (i < res->value.len)
|
while (i < res->value.len)
|
||||||
{
|
{
|
||||||
if (_word_split_loop(do_split, res->value.buffer[i++], append, &tmp))
|
if (do_split)
|
||||||
return (string_free(tmp), ERROR);
|
_word_split_loop_expand(res->value.buffer[i], append, &tmp, &exist);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string_push(&tmp, res->value.buffer[i].value);
|
||||||
|
exist = true;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if (!do_split || tmp.len != 0)
|
if (!do_split || tmp.len != 0 || exist)
|
||||||
vec_str_push(append, tmp.buf);
|
vec_str_push(append, tmp.buf);
|
||||||
else
|
else
|
||||||
string_free(tmp);
|
string_free(tmp);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue