diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-10-09 16:22:56 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-10-09 16:22:56 +0000 |
| commit | dbea00fa9d8d4b9ca32b7bbea6ecc4e6348a5c12 (patch) | |
| tree | 29cc8d4baf5de7c9f459de790135bd6aff1e7fbd /src/util.h | |
| parent | f816434d06c6bc66b2421d29c8d2ffecd04868ba (diff) | |
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added util::strip()
* src/util.cc
* src/util.h
* test/UtilTest.cc
Diffstat (limited to 'src/util.h')
| -rw-r--r-- | src/util.h | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -134,6 +134,28 @@ std::string trim(const std::string& src, void trimSelf(std::string& str, const std::string& trimCharset = DEFAULT_TRIM_CHARSET); +template<typename InputIterator> +std::string stripIter +(InputIterator first, InputIterator last, + const std::string& chars = DEFAULT_TRIM_CHARSET) +{ + if(std::distance(first, last) == 0) { + return A2STR::NIL; + } + for(; first != last && + std::find(chars.begin(), chars.end(), *first) != chars.end(); ++first); + if(first == last) { + return A2STR::NIL; + } + InputIterator left = last-1; + for(; left != first && + std::find(chars.begin(), chars.end(), *left) != chars.end(); --left); + return std::string(first, left+1); +} + +std::string strip +(const std::string& str, const std::string& chars = DEFAULT_TRIM_CHARSET); + bool startsWith(const std::string& target, const std::string& part); bool endsWith(const std::string& target, const std::string& part); |
