spingle/source/q_ctype.h

105 lines
2.2 KiB
C
Raw Permalink Normal View History

2019-11-24 20:45:15 -08:00
/* Locale insensitive ctype.h functions taken from the RPM library -
* RPM is Copyright (c) 1998 by Red Hat Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
2019-12-02 07:00:56 -08:00
#ifndef spingle__q_ctype_h
#define spingle__q_ctype_h
2019-11-24 20:45:15 -08:00
2019-11-25 16:49:58 -08:00
static inline int32_t q_isascii(int32_t c)
2019-11-24 20:45:15 -08:00
{
return ((c & ~0x7f) == 0);
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_islower(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (c >= 'a' && c <= 'z');
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isupper(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (c >= 'A' && c <= 'Z');
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isalpha(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (q_islower(c) || q_isupper(c));
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isdigit(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (c >= '0' && c <= '9');
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isxdigit(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (q_isdigit(c) || (c >= 'a' && c <= 'f') ||
2019-11-25 17:40:18 -08:00
(c >= 'A' && c <= 'F'));
2019-11-24 20:45:15 -08:00
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isalnum(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (q_isalpha(c) || q_isdigit(c));
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isblank(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (c == ' ' || c == '\t');
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isspace(int32_t c)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
switch(c)
{
case ' ':
case '\t':
case '\n':
case '\r':
case '\f':
case '\v':
return 1;
2019-11-24 20:45:15 -08:00
}
return 0;
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isgraph(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (c > 0x20 && c <= 0x7e);
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_isprint(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (c >= 0x20 && c <= 0x7e);
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_toascii(int32_t c)
2019-11-24 20:45:15 -08:00
{
return (c & 0x7f);
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_tolower(int32_t c)
2019-11-24 20:45:15 -08:00
{
return ((q_isupper(c)) ? (c | ('a' - 'A')) : c);
}
2019-11-25 16:49:58 -08:00
static inline int32_t q_toupper(int32_t c)
2019-11-24 20:45:15 -08:00
{
return ((q_islower(c)) ? (c & ~('a' - 'A')) : c);
}
2019-12-02 07:00:56 -08:00
#endif