summaryrefslogtreecommitdiff
path: root/source/q_shared.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/q_shared.h')
-rw-r--r--source/q_shared.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/source/q_shared.h b/source/q_shared.h
index 8869d1d..93175b4 100644
--- a/source/q_shared.h
+++ b/source/q_shared.h
@@ -405,16 +405,23 @@ int Q_HighlightStr( char *out, const char *in, int bufsize );
//=============================================
+// fast "C" macros
#define Q_isupper( c ) ( (c) >= 'A' && (c) <= 'Z' )
#define Q_islower( c ) ( (c) >= 'a' && (c) <= 'z' )
#define Q_isdigit( c ) ( (c) >= '0' && (c) <= '9' )
#define Q_isalpha( c ) ( Q_isupper( c ) || Q_islower( c ) )
#define Q_isalnum( c ) ( Q_isalpha( c ) || Q_isdigit( c ) )
#define Q_isprint( c ) ( (c) >= 32 && (c) < 127 )
+#define Q_isgraph( c ) ( (c) > 32 && (c) < 127 )
+#define Q_isspace( c ) ( c == ' ' || c == '\f' || c == '\n' || \
+ c == '\r' || c == '\t' || c == '\v' )
// tests if specified character is valid quake path character
#define Q_ispath( c ) ( Q_isalnum( c ) || (c) == '_' || (c) == '-' )
+// tests if specified character has special meaning to quake console
+#define Q_isspecial( c ) ( (c) == '\r' || (c) == '\n' || (c) == 127 )
+
static inline int Q_tolower( int c ) {
if( Q_isupper( c ) ) {
c += ( 'a' - 'A' );
@@ -464,6 +471,20 @@ static inline int Q_charhex( int c ) {
return -1;
}
+// converts quake char to ASCII equivalent
+static inline int Q_charascii( int c ) {
+ c &= 127; // strip high bits
+ if( Q_isgraph( c ) || Q_isspace( c ) ) {
+ return c;
+ }
+ switch( c ) {
+ // handle bold brackets
+ case 16: return '[';
+ case 17: return ']';
+ }
+ return '.'; // don't output control chars, etc
+}
+
// portable case insensitive compare
int Q_strcasecmp( const char *s1, const char *s2 );
int Q_strncasecmp( const char *s1, const char *s2, size_t n );