metalsvm/include/metalsvm/ctype.h
Stefan Lankes 1d8810aa91 add rudimental support of basic C functions
- isacii
- islower
- isupper
- toascii
- isspace
- isdigit
- tolower
- toupper
- strtol
- atoi
2011-03-24 11:01:59 +01:00

107 lines
1.9 KiB
C

/****************************************************************************************
*
* Author: Stefan Lankes
* Chair for Operating Systems, RWTH Aachen University
* Date: 24/03/2011
*
****************************************************************************************
*
* Written by the Chair for Operating Systems, RWTH Aachen University
*
* NO Copyright (C) 2010, Stefan Lankes,
* consider these trivial functions to be public domain.
*
* These functions are distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
#ifndef __CTYPE_H_
#define __CYTPE_H_
static inline int isascii(int c)
{
return (((unsigned char)(c))<=0x7f);
}
static inline int toascii(c)
{
return (((unsigned char)(c))&0x7f);
}
static inline int isspace(int c)
{
if (!isascii(c))
return 0;
if (' ' == (unsigned char) c)
return 1;
if ('\n' == (unsigned char) c)
return 1;
if ('\r' == (unsigned char) c)
return 1;
if ('\t' == (unsigned char) c)
return 1;
if ('\v' == (unsigned char) c)
return 1;
if ('\f' == (unsigned char) c)
return 1;
return 0;
}
static inline int isdigit(int c)
{
if (!isascii(c))
return 0;
if (((unsigned char) c >= '0') && ((unsigned char) c <= '9'))
return 1;
return 0;
}
static inline int islower(int c)
{
if (!isascii(c))
return 0;
if (((unsigned char) c >= 'a') && ((unsigned char) c <= 'z'))
return 1;
return 0;
}
static inline int isupper(int c)
{
if (!isascii(c))
return 0;
if (((unsigned char) c >= 'A') && ((unsigned char) c <= 'Z'))
return 1;
return 0;
}
static inline int isalpha(int c)
{
if (isupper(c) || islower(c))
return 1;
return 0;
}
static inline unsigned char tolower(unsigned char c)
{
if (isupper(c))
c -= 'A'-'a';
return c;
}
static inline unsigned char toupper(unsigned char c)
{
if (islower(c))
c -= 'a'-'A';
return c;
}
#endif