mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 08:38:23 +01:00
changed implementation of trim_left trim_right and trim.
see http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring Note: some previous uses of trim were erroneous (see tokiso_unit) since it had to be used like this: s = trim(s); can now be used like trim(s) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6330 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
69711a425a
commit
7c3f0b5baf
33
Parser.h
33
Parser.h
@ -10,6 +10,10 @@
|
||||
#include <sstream> // std::istringstream std::ostringstream
|
||||
#include <ostream> // std::ostream
|
||||
#include <istream> // std::istream
|
||||
#include <cctype> // std::isspace
|
||||
#include <algorithm> // std::find_if
|
||||
#include <functional> // std::ptr_fun std::not1
|
||||
|
||||
#include "PHRQ_base.h"
|
||||
#include "Keywords.h"
|
||||
#include "PHRQ_io.h"
|
||||
@ -269,22 +273,19 @@ class CParser: public PHRQ_base
|
||||
};
|
||||
|
||||
// Global functions
|
||||
inline std::string trim_right(const std::string &source , const std::string& t = " \t")
|
||||
{
|
||||
std::string str = source;
|
||||
return str.erase( str.find_last_not_of(t) + 1);
|
||||
}
|
||||
|
||||
inline std::string trim_left( const std::string& source, const std::string& t = " \t")
|
||||
{
|
||||
std::string str = source;
|
||||
return str.erase(0 , source.find_first_not_of(t) );
|
||||
}
|
||||
|
||||
inline std::string trim(const std::string& source, const std::string& t = " \t")
|
||||
{
|
||||
std::string str = source;
|
||||
return trim_left( trim_right( str , t) , t );
|
||||
static inline std::string &trim_left(std::string &s)
|
||||
{
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||
return s;
|
||||
}
|
||||
static inline std::string &trim_right(std::string &s)
|
||||
{
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
||||
return s;
|
||||
}
|
||||
static inline std::string &trim(std::string &s)
|
||||
{
|
||||
return trim_left(trim_right(s));
|
||||
}
|
||||
|
||||
#endif // PARSER_H_INCLUDED
|
||||
|
||||
@ -216,7 +216,7 @@ bool dumper::Read(CParser & parser)
|
||||
break;
|
||||
case 0: //file
|
||||
std::getline(parser.get_iss(), this->file_name);
|
||||
this->file_name = trim(this->file_name, " \t");
|
||||
trim(this->file_name);
|
||||
if (this->file_name.size() == 0)
|
||||
{
|
||||
this->file_name = "dump.out";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user