コード例 #1
0
ファイル: ft_strtrim.c プロジェクト: lambda2/zsh-backup
char	*ft_strtrim(char const *s)
{
	int				d;
	int				trim_start;
	unsigned int	c;
	char			*new_str;

	d = 0;
	c = 0;
	trim_start = 0;
	new_str = ft_strnew (ft_strlen (s));
	while (c < ft_strlen (s))
	{
		if (!trim_start && ft_isblank (s[c]))
			c++;
		else
		{
			trim_start = 1;
			new_str[d++] = s[c++];
		}
	}
	while (ft_isblank (new_str[--d]))
		new_str[d] = '\0';
	return (new_str);
}
コード例 #2
0
ファイル: ft_strsplit_blank.c プロジェクト: arlemi/minishell
static int			count_words(char *s)
{
	int		words;

	while (*s && ft_isblank(*s) == 1)
		++s;
	words = (*s) ? 1 : 0;
	while (*s)
	{
		if (ft_isblank(*s) == 1 && s[1] && ft_isblank(s[1]) == 0)
			++words;
		++s;
	}
	return (words);
}
コード例 #3
0
ファイル: ft_strtrim.c プロジェクト: Draguld/libft
char		*ft_strtrim(char const *s)
{
	int		begbl;
	int		endbl;
	char	*trim;
	size_t	i;

	i = 0;
	while (ft_isblank(s[i]) == 1)
	{
		i++;
		if (i == ft_strlen(s))
			return ("");
	}
	begbl = ft_beginblank((char *)s);
	endbl = ft_endblank((char *)s);
	trim = (char *)malloc((ft_strlen(s) + 1) - (begbl + endbl) * sizeof(*trim));
	if (trim == NULL)
		return (NULL);
	i = 0;
	while (i < ft_strlen(s) - (begbl + endbl))
	{
		trim[i] = s[i + begbl];
		i++;
	}
	trim[i] = '\0';
	return (trim);
}
コード例 #4
0
ファイル: ft_atoi.c プロジェクト: qstemper/42
int	ft_atoi(const char *str)
{
    int		res;
    int		i;
    int		c;

    res = 0;
    i = 0;
    c = 0;
    while (ft_isblank(str[i]))
        i++;
    if (str[i] == '+')
        i++;
    else if (str[i] == '-')
    {
        c = 1;
        i++;
    }
    while (str[i] != '\0' && ft_isdigit(str[i]))
    {
        res = res * 10 + str[i] - '0';
        i++;
    }
    if (c == 1)
        return (-res);
    return (res);
}
コード例 #5
0
ファイル: ft_atoi.c プロジェクト: bbouabou/ft_ls
int	ft_atoi(const char *c)
{
	int	result;
	int	i;

	i = 0;
	result = 0;
	while (ft_isblank(*c))
		c++;
	if (ft_isdigit(c[0]) == 0 && c[0] != '-' && c[0] != '+')
		return (0);
	if ((c[0] == '-' || c[0] == '+') && ft_isdigit(c[1]) == 0)
		return (0);
	if (c[0] == '-' || c[0] == '+')
		i = 1;
	while (c[i] != '\0' && ft_isdigit(c[i]) == 1)
	{
		if (ft_isdigit(c[i]) == 1)
			result = result * 10 + c[i] - '0';
		i++;
	}
	if (c[0] == '-' && ft_isdigit(c[1]) == 1)
		result = result * -1;
	return (result);
}
コード例 #6
0
ファイル: ft_isblank_test.c プロジェクト: ale-roy/libftasm
static void	test_3(void)
{
	printf("\ttest 3: ft_isblank(128): ");
	if (ft_isblank(128) == isblank(128))
		puts(SUCCESS);
	else
		puts(ERROR);
}
コード例 #7
0
ファイル: ft_isblank_test.c プロジェクト: ale-roy/libftasm
static void	test_1(void)
{
	printf("\ttest 1: ft_isblank(-1): ");
	if (ft_isblank(-1) == isblank(-1))
		puts(SUCCESS);
	else
		puts(ERROR);
}
コード例 #8
0
ファイル: misc_read.c プロジェクト: JulienBalestra/21sh
int		is_only_spaces(char *buf)
{
	size_t i;
	size_t len;

	i = 0;
	len = ft_strlen(buf);
	if (len == 1 && !ft_isblank(buf[i]))
		return (1);
	while (i < len - 1)
	{
		if (ft_isblank(buf[i]))
			i++;
		else
			return (0);
	}
	return (1);
}
コード例 #9
0
ファイル: ft_arg.c プロジェクト: Ngoguey42/proj01_algo_libft
static int			is_digit(char const *str)
{
	while (ft_isblank(*str))
		str++;
	if (*str == '+' || *str == '-')
		str++;
	while (ft_isdigit(*str))
		str++;
	return (*str == '\0');
}
コード例 #10
0
ファイル: ft_strtrim.c プロジェクト: eleonorev/PushSwap
char			*ft_strtrim(char const *s)
{
	int			i;
	int			j;
	char		*strim;

	i = 0;
	if (!s)
		return (NULL);
	j = ft_strlen(s) - 1;
	while (ft_isblank(s[i]) && s[i] != '\0')
		i++;
	while (j > -1 && ft_isblank(s[j]))
		j--;
	if (j < 0)
		return (ft_strdup(""));
	strim = ft_strsub(s, i, (j + 1 - i));
	return (strim);
}
コード例 #11
0
ファイル: ft_strtrim.c プロジェクト: wburgos/wolf3d
char		*ft_strtrim(char const *s)
{
	const char	*start;
	const char	*end;
	char		*str;
	size_t		len;

	start = s;
	end = s + ft_strlen(s) - 1;
	while (*start && ft_isblank(*start))
		start++;
	if (!*start)
		return (ft_strnew(0));
	while (ft_isblank(*end) && end > s)
		end--;
	len = end - start + 1;
	str = ft_strnew(len);
	str = ft_strncpy(str, start, len);
	return (str);
}
コード例 #12
0
ファイル: ft_sh.c プロジェクト: sbenning42/42
static int	empty_buffer(\
			char *buffer)
{
	while (*buffer)
	{
		if (!ft_isblank(*buffer))
			return (0);
		buffer++;
	}
	return (1);
}
コード例 #13
0
ファイル: ft_strtrim.c プロジェクト: Bric3d/42-FdF
char	*ft_strtrim(char const *s)
{
	size_t	a;
	size_t	b;
	char	*s2;

	a = 0;
	b = 0;
	if (!s)
		return (NULL);
	s2 = (char *)ft_memalloc(sizeof(char) * strlen(s) + 1);
	if (s2 == NULL)
		return (NULL);
	while (ft_isblank(s[a]) == 1)
		a++;
	while (s[a])
		s2[b++] = s[a++];
	while (ft_isblank(s2[--b]) == 1)
		s2[b] = '\0';
	return (s2);
}
コード例 #14
0
ファイル: ft_strtrim.c プロジェクト: Draguld/libft
static int	ft_beginblank(char *str)
{
	int	begblank;

	begblank = 0;
	while (ft_isblank(*str) == 1)
	{
		begblank++;
		str++;
	}
	str = str - begblank;
	return (begblank);
}
コード例 #15
0
ファイル: ft_vcmd.c プロジェクト: amoriarty/ft_sh1
t_bool							ft_vcmd(char *cmd)
{
	int								i;

	i = -1;
	while (cmd[++i])
	{
		if (!ft_isprint(cmd[i]) && !ft_isblank(cmd[i]))
		{
			ft_sherror("Invalid command", NULL, FALSE);
			return (FAILURE);
		}
	}
	return (SUCCESS);
}
コード例 #16
0
ファイル: read.c プロジェクト: arlemi/minishell
static void	fill_av(t_av *av, char *str)
{
	int		j;
	int		k;

	j = 0;
	ft_bzero(av,sizeof(t_av));
	while (ft_isblank(str[j]) == 1 && str[j] != '\0')
		j++;
	k = j;
	while (ft_isspace(str[k]) == 0 && str[k] != '\0')
		k++;
	av->cmd = ft_strsub(str, j, k - j);
	av->arg = ft_strsplit_blank(str + k);
	k = -1;
	while (av->arg != NULL && av->arg[++k] != NULL)
		av->argc++;
}
コード例 #17
0
ファイル: ft_isblank_test.c プロジェクト: ale-roy/libftasm
static void	test_2(void)
{
	int	i;

	printf("\ttest 2: ft_isblank([0-127]): ");
	i = 0;
	while (i < 128)
	{
		if (ft_isblank(i) != isblank(i))
		{
			puts(ERROR);
			break ;
		}
		i++;
	}
	if (i == 128)
		puts(SUCCESS);
}
コード例 #18
0
ファイル: ft_atol.c プロジェクト: wolfnether/LibFt
long	ft_atol(const char *nptr)
{
	long	i;
	int		neg;

	i = 0;
	neg = 1;
	while (ft_isblank(*nptr))
		nptr++;
	if (*nptr == '-' || *nptr == '+')
		neg = *nptr++ == '-' ? -1 : 1;
	while (ft_isdigit(*nptr))
	{
		i *= 10;
		i += *nptr++ - '0';
	}
	return (i * neg);
}
コード例 #19
0
ファイル: ft_strtrim.c プロジェクト: Draguld/libft
static int	ft_endblank(char *str)
{
	int	endblank;

	endblank = 0;
	while (*str != '\0')
	{
		str++;
	}
	str--;
	while (ft_isblank(*str) == 1)
	{
		endblank++;
		str--;
	}
	str = str + endblank - ft_strlen(str);
	return (endblank);
}
コード例 #20
0
ファイル: ft_isspace.c プロジェクト: AGBubble/libft
int		ft_isspace(int c)
{
	return (ft_isblank(c) || c == '\r' || c == '\v' || c == '\f');
}
コード例 #21
0
ファイル: ft_strtrim.c プロジェクト: agadiffe/libft
static int	ft_isblank_nl(int c)
{
	return (ft_isblank(c) || (c == '\n'));
}
コード例 #22
0
ファイル: ft_iswhitespace.c プロジェクト: Thog/fractol
int		ft_iswhitespace(int c)
{
	if (c == '\n' || ft_isblank(c))
		return (1);
	return (0);
}
コード例 #23
0
ファイル: ft_isblank2.c プロジェクト: zisson/filler_v2
int	ft_isblank2(int c)
{
	if (ft_isblank(c) || c == '\n')
		return (1);
	return (0);
}
コード例 #24
0
ファイル: ft_strtrim.c プロジェクト: sessaidi/ft_p
static t_bool	ft_iswhite(char c)
{
	return ((ft_isblank(c) || c == '\n') ? TRUE : FALSE);
}