-
Notifications
You must be signed in to change notification settings - Fork 0
/
quote_removal.c
63 lines (57 loc) · 1.55 KB
/
quote_removal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* quote_removal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aoizel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 14:49:08 by aoizel #+# #+# */
/* Updated: 2024/01/22 16:06:52 by aoizel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void word_remove_quotes(char *word)
{
int i;
int j;
char quote;
quote = 0;
i = 0;
j = 0;
while (word[i])
{
if (!quote && (word[i] == '"' || word[i] == '\''))
quote = word[i++];
if (quote && quote == word[i])
{
quote = 0;
i++;
continue ;
}
word[j] = word[i];
i++;
j++;
}
word[j] = '\0';
}
void unescape_quotes(char *word)
{
int i;
i = 0;
while (word[i])
{
if (word[i] == '"' - 10 || word[i] == '\'' - 10)
word[i] = word[i] + 10;
i++;
}
}
int quote_removal(t_wordlst *wordlst)
{
while (wordlst)
{
word_remove_quotes(wordlst->word);
unescape_quotes(wordlst->word);
wordlst = wordlst->next;
}
return (0);
}