diff options
author | dwight <dwight@10gen.com> | 2010-12-15 02:07:45 -0500 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2010-12-15 10:42:43 -0500 |
commit | 62fbef60e708eaaf02de89be7af18edea4e5677e (patch) | |
tree | fc907d82664afbdb66861ac823d893da78c70e4c /util/mongoutils | |
parent | 30d7c304fd333bc336792e585d73efd62da52606 (diff) | |
download | mongo-62fbef60e708eaaf02de89be7af18edea4e5677e.tar.gz |
str stuff
Diffstat (limited to 'util/mongoutils')
-rw-r--r-- | util/mongoutils/str.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/util/mongoutils/str.h b/util/mongoutils/str.h index 95a71931bb6..9ffb30834cc 100644 --- a/util/mongoutils/str.h +++ b/util/mongoutils/str.h @@ -97,6 +97,8 @@ namespace mongoutils { /** @return true if s contains x */ inline bool contains(string s, string x) { return strstr(s.c_str(), x.c_str()) != 0; } + inline bool contains(string s, char x) { + return strchr(s.c_str(), x) != 0; } /** @return everything befor the character x, else entire string */ inline string before(const string& s, char x) { @@ -147,7 +149,7 @@ namespace mongoutils { R = string(p+1); return true; } - /** split scanning reverse direction */ + /** split scanning reverse direction. Splits ONCE ONLY. */ inline bool rSplitOn(const string &s, char c, string& L, string& R) { const char *start = s.c_str(); const char *p = strrchr(start, c); @@ -160,6 +162,7 @@ namespace mongoutils { return true; } + /** @return umber of occurrences of c in s */ inline unsigned count( const string& s , char c ){ unsigned n=0; for ( unsigned i=0; i<s.size(); i++ ) @@ -168,6 +171,17 @@ namespace mongoutils { return n; } + /** remove trailing chars in place */ + inline bool stripTrailing(string& s, const char *chars) { + string::iterator i = s.end(); + while( s.begin() != i ) { + i--; + if( contains(chars, *i) ) { + s.erase(i); + } + } + } + } } |