aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2012-12-13 20:52:09 +0100
committerJohannes Schickel2012-12-13 21:08:47 +0100
commitb0ba4b01a4fee3409768bdced4de6719b51297bc (patch)
tree6ad91afdcee1804f54f911b4abafbac4d51ad3b6
parent7319ccd84f6facbaa3875d1adc31f26cea94d223 (diff)
downloadscummvm-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.
-rw-r--r--common/forbidden.h5
-rw-r--r--common/str.cpp2
-rw-r--r--common/util.cpp5
-rw-r--r--common/util.h13
-rw-r--r--engines/hugo/parser.cpp2
-rw-r--r--engines/queen/journal.cpp2
-rw-r--r--engines/touche/menu.cpp2
-rw-r--r--gui/widgets/list.cpp2
8 files changed, 27 insertions, 6 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
diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp
index 5fdb2026a7..2585c64fd8 100644
--- a/engines/hugo/parser.cpp
+++ b/engines/hugo/parser.cpp
@@ -235,7 +235,7 @@ void Parser::charHandler() {
if (_cmdLineIndex >= kMaxLineSize) {
//MessageBeep(MB_ICONASTERISK);
warning("STUB: MessageBeep() - Command line too long");
- } else if (isprint(static_cast<unsigned char>(c))) {
+ } else if (Common::isPrint(c)) {
_cmdLine[_cmdLineIndex++] = c;
_cmdLine[_cmdLineIndex] = '\0';
}
diff --git a/engines/queen/journal.cpp b/engines/queen/journal.cpp
index db06d540f5..474f72eca5 100644
--- a/engines/queen/journal.cpp
+++ b/engines/queen/journal.cpp
@@ -559,7 +559,7 @@ void Journal::updateTextField(uint16 ascii, int keycode) {
}
break;
default:
- if (isprint((char)ascii) &&
+ if (Common::isPrint((char)ascii) &&
_textField.textCharsCount < (sizeof(_textField.text) - 1) &&
_vm->display()->textWidth(_textField.text) < _textField.w) {
_textField.text[_textField.textCharsCount] = (char)ascii;
diff --git a/engines/touche/menu.cpp b/engines/touche/menu.cpp
index c58e2f1a33..46429ebbc2 100644
--- a/engines/touche/menu.cpp
+++ b/engines/touche/menu.cpp
@@ -103,7 +103,7 @@ struct MenuData {
void addCharToDescription(int slot, char chr) {
char *description = saveLoadDescriptionsTable[slot];
int descriptionLen = strlen(description);
- if (descriptionLen < 32 && isprint(static_cast<unsigned char>(chr))) {
+ if (descriptionLen < 32 && Common::isPrint(chr)) {
description[descriptionLen] = chr;
description[descriptionLen + 1] = 0;
}
diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index 13784ddf7f..95d39c4f24 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -284,7 +284,7 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
bool dirty = false;
int oldSelectedItem = _selectedItem;
- if (!_editMode && state.keycode <= Common::KEYCODE_z && isprint((unsigned char)state.ascii)) {
+ if (!_editMode && state.keycode <= Common::KEYCODE_z && Common::isPrint(state.ascii)) {
// Quick selection mode: Go to first list item starting with this key
// (or a substring accumulated from the last couple key presses).
// Only works in a useful fashion if the list entries are sorted.