From dc7c31454afabe17a8f464360fe076022fd4a014 Mon Sep 17 00:00:00 2001 From: dockes Date: Mon, 26 Jan 2009 13:29:40 +0000 Subject: [PATCH] add overloaded neutchars with different parameters --- src/utils/smallut.cpp | 16 +++++++++++----- src/utils/smallut.h | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp index 8d5993b4..2b3193a5 100644 --- a/src/utils/smallut.cpp +++ b/src/utils/smallut.cpp @@ -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 } diff --git a/src/utils/smallut.h b/src/utils/smallut.h index 26e15eb8..84504051 100644 --- a/src/utils/smallut.h +++ b/src/utils/smallut.h @@ -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 */