예제 #1
0
파일: ft_strtrim.c 프로젝트: sessaidi/ft_p
char			*ft_strtrim(char const *s)
{
	int		pos_e;
	t_bool	pos_t;
	size_t	pos_s;
	char	*v_str;

	pos_e = 0;
	pos_s = 0;
	pos_t = FALSE;
	v_str = ft_strnew(ft_strlen(s));
	while (pos_s < ft_strlen(s))
	{
		if (!pos_t && ft_iswhite(s[pos_s]))
			pos_s++;
		else
		{
			pos_t = TRUE;
			v_str[pos_e++] = s[pos_s++];
		}
	}
	while (ft_iswhite(v_str[--pos_e]))
		v_str[pos_e] = '\0';
	return (v_str);
}
예제 #2
0
파일: parse.c 프로젝트: rbernand/Corewar
enum e_parse_state		get_state(const char *line)
{
	if (ft_strnequ(line, NAME_CMD_STRING, NAME_CMD_LEN)
			&& ft_iswhite(line[NAME_CMD_LEN]))
		return (_PARSE_NAME);
	else if (ft_strnequ(line, COMMENT_CMD_STRING, COMMENT_CMD_LEN)
			&& ft_iswhite(line[COMMENT_CMD_LEN]))
		return (_PARSE_COMMENT);
	else if (is_labelled(line))
		return (_PARSE_LABEL);
	else
		return (_PARSE_INSTRUCTION);
	return (_PARSE_ERROR);
}
예제 #3
0
char		*ft_strtrim(char const *s)
{
	size_t		i;
	size_t		start;
	size_t		end;
	char		*dest;

	if (s == NULL)
		return (NULL);
	i = 0;
	while (ft_iswhite(s[i]) && s[i])
		i++;
	start = i;
	end = ft_end((char *)s, start);
	dest = (char *)malloc(sizeof(char));
	if (start != end || (start == end && start != (size_t)ft_strlen(s)))
	{
		if (!(dest == (char *)malloc((end - start + 2) * sizeof(char))))
			return (NULL);
		ft_strncpy(dest, s + start, end - start + 1);
		dest[end - start + 1] = 0;
	}
	else if (start == end && start == (size_t)ft_strlen(s))
		*dest = '\0';
	return (dest);
}
예제 #4
0
파일: ft_strtrim.c 프로젝트: Sleli42/fdf
static size_t	count_spaces(char const *s)
{
	size_t	i;

	i = 0;
	while (ft_iswhite(s[i]))
		i++;
	return (i);
}
예제 #5
0
파일: ft_strtrim.c 프로젝트: Sleli42/fdf
static size_t	count_spaces_return(char const *s, size_t len)
{
	if (len)
	{
		len--;
		while (ft_iswhite(s[len]) && len > 0)
			len--;
	}
	return (len);
}
예제 #6
0
char	*ft_ctos(char c)
{
	char	*s;

	if ((s = malloc(2)) == NULL)
		return (NULL);
	s[0] = c >= 0 && c < 31 && !ft_iswhite(c) ? 0 : c;
	s[1] = '\0';
	return (s);
}
예제 #7
0
size_t		ft_end(char *s, size_t i)
{
	size_t		end;

	end = i;
	while (s[i])
	{
		if (!ft_iswhite(s[i]))
			end = i;
		i++;
	}
	return (end);
}
예제 #8
0
static int		is_empty(char *s)
{
	int		i;

	i = 0;
	while (s[i])
	{
		if (ft_iswhite(s[i]))
			return (1);
		++i;
	}
	return (0);
}
예제 #9
0
파일: parse.c 프로젝트: rbernand/Corewar
static t_bool			is_labelled(const char *line)
{
	size_t				i;

	i = 0;
	while (line[i] && !ft_iswhite(line[i]))
	{
		if (i >= 1 && line[i] == LABEL_CHAR)
			return (_TRUE);
		if (ft_strchr(LABEL_CHARS, line[i]) == NULL)
			return (_FALSE);
		i++;
	}
	return (_FALSE);
}
예제 #10
0
파일: ft_atod.c 프로젝트: Julow/Arkanoid
double			ft_atod(const char *str)
{
	double			nb;
	double			part;
	double			sign;

	while (ft_iswhite(*str))
		str++;
	sign = (*str == '-') ? -1.0 : 1.0;
	str = (*str == '-' || *str == '+') ? str + 1 : str;
	nb = 0.0;
	while (*str >= '0' && *str <= '9')
		nb = nb * 10 + (*(str++) - '0');
	if (*str == '.' || *str == ',')
	{
		while (*(++str) >= '0' && *str <= '9')
			part = 0.0;
		while (*(--str) >= '0' && *str <= '9')
			part = (part + (*str - '0')) / 10.0;
		nb += part;
	}
	return (nb * sign);
}