/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* p_args_len.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #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; size_t end; t_bool terminate; mode = Q_NONE; end = start; 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)) terminate = p_meet_whitespace(word, ptr, mode); ptr++; } ptr -= 1; return (ptr - word); }