Skip to content
Snippets Groups Projects
Commit 41993912 authored by Oliver Sander's avatar Oliver Sander
Browse files

* Don't copy the input string, a reference will suffice

* Rewrite using switches and iterators   

Patch by Elias Pipping


[[Imported from SVN: r5293]]
parent 218208e7
Branches
Tags
No related merge requests found
......@@ -284,20 +284,37 @@ namespace Dune {
} // end namespace Dune
string ConfigParser::trim(string s)
static inline bool is_space(char c)
{
int i = 0;
while ((s[i] == ' ')or (s[i] == '\n') or (s[i] == '\r'))
i++;
switch (c) {
case ' ' :
case '\n' :
case '\r' :
return true;
default :
return false;
}
}
s.erase(0,i);
string ConfigParser::trim(const string& s) const
{
string::const_iterator b = s.begin();
string::const_iterator e = s.end();
for ( ; ; )
if (b != e)
if (is_space(*b))
++b;
else
break;
else
return string();
i = s.length();
while ((s[i-1] == ' ')or (s[i-1] == '\n') or (s[i-1] == '\r'))
i--;
while (is_space(e[-1]))
--e;
s.erase(i);
return s;
return string(b, e);
}
const ConfigParser::KeyVector& ConfigParser::getValueKeys() const
......
......@@ -226,7 +226,7 @@ namespace Dune {
std::map<std::string, std::string> values;
std::map<std::string, ConfigParser> subs;
std::string trim(std::string s);
std::string trim(const std::string& s) const;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment