libc: Add ctype.h
This commit is contained in:
parent
91d76a2ee4
commit
eb67ab113e
58
libs/libc/include/ctype.h
Normal file
58
libs/libc/include/ctype.h
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef _CTYPE_H
|
||||
#define _CTYPE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Is this character alphanumeric? */
|
||||
int isalnum(int c);
|
||||
|
||||
/* Is this character a letter? */
|
||||
int isalpha(int c);
|
||||
|
||||
/* Is this character part of ASCII? */
|
||||
int isascii(int c);
|
||||
|
||||
/* Is this character a blank character (space or tab)? */
|
||||
int isblank(int c);
|
||||
|
||||
/* Is this character a control character? */
|
||||
int iscntrl(int c);
|
||||
|
||||
/* Is this character a digit? */
|
||||
int isdigit(int c);
|
||||
|
||||
/* Is this character any printable character except space? */
|
||||
int isgraph(int c);
|
||||
|
||||
/* Is this character a lowercase letter? */
|
||||
int islower(int c);
|
||||
|
||||
/* Is this character any printable character (including space)? */
|
||||
int isprint(int c);
|
||||
|
||||
/* Is this character any printable character which is not a space or an alphanumeric character? */
|
||||
int ispunct(int c);
|
||||
|
||||
/* Is this character any space character (space, form feed, newline, carriage return, tab, vertical tab)? */
|
||||
int isspace(int c);
|
||||
|
||||
/* Is this character an uppercase letter? */
|
||||
int isupper(int c);
|
||||
|
||||
/* Is this character a hexadecimal digit (0-9, a-f, A-F)? */
|
||||
int isxdigit(int c);
|
||||
|
||||
/* Returns the lowercase form of the specified character. */
|
||||
int tolower(int c);
|
||||
|
||||
/* Returns the uppercase form of the specified character. */
|
||||
int toupper(int c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
81
libs/libc/src/ctype.cpp
Normal file
81
libs/libc/src/ctype.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <ctype.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int isalnum(int c)
|
||||
{
|
||||
return isalpha(c) || isdigit(c);
|
||||
}
|
||||
|
||||
int isalpha(int c)
|
||||
{
|
||||
return islower(c) || isupper(c);
|
||||
}
|
||||
|
||||
int isascii(int c)
|
||||
{
|
||||
return !(c & ~0x7f);
|
||||
}
|
||||
|
||||
int isblank(int c)
|
||||
{
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
||||
int iscntrl(int c)
|
||||
{
|
||||
return (unsigned int)c < 0x20 || c == 0x7f;
|
||||
}
|
||||
|
||||
int isdigit(int c)
|
||||
{
|
||||
return c >= '0' && c < ':';
|
||||
}
|
||||
|
||||
int isgraph(int c)
|
||||
{
|
||||
return (unsigned int)c - 0x21 < 0x5e;
|
||||
}
|
||||
|
||||
int islower(int c)
|
||||
{
|
||||
return c >= 'a' && c < '{';
|
||||
}
|
||||
|
||||
int isprint(int c)
|
||||
{
|
||||
return (unsigned int)c - 0x20 < 0x5f;
|
||||
}
|
||||
|
||||
int ispunct(int c)
|
||||
{
|
||||
return isgraph(c) && !isalnum(c);
|
||||
}
|
||||
|
||||
int isspace(int c)
|
||||
{
|
||||
return c == ' ' || (unsigned int)c - '\t' < 5;
|
||||
}
|
||||
|
||||
int isupper(int c)
|
||||
{
|
||||
return c >= 'A' && c < '[';
|
||||
}
|
||||
|
||||
int isxdigit(int c)
|
||||
{
|
||||
return isdigit(c) || ((unsigned int)c | 32) - 'a' < 6;
|
||||
}
|
||||
|
||||
int tolower(int c)
|
||||
{
|
||||
if (isupper(c)) return c | 32;
|
||||
return c;
|
||||
}
|
||||
|
||||
int toupper(int c)
|
||||
{
|
||||
if (islower(c)) return c & 0x5f;
|
||||
return c;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user