summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-10-09 16:22:56 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-10-09 16:22:56 +0000
commitdbea00fa9d8d4b9ca32b7bbea6ecc4e6348a5c12 (patch)
tree29cc8d4baf5de7c9f459de790135bd6aff1e7fbd /src/util.h
parentf816434d06c6bc66b2421d29c8d2ffecd04868ba (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.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index 49c7c578..12af8ed7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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);