Skip to content

Commit

Permalink
ctype: Make functions static inline, move to the header
Browse files Browse the repository at this point in the history
DONE: RTOS-549
  • Loading branch information
agkaminski committed Aug 8, 2023
1 parent 481eeeb commit 796dbff
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 132 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ all: $(PREFIX_A)libphoenix.a


include arch/$(TARGET_SUFF)/Makefile
include ctype/Makefile
include err/Makefile
include errno/Makefile
include locale/Makefile
Expand Down
7 changes: 0 additions & 7 deletions ctype/Makefile

This file was deleted.

100 changes: 0 additions & 100 deletions ctype/ctype.c

This file was deleted.

90 changes: 66 additions & 24 deletions include/ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* ctypes.h
*
* Copyright 2017 Phoenix Systems
* Author: Pawel Pisarczyk
* Copyright 2017, 2023 Phoenix Systems
* Author: Pawel Pisarczyk, Adrian Kepka, Aleksander Kaminski
*
* This file is part of Phoenix-RTOS.
*
Expand All @@ -22,65 +22,107 @@ extern "C" {
#endif


/* This function checks whether the passed character is alphanumeric. */
extern int isalnum(int c);
/* This function checks whether the passed character is lowercase letter. */
static inline int islower(int c)
{
return (c >= 'a' && c <= 'z') ? 1 : 0;
}


/* This function checks whether the passed character is an uppercase letter. */
static inline int isupper(int c)
{
return (c >= 'A' && c <= 'Z') ? 1 : 0;
}


/* This function checks whether the passed character is alphabetic. */
extern int isalpha(int c);
static inline int isalpha(int c)
{
return (islower(c) || isupper(c)) ? 1 : 0;
}


/* This function checks whether the passed character is control character. */
extern int iscntrl(int c);
static inline int iscntrl(int c)
{
return (((c >= 0x00) && (c <= 0x1f)) || c == 0x7f) ? 1 : 0;
}


/* This function checks whether the passed character is decimal digit. */
extern int isdigit(int c);
static inline int isdigit(int c)
{
return (c >= '0' && c <= '9') ? 1 : 0;
}


/* This function checks whether the passed character has graphical representation using locale. */
extern int isgraph(int c);
/* This function checks whether the passed character is alphanumeric. */
static inline int isalnum(int c)
{
return (isalpha(c) || isdigit(c)) ? 1 : 0;
}


/* This function checks whether the passed character is lowercase letter. */
extern int islower(int c);
/* This function checks whether the passed character is printable. */
static inline int isprint(int c)
{
return ((c > 0x1f) && (c < 0x7f)) ? 1 : 0;
}


/* This function checks whether the passed character is printable. */
extern int isprint(int c);
/* This function checks whether the passed character has graphical representation using locale. */
static inline int isgraph(int c)
{
return ((c != ' ') && (isprint(c) != 0)) ? 1 : 0;
}


/* This function checks whether the passed character is a punctuation character. */
extern int ispunct(int c);
static inline int ispunct(int c)
{
return ((isgraph(c) != 0) && (isalnum(c) == 0)) ? 1 : 0;
}


/* This function checks whether the passed character is white-space. */
extern int isspace(int c);


/* This function checks whether the passed character is an uppercase letter. */
extern int isupper(int c);
static inline int isspace(int c)
{
return (c == ' ' || c == '\f' || c == '\t' || c == '\n' || c == '\r' || c == '\v') ? 1 : 0;
}


/* This function checks whether the passed character is a hexadecimal digit. */
extern int isxdigit(int c);
static inline int isxdigit(int c)
{
return (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F'))) ? 1 : 0;
}


/* This function checks whether the passed character is a blank character. */
extern int isblank(int c);
static inline int isblank(int c)
{
return ((c == ' ') || (c == '\t')) ? 1 : 0;
}


/* This function converts uppercase letters to lowercase. */
extern int tolower(int c);
static inline int tolower(int c)
{
return (isupper(c) != 0) ? (c - 'A' + 'a') : c;
}


/* This function converts lowercase letters to uppercase. */
extern int toupper(int c);
static inline int toupper(int c)
{
return (islower(c) != 0) ? (c - 'a' + 'A') : c;
}


static inline int isascii(int c)
{
return (c & ~0x7f);
return ((c < 0) || (c > '\x7f')) ? 0 : 1;
}


Expand Down

0 comments on commit 796dbff

Please sign in to comment.