aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorGregory Montoir2007-02-13 21:06:57 +0000
committerGregory Montoir2007-02-13 21:06:57 +0000
commit1ce912e1063ae297407b4a9dfd5f30d4819eb284 (patch)
treea60c5b02027b991908299884d60ada4d014a9b2c /common
parent474d49dc146876b773bfef80335b740d1b1fa8a7 (diff)
downloadscummvm-rg350-1ce912e1063ae297407b4a9dfd5f30d4819eb284.tar.gz
scummvm-rg350-1ce912e1063ae297407b4a9dfd5f30d4819eb284.tar.bz2
scummvm-rg350-1ce912e1063ae297407b4a9dfd5f30d4819eb284.zip
made rtrim() and ltrim() global functions, to reduce code duplication (it seems parallaction/parser.cpp code re-use them too
svn-id: r25564
Diffstat (limited to 'common')
-rw-r--r--common/config-file.cpp13
-rw-r--r--common/config-manager.cpp13
-rw-r--r--common/str.cpp16
-rw-r--r--common/str.h5
4 files changed, 21 insertions, 26 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp
index af991b931d..eef70ef1b9 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 0f80e5c84f..05a1b22404 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 ad2367fb41..be0144954b 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 c611b3df87..c7c9b466b1 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<String> {
public:
void push_back(const char *str) {