diff --git a/common/config-file.cpp b/common/config-file.cpp index af991b931d0..eef70ef1b94 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -32,19 +32,6 @@ namespace Common { -static char *ltrim(char *t) { - while (isspace(*t)) - t++; - return t; -} - -static char *rtrim(char *t) { - int l = strlen(t) - 1; - while (l >= 0 && isspace(t[l])) - t[l--] = 0; - return t; -} - /** * Check whether the given string is a valid section or key name. * For that, it must only consist of letters, numbers, dashes and diff --git a/common/config-manager.cpp b/common/config-manager.cpp index 0f80e5c84f8..05a1b224044 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -45,19 +45,6 @@ DECLARE_SINGLETON(Common::ConfigManager); #define MAXLINELEN 256 -static char *ltrim(char *t) { - while (isspace(*t)) - t++; - return t; -} - -static char *rtrim(char *t) { - int l = strlen(t) - 1; - while (l >= 0 && isspace(t[l])) - t[l--] = 0; - return t; -} - static bool isValidDomainName(const Common::String &domName) { const char *p = domName.c_str(); while (*p && (isalnum(*p) || *p == '-' || *p == '_')) diff --git a/common/str.cpp b/common/str.cpp index ad2367fb416..be0144954bc 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -431,5 +431,21 @@ String operator +(const String &x, const char *y) { return temp; } +char *ltrim(char *t) { + while (isspace(*t)) + t++; + return t; +} + +char *rtrim(char *t) { + int l = strlen(t) - 1; + while (l >= 0 && isspace(t[l])) + t[l--] = 0; + return t; +} + +char *trim(char *t) { + return rtrim(ltrim(t)); +} } // End of namespace Common diff --git a/common/str.h b/common/str.h index c611b3df87d..c7c9b466b18 100644 --- a/common/str.h +++ b/common/str.h @@ -194,6 +194,11 @@ String operator +(const String &x, const char *y); bool operator == (const char *x, const String &y); bool operator != (const char *x, const String &y); +// Utility functions to remove leading and trailing whitespaces +extern char *ltrim(char *t); +extern char *rtrim(char *t); +extern char *trim(char *t); + class StringList : public Array { public: void push_back(const char *str) { diff --git a/engines/agi/predictive.cpp b/engines/agi/predictive.cpp index e65e1bf2b45..731384b5c7d 100644 --- a/engines/agi/predictive.cpp +++ b/engines/agi/predictive.cpp @@ -315,19 +315,6 @@ bool AgiEngine::predictiveDialog(void) { return rc; } -static char *ltrim(char *t) { - while (isspace(*t)) - t++; - return t; -} - -static char *rtrim(char *t) { - int l = strlen(t) - 1; - while (l >= 0 && isspace(t[l])) - t[l--] = 0; - return t; -} - #define MAXLINELEN 80 void AgiEngine::loadDict(void) { @@ -343,7 +330,7 @@ void AgiEngine::loadDict(void) { while (!in.eos() && in.readLine(buf, MAXLINELEN)) { // Skip leading & trailing whitespaces - char *word = rtrim(ltrim(buf)); + char *word = Common::trim(buf); // Skip empty lines if (*word == 0) diff --git a/engines/queen/logic.cpp b/engines/queen/logic.cpp index 9973386b651..f7a23eeb3dc 100644 --- a/engines/queen/logic.cpp +++ b/engines/queen/logic.cpp @@ -44,20 +44,6 @@ namespace Queen { -static Common::String trim(const Common::String &s) { - const char *p; - - p = s.c_str(); - while (*p == ' ') ++p; - int start = p - s.c_str(); - - p = s.c_str() + s.size() - 1; - while (p != s.c_str() && *p == ' ') --p; - int end = p - s.c_str(); - - return Common::String(s.c_str() + start, end - start + 1); -} - Logic::Logic(QueenEngine *vm) : _credits(NULL), _objectData(NULL), _roomData(NULL), _sfxName(NULL), _itemData(NULL), _graphicData(NULL), _walkOffData(NULL), _objectDescription(NULL), @@ -227,16 +213,16 @@ void Logic::readQueenJas() { _joeResponse.push_back(""); for (i = 1; i <= JOE_RESPONSE_MAX; i++) { - _joeResponse.push_back(queen2jas.nextLine()); - } + char *defaultResponse = queen2jas.nextLine(); - // Spanish version adds some space characters (0x20) at the beginning - // and the end of the journal button captions. As the engine computes - // the text width to center it, we need to trim those strings. - if (_vm->resource()->getLanguage() == Common::ES_ESP) { - for (i = 30; i <= 35; i++) { - _joeResponse[i] = trim(_joeResponse[i]); + // In the spanish version, captions of journal buttons have leading & trailing + // whitespaces (they probably did it that way to center the texts). As we do + // differently (see code in journal.cpp), we remove these extra characters here. + if (_vm->resource()->getLanguage() == Common::ES_ESP && i >= 30 && i <= 35) { + defaultResponse = Common::trim(defaultResponse); } + + _joeResponse.push_back(defaultResponse); } _aAnim.push_back("");