2012-09-28 22:36:46 +00: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).
2012-01-08 14:35:35 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
This file is part of the Sortix C Library.
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
The Sortix C Library 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.
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
The Sortix C Library 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.
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
ctype/ctype.cpp
|
2013-07-10 13:26:01 +00:00
|
|
|
Character types.
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
|
2012-09-28 22:36:46 +00: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).
2012-01-08 14:35:35 +00:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
// TODO: Support other locales than ASCII.
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isalnum(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return isalpha(c) || isdigit(c);
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isalpha(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return isupper(c) || islower(c);
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isblank(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return c == ' ' || c == '\t';
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int iscntrl(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return 0 <= c && c < 32;
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isdigit(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return '0' <= c && c <= '9';
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isgraph(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return '!' <= c && c <= '~';
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int islower(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return 'a' <= c && c <= 'z';
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isprint(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return isgraph(c) || c == ' ';
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int ispunct(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return isprint(c) && c != ' ' && !isalnum(c);
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isspace(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
2013-07-11 16:19:41 +00:00
|
|
|
return c == '\t' || c == '\n' || c == '\v' ||
|
|
|
|
c == '\f' || c == '\r' || c == ' ';
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isupper(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
|
|
|
return 'A' <= c && c <= 'Z';
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int isxdigit(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
2013-07-11 16:19:41 +00:00
|
|
|
if ( isdigit(c) )
|
|
|
|
return 1;
|
|
|
|
if ( 'a' <= c && c <= 'f' ) return 1;
|
|
|
|
if ( 'A' <= c && c <= 'F' ) return 1;
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int tolower(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
2013-07-11 16:19:41 +00:00
|
|
|
if ( 'A' <= c && c <= 'Z' )
|
|
|
|
return 'a' + c - 'A';
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:19:41 +00:00
|
|
|
extern "C" int toupper(int c)
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
{
|
2013-07-11 16:19:41 +00:00
|
|
|
if ( 'a' <= c && c <= 'z' )
|
|
|
|
return 'A' + c - 'a';
|
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).
2012-01-08 14:35:35 +00:00
|
|
|
return c;
|
|
|
|
}
|