Whitespace disallowed

This commit is contained in:
Timo Schmidt 2023-03-31 22:06:11 +02:00
parent 1d032f7b5e
commit 80d8285fe5
2 changed files with 25 additions and 7 deletions

View File

@ -6,13 +6,23 @@
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */ /* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/30 22:50:52 by tosuman #+# #+# */ /* Created: 2023/03/30 22:50:52 by tosuman #+# #+# */
/* Updated: 2023/03/30 22:50:53 by tosuman ### ########.fr */ /* Updated: 2023/03/31 22:05:08 by tischmid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
int ft_isspace(char c)
{
return (c == ' '
|| c == '\t'
|| c == '\n'
|| c == '\r'
|| c == '\f'
|| c == '\v');
}
unsigned int char_count(const char *str, char c) unsigned int char_count(const char *str, char c)
{ {
unsigned int count; unsigned int count;
@ -35,7 +45,7 @@ unsigned int is_valid_base(const char *base)
size = 0; size = 0;
while (*base) while (*base)
{ {
if (*base == '+' || *base == '-') if (*base == '+' || *base == '-' || ft_isspace(*base))
return (0); return (0);
if (char_count(base, *base) > 1) if (char_count(base, *base) > 1)
return (0); return (0);

View File

@ -6,10 +6,20 @@
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */ /* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/30 22:47:43 by tosuman #+# #+# */ /* Created: 2023/03/30 22:47:43 by tosuman #+# #+# */
/* Updated: 2023/03/30 22:47:43 by tosuman ### ########.fr */ /* Updated: 2023/03/31 22:05:31 by tischmid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
int ft_isspace(char c)
{
return (c == ' '
|| c == '\t'
|| c == '\n'
|| c == '\r'
|| c == '\f'
|| c == '\v');
}
unsigned int char_count(const char *str, char c) unsigned int char_count(const char *str, char c)
{ {
unsigned int count; unsigned int count;
@ -32,7 +42,7 @@ unsigned int is_valid_base(const char *base)
size = 0; size = 0;
while (*base) while (*base)
{ {
if (*base == '+' || *base == '-' || *base == ' ') if (*base == '+' || *base == '-' || ft_isspace(*base))
return (0); return (0);
if (char_count(base, *base) > 1) if (char_count(base, *base) > 1)
return (0); return (0);
@ -70,9 +80,7 @@ int ft_atoi_base(char *str, char *base)
base_len = is_valid_base(base); base_len = is_valid_base(base);
if (!base_len) if (!base_len)
return (0); return (0);
while (*str == ' ' || *str == '\t' while (ft_isspace(*str))
|| *str == '\n' || *str == '\r'
|| *str == '\f' || *str == '\v')
++str; ++str;
while (*str == '+' || *str == '-') while (*str == '+' || *str == '-')
if (*str++ == '-') if (*str++ == '-')