00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef _LOG4CPP_STRINGUTIL_HH
00010 #define _LOG4CPP_STRINGUTIL_HH
00011
00012 #include <log4cpp/Portability.hh>
00013 #include <string>
00014 #include <vector>
00015 #include <climits>
00016
00017 namespace log4cpp {
00018
00019 class StringUtil {
00020 public:
00025 static std::string trim(const std::string& s);
00026
00039 static void split(std::vector<std::string>& v,
00040 const std::string& s, char delimiter,
00041 unsigned int maxSegments = INT_MAX);
00052 template<typename T> static unsigned int split(T& output,
00053 const std::string& s, char delimiter,
00054 unsigned int maxSegments = INT_MAX) {
00055 std::string::size_type left = 0;
00056 unsigned int i;
00057 for(i = 1; i < maxSegments; i++) {
00058 std::string::size_type right = s.find(delimiter, left);
00059 if (right == std::string::npos) {
00060 break;
00061 }
00062 *output++ = s.substr(left, right - left);
00063 left = right + 1;
00064 }
00065
00066 *output++ = s.substr(left);
00067 return i;
00068 };
00069 };
00070 }
00071
00072 #endif // _LOG4CPP_STRINGUTIL_HH
00073