mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Added isalnum(3), isalpha(3), isblank(3), iscntrl(3), isdigit(3),
isgraph(3), islower(3), isprint(3), ispunct(3), isspace(3), isupper(3), isxdigit(3), tolower(3), and toupper(3).
This commit is contained in:
parent
ad200ffa91
commit
954fd11703
3 changed files with 158 additions and 0 deletions
|
@ -29,11 +29,13 @@ ASFLAGS=$(CPUASFLAGS)
|
|||
NASMFLAGS=$(CPUNASMFLAGS)
|
||||
|
||||
COBJS=\
|
||||
c/ctype.o \
|
||||
c/file.o \
|
||||
c/fdio.o \
|
||||
c/stdio.o \
|
||||
|
||||
CHEADERS=\
|
||||
c/h/ctype.h \
|
||||
c/h/unistd.h \
|
||||
c/h/stdlib.h \
|
||||
c/h/wchar.h \
|
||||
|
|
103
libmaxsi/c/ctype.c
Normal file
103
libmaxsi/c/ctype.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
ctype.c
|
||||
Character types.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
// TODO: Support other locales than ASCII.
|
||||
|
||||
int isalnum(int c)
|
||||
{
|
||||
return isalpha(c) || isdigit(c);
|
||||
}
|
||||
|
||||
int isalpha(int c)
|
||||
{
|
||||
return isupper(c) || islower(c);
|
||||
}
|
||||
|
||||
int isblank(int c)
|
||||
{
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
||||
int iscntrl(int c)
|
||||
{
|
||||
return 0 <= c && c < 32;
|
||||
}
|
||||
|
||||
int isdigit(int c)
|
||||
{
|
||||
return '0' <= c && c <= '9';
|
||||
}
|
||||
|
||||
int isgraph(int c)
|
||||
{
|
||||
return '!' <= c && c <= '~';
|
||||
}
|
||||
|
||||
int islower(int c)
|
||||
{
|
||||
return 'a' <= c && c <= 'z';
|
||||
}
|
||||
|
||||
int isprint(int c)
|
||||
{
|
||||
return isgraph(c) || c == ' ';
|
||||
}
|
||||
|
||||
int ispunct(int c)
|
||||
{
|
||||
return isprint(c) && c != ' ' && !isalnum(c);
|
||||
}
|
||||
|
||||
int isspace(int c)
|
||||
{
|
||||
return c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' ';
|
||||
}
|
||||
|
||||
int isupper(int c)
|
||||
{
|
||||
return 'A' <= c && c <= 'Z';
|
||||
}
|
||||
|
||||
int isxdigit(int c)
|
||||
{
|
||||
if ( isdigit(c) ) { return 1; }
|
||||
if ( 'a' <= c && c <= 'f' ) { return 1; }
|
||||
if ( 'A' <= c && c <= 'F' ) { return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tolower(int c)
|
||||
{
|
||||
if ( 'A' <= c && c <= 'Z' ) { return 'a' + c - 'A'; }
|
||||
return c;
|
||||
}
|
||||
|
||||
int toupper(int c)
|
||||
{
|
||||
if ( 'a' <= c && c <= 'z' ) { return 'A' + c - 'a'; }
|
||||
return c;
|
||||
}
|
||||
|
53
libmaxsi/c/hsrc/ctype.h
Normal file
53
libmaxsi/c/hsrc/ctype.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
ctype.h
|
||||
Character types.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/* TODO: POSIX-1.2008 compliance is only partial */
|
||||
|
||||
#ifndef _CTYPE_H
|
||||
#define _CTYPE_H 1
|
||||
|
||||
#include <features.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/* TODO: Declare locale_t and the *_t functions here */
|
||||
int isalnum(int c);
|
||||
int isalpha(int c);
|
||||
int isblank(int c);
|
||||
int iscntrl(int c);
|
||||
int isdigit(int c);
|
||||
int isgraph(int c);
|
||||
int islower(int c);
|
||||
int isprint(int c);
|
||||
int ispunct(int c);
|
||||
int isspace(int c);
|
||||
int isupper(int c);
|
||||
int isxdigit(int c);
|
||||
int tolower(int c);
|
||||
int toupper(int c);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Reference in a new issue