From 5bd265637badcf17851d615e547a2d1fdfef07ec Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 4 Aug 2021 09:14:34 +0200 Subject: [PATCH] ULTIMA: fix global constructor warnings This also makes the code independent of the user's locale (being dependent on that by accident can lead to difficult to track down bugs) The list of whitespace used now is what the C standard guarantees as minimal set of characters accepted by `isspace` as whitespace. --- engines/ultima/nuvie/keybinding/keys.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/engines/ultima/nuvie/keybinding/keys.cpp b/engines/ultima/nuvie/keybinding/keys.cpp index 44023814ad9..c787b32f47f 100644 --- a/engines/ultima/nuvie/keybinding/keys.cpp +++ b/engines/ultima/nuvie/keybinding/keys.cpp @@ -41,15 +41,7 @@ namespace Ultima { namespace Nuvie { -static class Chardata { // ctype-like character lists -public: - string whitespace; - Chardata() { - for (size_t i = 0; i < 256; i++) - if (Common::isSpace(i)) - whitespace += static_cast(i); - } -} chardata; +static const char * whitespace = "\t\n\v\f\r "; typedef void(*ActionFunc)(int const *); @@ -453,7 +445,7 @@ void KeyBinder::ParseText(char *text, int len) { } static void skipspace(string &s) { - size_t i = s.findFirstNotOf(chardata.whitespace); + size_t i = s.findFirstNotOf(whitespace); if (i && i != string::npos) s.erase(0, i); } @@ -494,7 +486,7 @@ void KeyBinder::ParseLine(char *line) { s.erase(0, 6); u.erase(0, 6); } else { - i = s.findFirstOf(chardata.whitespace); + i = s.findFirstOf(whitespace); keycode = s.substr(0, i); s.erase(0, i); @@ -532,7 +524,7 @@ void KeyBinder::ParseLine(char *line) { // get function skipspace(s); - i = s.findFirstOf(chardata.whitespace); + i = s.findFirstOf(whitespace); string t = s.substr(0, i); s.erase(0, i); t = Std::to_uppercase(t); @@ -550,7 +542,7 @@ void KeyBinder::ParseLine(char *line) { int np = 0; while (!s.empty() && s[0] != '#' && np < c_maxparams) { - i = s.findFirstOf(chardata.whitespace); + i = s.findFirstOf(whitespace); string tmp = s.substr(0, i); s.erase(0, i); skipspace(s);