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.c93
1 files changed, 24 insertions, 69 deletions
diff --git a/src/p_args_len.c b/src/p_args_len.c
index 801406f..3e5bfbf 100644
--- a/src/p_args_len.c
+++ b/src/p_args_len.c
@@ -14,87 +14,42 @@
#include <stddef.h>
#include "d_define.h"
+#include "u_parse.h"
+#include "u_utils.h"
-static size_t
- p_skip_delim_size(const char word[], char c, size_t end)
+static t_bool
+ p_meet_whitespace(const char *head, char *ptr, t_quote_mode mode)
{
- end++;
- if (word[end] == c)
- return (end + 1);
- while (word[end] != C_NUL && word[end] != c)
+ if (mode == Q_NONE && u_is_not_escaped(head, ptr) == TRUE)
{
- end++;
- if (word[end] == c && c == C_DQUOTE)
- {
- if (word[end - 1] == C_BACKS && word[end - 2] != C_BACKS)
- {
- end++;
- }
- }
+ return (TRUE);
}
- if (word[end] != C_NUL)
- {
- end++;
- }
- return (end);
-}
-
-static size_t
- p_skip_unquote(const char word[], size_t end)
-{
- while (word[end] != C_NUL && ft_iswhitespace(word[end]) == FALSE)
- {
- end++;
- if (ft_iswhitespace(word[end]) == TRUE && end == 1 &&
- word[end - 1] == C_BACKS)
- {
- end++;
- }
- else if (ft_iswhitespace(word[end]) == TRUE && end > 1 &&
- word[end - 1] == C_BACKS && word[end - 2] != C_BACKS)
- {
- end++;
- }
- }
- return (end);
-}
-
-static size_t
- p_skip_quote(const char word[], size_t end)
-{
- while (word[end] != C_NUL && ft_iswhitespace(word[end]) == FALSE)
- {
- if (word[end] == C_SQUOTE || word[end] == C_DQUOTE)
- {
- end = p_skip_delim_size(word, word[end], end);
- }
- else
- {
- while (word[end] != C_NUL &&
- ft_iswhitespace(word[end]) == FALSE)
- {
- end++;
- }
- }
- }
- return (end);
+ return (FALSE);
}
size_t
p_arg_len(const char word[], const size_t start)
{
- size_t end;
+ t_quote_mode mode;
+ char *ptr;
+ size_t end;
+ t_bool terminate;
+ mode = Q_NONE;
end = start;
- if (word[start] != C_SQUOTE && word[start] != C_DQUOTE &&
- word[start] != C_NUL)
- {
- end = p_skip_unquote(word, end);
- }
- else if (word[end] == C_SQUOTE || word[end] == C_DQUOTE)
+ ptr = (char*)word + start;
+ terminate = FALSE;
+ while (*ptr != C_NUL && terminate == FALSE)
{
- end = p_skip_quote(word, end);
+ 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++;
}
- return (end);
+ ptr -= 1;
+ return (ptr - word);
}