blob: e20cde833741ac461cdba19ab68eff475dfa5d29 (
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* p_args_len.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <stddef.h>
#include "d_define.h"
#include "u_parse.h"
#include "u_utils.h"
static t_bool p_meet_whitespace(const char *head,
char *ptr,
t_quote_mode mode)
{
if (mode == Q_NONE && u_is_not_escaped(head, ptr) == TRUE)
{
return (TRUE);
}
return (FALSE);
}
size_t p_arg_len(const char word[], const size_t start)
{
t_quote_mode mode;
char *ptr;
t_bool terminate;
mode = Q_NONE;
ptr = (char*)word + start;
terminate = FALSE;
while (*ptr != C_NUL && terminate == FALSE)
{
if (*ptr == C_DQUOTE)
mode = u_meet_dquote(word, ptr, mode);
else if (*ptr == C_SQUOTE)
mode = u_meet_squote(word, ptr, mode);
else if (ft_iswhitespace(*ptr) == TRUE)
terminate = p_meet_whitespace(word, ptr, mode);
ptr++;
}
if (terminate == TRUE)
ptr -= 1;
return (ptr - word);
}
|