summaryrefslogtreecommitdiffstats
path: root/src/p_args_len.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/p_args_len.c')
-rw-r--r--src/p_args_len.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/p_args_len.c b/src/p_args_len.c
new file mode 100644
index 0000000..729e5c5
--- /dev/null
+++ b/src/p_args_len.c
@@ -0,0 +1,56 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* 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;
+ 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) == TRUE)
+ terminate = p_meet_whitespace(word, ptr, mode);
+ ptr++;
+ }
+ if (terminate == TRUE)
+ ptr -= 1;
+ return (ptr - word);
+}
+