aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/config-file.cpp6
-rw-r--r--common/config-manager.cpp6
-rw-r--r--common/forbidden.h43
-rw-r--r--common/str.cpp8
-rw-r--r--common/util.cpp43
-rw-r--r--common/util.h64
-rw-r--r--common/xmlparser.cpp10
-rw-r--r--common/xmlparser.h2
8 files changed, 166 insertions, 16 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp
index 81e0ae6b45..4224d7491d 100644
--- a/common/config-file.cpp
+++ b/common/config-file.cpp
@@ -30,7 +30,7 @@ namespace Common {
bool ConfigFile::isValidName(const String &name) {
const char *p = name.c_str();
- while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.'))
+ while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.'))
p++;
return *p == 0;
}
@@ -108,7 +108,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
// is, verify that it only consists of alphanumerics,
// periods, dashes and underscores). Mohawk Living Books games
// can have periods in their section names.
- while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.'))
+ while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.'))
p++;
if (*p == '\0')
@@ -131,7 +131,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
// Skip leading whitespaces
const char *t = line.c_str();
- while (isspace(static_cast<unsigned char>(*t)))
+ while (isSpace(*t))
t++;
// Skip empty lines / lines with only whitespace
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index c62dee8bea..aaa812bc94 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -29,7 +29,7 @@
static bool isValidDomainName(const Common::String &domName) {
const char *p = domName.c_str();
- while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_'))
+ while (*p && (Common::isAlnum(*p) || *p == '-' || *p == '_'))
p++;
return *p == 0;
}
@@ -187,7 +187,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) {
// Get the domain name, and check whether it's valid (that
// is, verify that it only consists of alphanumerics,
// dashes and underscores).
- while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_'))
+ while (*p && (isAlnum(*p) || *p == '-' || *p == '_'))
p++;
if (*p == '\0')
@@ -205,7 +205,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) {
// Skip leading whitespaces
const char *t = line.c_str();
- while (isspace(static_cast<unsigned char>(*t)))
+ while (isSpace(*t))
t++;
// Skip empty lines / lines with only whitespace
diff --git a/common/forbidden.h b/common/forbidden.h
index 8b5a2f738e..eec80bba59 100644
--- a/common/forbidden.h
+++ b/common/forbidden.h
@@ -317,6 +317,49 @@
#endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
+
+//
+// Disable various symbols from ctype.h
+//
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_ctype_h
+
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isalnum
+ #undef isalnum
+ #define isalnum(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isalpha
+ #undef isalpha
+ #define isalpha(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isdigit
+ #undef isdigit
+ #define isdigit(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isnumber
+ #undef isnumber
+ #define isnumber(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_islower
+ #undef islower
+ #define islower(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isspace
+ #undef isspace
+ #define isspace(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+ #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isupper
+ #undef isupper
+ #define isupper(a) FORBIDDEN_SYMBOL_REPLACEMENT
+ #endif
+
+#endif // FORBIDDEN_SYMBOL_EXCEPTION_ctype_h
+
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_mkdir
#undef mkdir
#define mkdir(a,b) FORBIDDEN_SYMBOL_REPLACEMENT
diff --git a/common/str.cpp b/common/str.cpp
index 76c0ba2886..84805082ac 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -405,13 +405,13 @@ void String::trim() {
makeUnique();
// Trim trailing whitespace
- while (_size >= 1 && isspace(static_cast<unsigned char>(_str[_size - 1])))
+ while (_size >= 1 && isSpace(_str[_size - 1]))
--_size;
_str[_size] = 0;
// Trim leading whitespace
char *t = _str;
- while (isspace((unsigned char)*t))
+ while (isSpace(*t))
t++;
if (t != _str) {
@@ -606,14 +606,14 @@ String operator+(const String &x, char y) {
}
char *ltrim(char *t) {
- while (isspace(static_cast<unsigned char>(*t)))
+ while (isSpace(*t))
t++;
return t;
}
char *rtrim(char *t) {
int l = strlen(t) - 1;
- while (l >= 0 && isspace(static_cast<unsigned char>(t[l])))
+ while (l >= 0 && isSpace(t[l]))
t[l--] = 0;
return t;
}
diff --git a/common/util.cpp b/common/util.cpp
index 1c4df8b6cd..3f97308d8e 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -19,6 +19,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#define FORBIDDEN_SYMBOL_EXCEPTION_isalnum
+#define FORBIDDEN_SYMBOL_EXCEPTION_isalpha
+#define FORBIDDEN_SYMBOL_EXCEPTION_isdigit
+#define FORBIDDEN_SYMBOL_EXCEPTION_isnumber
+#define FORBIDDEN_SYMBOL_EXCEPTION_islower
+#define FORBIDDEN_SYMBOL_EXCEPTION_isspace
+#define FORBIDDEN_SYMBOL_EXCEPTION_isupper
+
+
#include "common/util.h"
#include "common/translation.h"
#include "common/config-manager.h"
@@ -406,4 +415,38 @@ void updateGameGUIOptions(const String &options, const String &langOption) {
}
}
+#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);
+}
+
} // End of namespace Common
diff --git a/common/util.h b/common/util.h
index dfa57d7259..617bc3dcfa 100644
--- a/common/util.h
+++ b/common/util.h
@@ -133,6 +133,70 @@ extern void hexdump(const byte * data, int len, int bytesPerLine = 16, int start
*/
bool parseBool(const String &val, bool &valAsBool);
+
+/**
+ * Test whether the given character is alphanumeric (a-z, A-Z, 0-9).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is alphanumeric, false otherwise.
+ */
+bool isAlnum(int c);
+
+/**
+ * Test whether the given character is an alphabetic letter (a-z, A-Z).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is TODO, false otherwise.
+ */
+bool isAlpha(int c);
+
+/**
+ * Test whether the given character is a decimal-digit (0-9).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is a decimal-digit, false otherwise.
+ */
+bool isDigit(int c);
+
+/**
+ * Test whether the given character is a lower-case letter (a-z).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is a lower-case letter, false otherwise.
+ */
+bool isLower(int c);
+
+/**
+ * Test whether the given character is a white-space.
+ * White-space characters are ' ', '\t', '\r', '\n', '\v', '\f'.
+ *
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is a white-space, false otherwise.
+ */
+bool isSpace(int c);
+
+/**
+ * Test whether the given character is an upper-case letter (A-Z).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is an upper-case letter, false otherwise.
+ */
+bool isUpper(int c);
+
+
/**
* List of game language.
*/
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index 1181b399cc..ea3d44cf87 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -263,7 +263,7 @@ bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) {
int *num_ptr;
while (count--) {
- while (isspace(static_cast<unsigned char>(*key)))
+ while (isSpace(*key))
key++;
num_ptr = va_arg(args, int*);
@@ -271,7 +271,7 @@ bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) {
key = parseEnd;
- while (isspace(static_cast<unsigned char>(*key)))
+ while (isSpace(*key))
key++;
if (count && *key++ != ',')
@@ -463,10 +463,10 @@ bool XMLParser::parse() {
}
bool XMLParser::skipSpaces() {
- if (!isspace(static_cast<unsigned char>(_char)))
+ if (!isSpace(_char))
return false;
- while (_char && isspace(static_cast<unsigned char>(_char)))
+ while (_char && isSpace(_char))
_char = _stream->readByte();
return true;
@@ -516,7 +516,7 @@ bool XMLParser::parseToken() {
_char = _stream->readByte();
}
- return isspace(static_cast<unsigned char>(_char)) != 0 || _char == '>' || _char == '=' || _char == '/';
+ return isSpace(_char) != 0 || _char == '>' || _char == '=' || _char == '/';
}
} // End of namespace Common
diff --git a/common/xmlparser.h b/common/xmlparser.h
index 04fb54efbb..1e474b596c 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -295,7 +295,7 @@ protected:
* in their name.
*/
virtual inline bool isValidNameChar(char c) {
- return isalnum(static_cast<unsigned char>(c)) || c == '_';
+ return isAlnum(c) || c == '_';
}
/**