single quote expander

This commit is contained in:
lderidde
2025-02-08 20:59:56 +01:00
parent 1e5e7a1bfc
commit c102a6884c
2 changed files with 26 additions and 2 deletions

View File

@@ -106,6 +106,30 @@ void expander_var(t_ast_n *node, int j)
node->args[j] = new;
}
int in_squote(char *str, char *ch)
{
if (!ft_strchr(str, '\'') && !ft_strchr(str, '\"'))
return (0);
else if (ft_strchr(str, '\'') && !ft_strchr(str, '\"'))
{
if ((ch > ft_strchr(str, '\'')) && ch < ft_strrchr(str, '\''))
return (1);
return (0);
}
else if (!ft_strchr(str, '\'') && ft_strchr(str, '\"'))
return (0);
else
{
if (ft_strchr(str, '\'') < ft_strchr(str, '\"'))
{
if ((ch > ft_strchr(str, '\'')) && ch < ft_strrchr(str, '\''))
return (1);
return (0);
}
return (0);
}
}
int expand_var(t_ast_n *node, int j)
{
int i;
@@ -113,7 +137,7 @@ int expand_var(t_ast_n *node, int j)
i = 0;
while (node->args[j][i])
{
if (node->args[j][i] == '$')
if (node->args[j][i] == '$' && !in_squote(node->args[j], &node->args[j][i]))
return (expander_var(node, j), 1);
i++;
}

View File

@@ -53,7 +53,7 @@ int ifremove_quote(t_ast_n *node, int j)
c = '\'';
else
c = '\"';
if (c && (ft_strchr(node->args[j], c) && ft_strrchr(node->args[j], c)))
if (c && (ft_strchr(node->args[j], c) != ft_strrchr(node->args[j], c)))
remove_quote(node, j, c);
if (c)
ret = 1;