2020-05-24 21:30:55 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef CTYPE_H
|
|
|
|
#define CTYPE_H
|
2022-02-19 16:17:40 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
2020-05-24 21:30:55 +01:00
|
|
|
* Provides a subset of the functions normally provided by <ctype.h>.
|
|
|
|
*
|
2022-02-19 19:56:55 +00:00
|
|
|
*//*
|
2022-02-19 16:17:40 +00:00
|
|
|
* Copyright (C) 2020-2022 Martin Whitaker.
|
2020-05-24 21:30:55 +01:00
|
|
|
*/
|
|
|
|
|
2022-02-19 16:17:40 +00:00
|
|
|
/**
|
2020-05-24 21:30:55 +01:00
|
|
|
* If c is a lower-case letter, returns its upper-case equivalent, otherwise
|
|
|
|
* returns c. Assumes c is an ASCII character.
|
|
|
|
*/
|
2022-05-17 16:54:28 +02:00
|
|
|
static inline int toupper(int c)
|
|
|
|
{
|
|
|
|
if (c >= 'a' && c <= 'z') {
|
|
|
|
return c + 'A' -'a';
|
|
|
|
} else {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 21:30:55 +01:00
|
|
|
|
2022-02-19 16:17:40 +00:00
|
|
|
/**
|
2020-05-24 21:30:55 +01:00
|
|
|
* Returns 1 if c is a decimal digit, otherwise returns 0. Assumes c is an
|
|
|
|
* ASCII character.
|
|
|
|
*/
|
2022-05-17 16:54:28 +02:00
|
|
|
static inline int isdigit(int c)
|
|
|
|
{
|
|
|
|
return c >= '0' && c <= '9';
|
|
|
|
}
|
2020-05-24 21:30:55 +01:00
|
|
|
|
2022-02-19 16:17:40 +00:00
|
|
|
/**
|
2020-05-24 21:30:55 +01:00
|
|
|
* Returns 1 if c is a hexadecimal digit, otherwise returns 0. Assumes c is an
|
|
|
|
* ASCII character.
|
|
|
|
*/
|
2022-05-17 16:54:28 +02:00
|
|
|
static inline int isxdigit(int c)
|
|
|
|
{
|
|
|
|
return isdigit(c) || (toupper(c) >= 'A' && toupper(c) <= 'F');
|
|
|
|
}
|
2020-05-24 21:30:55 +01:00
|
|
|
|
|
|
|
#endif // CTYPE_H
|