[Scummvm-cvs-logs] SF.net SVN: scummvm: [25564] scummvm/trunk
cyx at users.sourceforge.net
cyx at users.sourceforge.net
Tue Feb 13 22:07:01 CET 2007
Revision: 25564
http://scummvm.svn.sourceforge.net/scummvm/?rev=25564&view=rev
Author: cyx
Date: 2007-02-13 13:06:57 -0800 (Tue, 13 Feb 2007)
Log Message:
-----------
made rtrim() and ltrim() global functions, to reduce code duplication (it seems parallaction/parser.cpp code re-use them too
Modified Paths:
--------------
scummvm/trunk/common/config-file.cpp
scummvm/trunk/common/config-manager.cpp
scummvm/trunk/common/str.cpp
scummvm/trunk/common/str.h
scummvm/trunk/engines/agi/predictive.cpp
scummvm/trunk/engines/queen/logic.cpp
Modified: scummvm/trunk/common/config-file.cpp
===================================================================
--- scummvm/trunk/common/config-file.cpp 2007-02-13 21:06:45 UTC (rev 25563)
+++ scummvm/trunk/common/config-file.cpp 2007-02-13 21:06:57 UTC (rev 25564)
@@ -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
Modified: scummvm/trunk/common/config-manager.cpp
===================================================================
--- scummvm/trunk/common/config-manager.cpp 2007-02-13 21:06:45 UTC (rev 25563)
+++ scummvm/trunk/common/config-manager.cpp 2007-02-13 21:06:57 UTC (rev 25564)
@@ -45,19 +45,6 @@
#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 == '_'))
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2007-02-13 21:06:45 UTC (rev 25563)
+++ scummvm/trunk/common/str.cpp 2007-02-13 21:06:57 UTC (rev 25564)
@@ -431,5 +431,21 @@
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
Modified: scummvm/trunk/common/str.h
===================================================================
--- scummvm/trunk/common/str.h 2007-02-13 21:06:45 UTC (rev 25563)
+++ scummvm/trunk/common/str.h 2007-02-13 21:06:57 UTC (rev 25564)
@@ -194,6 +194,11 @@
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<String> {
public:
void push_back(const char *str) {
Modified: scummvm/trunk/engines/agi/predictive.cpp
===================================================================
--- scummvm/trunk/engines/agi/predictive.cpp 2007-02-13 21:06:45 UTC (rev 25563)
+++ scummvm/trunk/engines/agi/predictive.cpp 2007-02-13 21:06:57 UTC (rev 25564)
@@ -315,19 +315,6 @@
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 @@
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)
Modified: scummvm/trunk/engines/queen/logic.cpp
===================================================================
--- scummvm/trunk/engines/queen/logic.cpp 2007-02-13 21:06:45 UTC (rev 25563)
+++ scummvm/trunk/engines/queen/logic.cpp 2007-02-13 21:06:57 UTC (rev 25564)
@@ -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 @@
_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("");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list