40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* ************************************************************************** */
 | |
| /*                                                                            */
 | |
| /*                                                        :::      ::::::::   */
 | |
| /*   ft_is_in_quote.c                                   :+:      :+:    :+:   */
 | |
| /*                                                    +:+ +:+         +:+     */
 | |
| /*   By: cchauvet <cchauvet@student.42angoulem      +#+  +:+       +#+        */
 | |
| /*                                                +#+#+#+#+#+   +#+           */
 | |
| /*   Created: 2023/02/21 12:59:34 by cchauvet          #+#    #+#             */
 | |
| /*   Updated: 2023/02/21 23:08:10 by cchauvet         ###   ########.fr       */
 | |
| /*                                                                            */
 | |
| /* ************************************************************************** */
 | |
| 
 | |
| #include "utils.h"
 | |
| 
 | |
| int	ft_is_in_quote(const char *str, size_t n)
 | |
| {
 | |
| 	size_t	double_quoted;
 | |
| 	size_t	simple_quoted;
 | |
| 	size_t	i;
 | |
| 
 | |
| 	double_quoted = 0;
 | |
| 	simple_quoted = 0;
 | |
| 	i = 0;
 | |
| 	while (str[i] != '\0' && i < n)
 | |
| 	{
 | |
| 		if (str[i] == '"')
 | |
| 		{
 | |
| 			if (simple_quoted == 0)
 | |
| 				double_quoted = !double_quoted;
 | |
| 		}
 | |
| 		else if (str[i] == '\'')
 | |
| 		{
 | |
| 			if (double_quoted == 0)
 | |
| 				simple_quoted = !simple_quoted;
 | |
| 		}
 | |
| 		i++;
 | |
| 	}
 | |
| 	return (simple_quoted + double_quoted * 2);
 | |
| }
 |