UteroOS / utero-archive

The Operating System (for x86_64) written in Crystal as much as possible

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementing ctype functions

noriyotcp opened this issue · comments

Implementing ctype functions

A. from musl-1.1.15/include/ctype.h

int   isalnum(int);
int   isalpha(int);
int   isblank(int);
int   iscntrl(int);
int   isdigit(int);
int   isgraph(int);
int   islower(int);
int   isprint(int);
int   ispunct(int);
int   isspace(int);
int   isupper(int);
int   isxdigit(int);
int   tolower(int);
int   toupper(int);

B. from pdclib-*/includes/ctype.h

/* Character classification functions */

/* Note that there is a difference between "whitespace" (any printing, non-
   graph character, like horizontal and vertical tab), and "blank" (the literal
   ' ' space character).

   There will be masking macros for each of these later on, but right now I
   focus on the functions only.
*/

/* Returns isalpha( c ) || isdigit( c ) */
int isalnum( int c ) _PDCLIB_nothrow;

/* Returns isupper( c ) || islower( c ) in the "C" locale.
   In any other locale, also returns true for a locale-specific set of
   alphabetic characters which are neither control characters, digits,
   punctation, or whitespace.
*/
int isalpha( int c ) _PDCLIB_nothrow;

/* Returns true if the character isspace() and used for seperating words within
   a line of text. In the "C" locale, only ' ' and '\t' are considered blanks.
*/
int isblank( int c ) _PDCLIB_nothrow;

/* Returns true if the character is a control character. */
int iscntrl( int c ) _PDCLIB_nothrow;

/* Returns true if the character is a decimal digit. Locale-independent. */
int isdigit( int c ) _PDCLIB_nothrow;

/* Returns true for every printing character except space (' '). */
int isgraph( int c ) _PDCLIB_nothrow;

/* Returns true for lowercase letters in the "C" locale.
   In any other locale, also returns true for a locale-specific set of
   characters which are neither control characters, digits, punctation, or
   space (' '). In a locale other than the "C" locale, a character might test
   true for both islower() and isupper().
*/
int islower( int c ) _PDCLIB_nothrow;

/* Returns true for every printing character including space (' '). */
int isprint( int c ) _PDCLIB_nothrow;

/* Returns true for every printing character that is neither whitespace
   nor alphanumeric in the "C" locale. In any other locale, there might be
   characters that are printing characters, but neither whitespace nor
   alphanumeric.
*/
int ispunct( int c ) _PDCLIB_nothrow;

/* Returns true for every standard whitespace character (' ', '\f', '\n', '\r',
   '\t', '\v') in the "C" locale. In any other locale, also returns true for a
   locale-specific set of characters for which isalnum() is false.
*/ 
int isspace( int c ) _PDCLIB_nothrow;

/* Returns true for uppercase letters in the "C" locale.
   In any other locale, also returns true for a locale-specific set of
   characters which are neither control characters, digits, punctation, or
   space (' '). In a locale other than the "C" locale, a character might test
   true for both islower() and isupper().
*/
int isupper( int c ) _PDCLIB_nothrow;

/* Returns true for any hexadecimal-digit character. Locale-independent. */
int isxdigit( int c ) _PDCLIB_nothrow;

/* Character case mapping functions */

/* Converts an uppercase letter to a corresponding lowercase letter. Input that
   is not an uppercase letter remains unchanged.
*/
int tolower( int c ) _PDCLIB_nothrow;

/* Converts a lowercase letter to a corresponding uppercase letter. Input that
   is not a lowercase letter remains unchanged.
*/
int toupper( int c ) _PDCLIB_nothrow;

C. from this book

(a file name is strutil.c, no header file, does not consider the localee?)

int isupper(char c);
int islower(char c);
int isalpha(char c);
int isspace(char c);
int isdigit(char c);
char *ltrim(char *s);
char *rtrim(char *s);
char *trim(char *s);

The easiest plan seems to be C. I gonna try this.

These \`trim\` functions are defined but never be used. Put them on hold.