示例#1
0
char			*skip_quotes_nb_arg(char *str, size_t *i, t_cmd *cmd)
{
	size_t		start;

	if (!verif_empty_quote(str, i))
	{
		return (NULL);
	}
	start = *i;
	while (str[*i] && !ft_isspace2(str[*i]) && !is_sep(i, str, 0, cmd))
	{
		if (is_redir(i, str, 0, cmd) && ft_isdigit(str[*i]))
		{
			break ;
		}
		if (!is_escaped_char(str, *i) && is_quote_open(str[*i]))
		{
			get_pos_after_quote(i, str);
		}
		(*i)++;
	}
	if (start != *i)
		return ((void*)1);
	return (NULL);
}
size_t memory_length(const std::string& input) {
    size_t length = 0;
    size_t surrounding_quotes = 2;
    for ( auto it = input.begin(); it != input.end(); it++) {
       if (is_escaped_char('\\',it,input.end()) || is_escaped_char('\"',it,input.end())) {
           length += 1;
           it++;
       } else if (is_escaped_char('x',it,input.end())) {
           length += 1;
           it++;
           save_increase_iterator(it,input.end());
           save_increase_iterator(it,input.end());
       } else {
            length += 1;
       }
    }
    return length-surrounding_quotes;
}
示例#3
0
void			get_pos_after_quote(size_t *i, char *str)
{
	char open;

	open = str[*i];
	while (!(is_quote_close(open, str[*i + 1]) &&
	!is_escaped_char(str, *i + 1)) && str[*i + 1])
		(*i)++;
	if (str[*i])
		(*i)++;
}
示例#4
0
int				verif_empty_quote(char *str, size_t *i)
{
	size_t tmp;

	tmp = *i + 1;
	if (!str[tmp] || ft_isspace2(str[tmp]))
	{
		return (1);
	}
	while ((!is_quote_close(str[*i], str[tmp]) && str[tmp]) ||
	is_escaped_char(str, tmp))
	{
		if ((!is_quote(str[tmp]) && !ft_isspace2(str[tmp])) ||
		is_escaped_char(str, tmp))
			return (1);
		tmp++;
	}
	if (str[tmp])
		*i = tmp + 1;
	return (0);
}
示例#5
0
char			*skip_quotes(char **str, size_t *i, t_cmd *cmd)
{
	size_t		start;

	if (is_quote_open((*str)[*i]) && !is_escaped_char(*str, *i) &&
	!verif_empty_quote(*str, i))
		return (NULL);
	start = *i;
	skip_quotes_replace_string(cmd, str, i);
	if (start != *i)
	{
		return (ft_strsub(*str, start, *i - start));
	}
	return (NULL);
}
示例#6
0
int			is_tilde_and_replace(t_data *data, char **str, size_t *index)
{
	char	*home;
	char	*tmp;

	if (((*str)[*index] == '~' && !is_escaped_char(*str, *index) &&
		(ft_isspace2((*str)[*index]) || (*str)[*index + 1] == '/'
		|| (*str)[*index + 1] == '\0')))
	{
		home = find_var_env(data, "HOME", data->env);
		if (home)
		{
			(*str)[*index] = '\0';
			tmp = ft_strjoinaf1(ft_strjoin(*str, home), *str + *index + 1);
			free(*str);
			*str = tmp;
			(*index) += ft_strlen(home);
		}
		free(home);
	}
	return (1);
}
示例#7
0
static void		skip_quotes_replace_string(t_cmd *cmd, char **str, size_t *i)
{
	while ((*str)[*i] && !ft_isspace2((*str)[*i]) && !is_sep(i, *str, 0, cmd))
	{
		if ((*str)[*i] == '\\')
		{
			if ((*str)[*i + 1])
				*str = delete_char(*str, *i + 1);
		}
		else
		{
			if ((is_redir(i, *str, 0, cmd) || is_aggr(i, *str, 0)) &&
			ft_isdigit((*str)[*i]))
			{
				(*i)++;
				break ;
			}
			if (is_quote_open((*str)[*i]) && !is_escaped_char(*str, *i))
				join_inside_quote(i, str);
		}
		if ((*str)[*i])
			(*i)++;
	}
}
示例#8
0
		void do_wr_val(char x)
		{
			if(is_escaped_char(x))
				out << '\\' << translate_esc_char(x);
			else out << x;
		}