From d5777a65653bf23769aaba89dbd54b81fdbdfaff Mon Sep 17 00:00:00 2001 From: "wrenczes@gmail.com" Date: Sat, 5 Feb 2011 06:42:53 +0000 Subject: [PATCH] A simpler way to allow trim() to work with temporary strings. --- projects/mtg/include/utils.h | 14 ++++++-------- projects/mtg/src/utils.cpp | 22 ---------------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/projects/mtg/include/utils.h b/projects/mtg/include/utils.h index 61cfd555d..20d328ebd 100644 --- a/projects/mtg/include/utils.h +++ b/projects/mtg/include/utils.h @@ -74,19 +74,17 @@ namespace wagic using std::string; -#define SPACES " \t\r\n" //string manipulation methods - -// for trimming strings on the fly -string trim (const string & s, const string & t = SPACES); -string trim_right (const string & s, const string & t = SPACES); -string trim_left (const string & s, const string & t = SPACES); - -// trimmning strings inplace string& trim(string& str); string& ltrim(string& str); string& rtrim(string& str); +inline string trim(const string& str) +{ + string value(str); + return trim(value); +} + std::string join(vector& v, string delim = " "); std::vector& split(const std::string& s, char delim, std::vector& elems); diff --git a/projects/mtg/src/utils.cpp b/projects/mtg/src/utils.cpp index b6969a59d..064d2bc14 100644 --- a/projects/mtg/src/utils.cpp +++ b/projects/mtg/src/utils.cpp @@ -237,28 +237,6 @@ u32 ramAvailable(void) } /* String manipulation functions */ -string trim_right (const string & s, const string & t) -{ - string d (s); - string::size_type i (d.find_last_not_of (t)); - if (i == string::npos) - return ""; - else - return d.erase (d.find_last_not_of (t) + 1) ; -} - -string trim_left (const string & s, const string & t) -{ - string d (s); - return d.erase (0, s.find_first_not_of (t)) ; -} - -string trim (const string & s, const string & t) -{ - string d (s); - return trim_left (trim_right (d, t), t) ; -} - string& trim(string& str) { str = ltrim(str);