add overloaded neutchars with different parameters

This commit is contained in:
dockes 2009-01-26 13:29:40 +00:00
parent 79c1f814f9
commit dc7c31454a
2 changed files with 13 additions and 6 deletions

View File

@ -357,17 +357,22 @@ void trimstring(string &s, const char *ws)
}
// Remove some chars and replace them with spaces
string neutchars(const string &str, string delims)
string neutchars(const string &str, const string &chars)
{
string out;
neutchars(str, out, chars);
return out;
}
void neutchars(const string &str, string &out, const string& chars)
{
string::size_type startPos, pos;
for (pos = 0;;) {
// Skip initial delims, break if this eats all.
if ((startPos = str.find_first_not_of(delims, pos)) == string::npos)
// Skip initial chars, break if this eats all.
if ((startPos = str.find_first_not_of(chars, pos)) == string::npos)
break;
// Find next delimiter or end of string (end of token)
pos = str.find_first_of(delims, startPos);
pos = str.find_first_of(chars, startPos);
// Add token to the output. Note: token cant be empty here
if (pos == string::npos) {
out += str.substr(startPos);
@ -375,7 +380,6 @@ string neutchars(const string &str, string delims)
out += str.substr(startPos, pos - startPos) + " ";
}
}
return out;
}
@ -711,6 +715,8 @@ int main(int argc, char **argv)
#elif 1
std::string testit("ligne\ndeuxieme ligne\r3eme ligne\r\n");
cout << "[" << neutchars(testit, "\r\n") << "]" << endl;
string i, o;
cout << "neutchars(null) is [" << neutchars(i, "\r\n") << "]" << endl;
#endif
}

View File

@ -80,7 +80,8 @@ extern string escapeHtml(const string &in);
/** Replace some chars with spaces (ie: newline chars). This is not utf8-aware
* so chars should only contain ascii */
extern string neutchars(const string &str, string chars);
extern string neutchars(const string &str, const string &chars);
extern void neutchars(const string &str, string& out, const string &chars);
/** turn string into something that won't be expanded by a shell. In practise
* quote with single-quotes and escape internal singlequotes */