From 658080deeda79d20ea40643569fbcb072573e7cf Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 28 Jan 2012 01:15:49 +0100 Subject: ALL: Avoid using is* macros from ctype.h On some systems, passing signed chars to macros like isspace() etc. lead to a runtime error. Hence, mark these macros as forbidden by default, and introduce otherwise equivalent alternatives for them. --- common/util.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'common/util.h') diff --git a/common/util.h b/common/util.h index dfa57d7259..1df7bbb9c3 100644 --- a/common/util.h +++ b/common/util.h @@ -34,6 +34,17 @@ ((((size_t)value) & ((alignment) - 1)) == 0) +//namespace{ +bool isAlnum(int c); +bool isAlpha(int c); +bool isDigit(int c); +bool isNumber(int c); +bool isLower(int c); +bool isSpace(int c); +bool isUpper(int c); +//} + + #ifdef MIN #undef MIN #endif -- cgit v1.2.3 From 4f8665fc836898ebf54fc73b1061125b748183bc Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 20 Feb 2012 16:03:39 +0100 Subject: COMMON: Move isFoo functions to namespace Common, add doxygen comments --- common/util.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 11 deletions(-) (limited to 'common/util.h') diff --git a/common/util.h b/common/util.h index 1df7bbb9c3..617bc3dcfa 100644 --- a/common/util.h +++ b/common/util.h @@ -34,17 +34,6 @@ ((((size_t)value) & ((alignment) - 1)) == 0) -//namespace{ -bool isAlnum(int c); -bool isAlpha(int c); -bool isDigit(int c); -bool isNumber(int c); -bool isLower(int c); -bool isSpace(int c); -bool isUpper(int c); -//} - - #ifdef MIN #undef MIN #endif @@ -144,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. */ -- cgit v1.2.3