/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   lexer_parse_quotes.c                               :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: qmennen <qmennen@student.codam.nl>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/02/27 19:02:37 by qmennen           #+#    #+#             */
/*   Updated: 2025/02/27 19:26:35 by qmennen          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

char	*lexer_parse_quotes(t_minishell *msh, t_lexer *lexer)
{
	int		start;
	int		len;
	char	qc;
	char	*word;

	qc = lexer->current_char;
	word = NULL;
	lexer_readchar(lexer);
	start = lexer->pos;
	while (lexer->current_char != '\0' && lexer->current_char != qc)
		lexer_readchar(lexer);
	len = lexer->pos - start;
	word = malloc_safe(msh, sizeof(char) * len + 1);
	ft_strlcpy(word, lexer->input + start, len + 1);
	if (lexer->current_char == qc)
		lexer_readchar(lexer);
	else
	{
		free_safe(msh, (void **)&word);
		return (NULL);
	}
	return (word);
}
