Skip to content

Commit

Permalink
COMMON: Filter non-ASCII values in ctype.h-style isFOO functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Feb 20, 2012
1 parent 4f8665f commit 02ebd55
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions common/util.cpp
Expand Up @@ -415,32 +415,37 @@ void updateGameGUIOptions(const String &options, const String &langOption) {
}
}

//
// TODO: Instead of a blind cast, we might want to verify
// if c equals EOS; and/or is in the range -255..+255;
// and return false if it isn't.
//
#define ENSURE_ASCII_CHAR(c) \
if (c < 0 || c > 127) \
return false

bool isAlnum(int c) {
ENSURE_ASCII_CHAR(c);
return isalnum((byte)c);
}

bool isAlpha(int c) {
ENSURE_ASCII_CHAR(c);
return isalpha((byte)c);
}

bool isDigit(int c) {
ENSURE_ASCII_CHAR(c);
return isdigit((byte)c);
}

bool isLower(int c) {
ENSURE_ASCII_CHAR(c);
return islower((byte)c);
}

bool isSpace(int c) {
ENSURE_ASCII_CHAR(c);
return isspace((byte)c);
}

bool isUpper(int c) {
ENSURE_ASCII_CHAR(c);
return isupper((byte)c);
}

Expand Down

0 comments on commit 02ebd55

Please sign in to comment.