blob: 8160ca6364108aba39260bd3b6cae819170fe240 (
plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* trim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:36 by nahaddac #+# #+# */
/* Updated: 2020/07/17 10:18:51 by nahaddac ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
char *del_space(t_token *tk)
{
int i;
char *s;
i = 0;
while(tk->content[i] != '\0')
{
if(tk->content[i] == '\\')
return tk->content;
if(tk->content[i] == ' ')
break;
i++;
}
s = ft_strsubf(tk->content, 0, i);
return(s);
}
char *del_quote(char *str)
{
int i;
char *s;
i = 0;
while(str[i++] != '\0')
{
if(str[i] == '\\')
i+=2;
if (str[i] == '\'' || str[i] == '"')
break;
}
if(str[i] != '\'' && str[i] != '"')
return str;
s = ft_strsubf(str, 1, i - 1);
return (s);
}
t_ftlst *lexe_trim_out(t_ftlst *lst)
{
t_ftlst *first;
t_token *tk;
first = lst;
while(lst != NULL)
{
tk = lst->data;
if (tk->tag & (TAG_STR_DOUBLE | TAG_STR_SINGLE))
{
tk->content = del_quote(tk->content);
if(lst->next == NULL)
if (tk->tag & TAG_STICK)
tk->tag -= TAG_STICK;
}
else
{
tk->content = del_space(tk);
if(lst->next == NULL)
if (tk->tag & TAG_STICK)
tk->tag -= TAG_STICK;
}
lst = lst->next;
}
return (first);
}
|