diff options
author | Johannes Schickel | 2012-12-13 20:52:09 +0100 |
---|---|---|
committer | Johannes Schickel | 2012-12-13 21:08:47 +0100 |
commit | b0ba4b01a4fee3409768bdced4de6719b51297bc (patch) | |
tree | 6ad91afdcee1804f54f911b4abafbac4d51ad3b6 /common | |
parent | 7319ccd84f6facbaa3875d1adc31f26cea94d223 (diff) | |
download | scummvm-rg350-b0ba4b01a4fee3409768bdced4de6719b51297bc.tar.gz scummvm-rg350-b0ba4b01a4fee3409768bdced4de6719b51297bc.tar.bz2 scummvm-rg350-b0ba4b01a4fee3409768bdced4de6719b51297bc.zip |
COMMON: Add wrapper for isprint.
This is done in the spirit of 658080deeda79d20ea40643569fbcb072573e7cf.
Diffstat (limited to 'common')
-rw-r--r-- | common/forbidden.h | 5 | ||||
-rw-r--r-- | common/str.cpp | 2 | ||||
-rw-r--r-- | common/util.cpp | 5 | ||||
-rw-r--r-- | common/util.h | 13 |
4 files changed, 23 insertions, 2 deletions
diff --git a/common/forbidden.h b/common/forbidden.h index eec80bba59..46890e0269 100644 --- a/common/forbidden.h +++ b/common/forbidden.h @@ -358,6 +358,11 @@ #define isupper(a) FORBIDDEN_SYMBOL_REPLACEMENT #endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isprint + #undef isprint + #define isprint(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + #endif // FORBIDDEN_SYMBOL_EXCEPTION_ctype_h #ifndef FORBIDDEN_SYMBOL_EXCEPTION_mkdir diff --git a/common/str.cpp b/common/str.cpp index 84805082ac..8210ca6bb8 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -764,7 +764,7 @@ String tag2string(uint32 tag) { str[4] = '\0'; // Replace non-printable chars by dot for (int i = 0; i < 4; ++i) { - if (!isprint((unsigned char)str[i])) + if (!Common::isPrint(str[i])) str[i] = '.'; } return String(str); diff --git a/common/util.cpp b/common/util.cpp index 4d9ff11c5c..3d40fffff5 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -26,6 +26,7 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_islower #define FORBIDDEN_SYMBOL_EXCEPTION_isspace #define FORBIDDEN_SYMBOL_EXCEPTION_isupper +#define FORBIDDEN_SYMBOL_EXCEPTION_isprint #include "common/util.h" @@ -144,4 +145,8 @@ bool isUpper(int c) { return isupper((byte)c); } +bool isPrint(int c) { + ENSURE_ASCII_CHAR(c); + return isprint((byte)c); +} } // End of namespace Common diff --git a/common/util.h b/common/util.h index 78340980d5..4ca1c42929 100644 --- a/common/util.h +++ b/common/util.h @@ -165,6 +165,17 @@ bool isSpace(int c); */ bool isUpper(int c); -} // End of namespace Common +/** + * Test whether the given character is printable. This includes the space + * character (' '). + * + * 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 printable, false otherwise. + */ +bool isPrint(int c); +} // End of namespace Common #endif |