00001 /*----------------------------------------------------------------------------- 00002 Name: StringStripper.h 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Helper to strip a std::string containing separators into a std::vector 00006 Author: <Michele Laghi> laghi@swissinfo.org 00007 -----------------------------------------------------------------------------*/ 00008 00009 #ifndef _UTIL_STRINGSTRIPPER_H 00010 #define _UTIL_STRINGSTRIPPER_H 00011 00012 #include <string> 00013 #include <vector> 00014 #include <util/XmlBCfg.h> 00015 00016 00017 00018 namespace org { namespace xmlBlaster { 00019 namespace util { 00020 00031 class Dll_Export StringStripper { 00032 00033 private: 00034 std::string separator_; 00035 int sepSize_; 00036 public: 00037 00038 StringStripper(const std::string &separator) { 00039 separator_ = separator; 00040 sepSize_ = (int)separator_.length(); 00041 } 00042 00048 std::vector<std::string> strip(std::string line) { 00049 std::vector<std::string> ret; 00050 std::string sub; 00051 int pos; 00052 while ((pos=(int)line.find(separator_)) >= 0) { 00053 sub.assign(line,0, pos); 00054 line = line.substr(pos+sepSize_); 00055 ret.insert(ret.end(), sub); 00056 } 00057 ret.insert(ret.end(), line); 00058 return ret; 00059 } 00060 00061 }; 00062 }}} // namespace 00063 00064 #endif 00065