text: /* ************************************************************************** */
  /*                                                                            */
  /*                                                        :::      ::::::::   */
  /*   ft_strtrim.c                                       :+:      :+:    :+:   */
  /*                                                    +:+ +:+         +:+     */
  /*   By: dvdovenk <marvin@42.fr>                    +#+  +:+       +#+        */
  /*                                                +#+#+#+#+#+   +#+           */
  /*   Created: 2016/11/27 18:09:18 by dvdovenk          #+#    #+#             */
  /*   Updated: 2016/12/01 12:30:24 by dvdovenk         ###   ########.fr       */
  /*                                                                            */
  /* ************************************************************************** */
  
  #include "../includes/libft.h"
  
  char	*ft_strtrim(char const *s)
  {
  	int		i;
  	int		len;
  	char	*str;
  
  	if (!s)
  		return (NULL);
  	len = ft_strlen(s);
  	while (s[len - 1] == ' ' || s[len - 1] == '\t' || s[len - 1] == '\n')
  		len--;
  	i = -1;
  	while (s[++i] == ' ' || s[i] == '\t' || s[i] == '\n')
  		len--;
  	if (len <= 0)
  		len = 0;
  	if (!(str = (char*)malloc(sizeof(char) * (len + 1))))
  		return (NULL);
  	s += i;
  	i = -1;
  	while (++i < len)
  		str[i] = *s++;
  	str[i] = '\0';
  	return (str);
  }
  