aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/forbidden.h5
-rw-r--r--common/str.cpp2
-rw-r--r--common/util.cpp5
-rw-r--r--common/util.h13
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