00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _LOG4TANGO_STRINGUTIL_H
00029 #define _LOG4TANGO_STRINGUTIL_H
00030
00031 #include "PortabilityImpl.hh"
00032 #include <string>
00033 #include <vector>
00034 #include <climits>
00035 #include <stdarg.h>
00036
00037 namespace log4tango {
00038
00039 class StringUtil
00040 {
00041 public:
00042
00049 static std::string vform(const char* format, va_list args);
00050
00055 static std::string trim(const std::string& s);
00056
00070 static unsigned int split(std::vector<std::string>& v,
00071 const std::string& s, char delimiter,
00072 unsigned int maxSegments = INT_MAX);
00073
00084 template<typename T>
00085 static unsigned int split(T& output,
00086 const std::string& s, char delimiter,
00087 unsigned int maxSegments = INT_MAX)
00088 {
00089 std::string::size_type left = 0;
00090 unsigned int i;
00091 for (i = 1; i < maxSegments; i++) {
00092 std::string::size_type right = s.find(delimiter, left);
00093 if (right == std::string::npos) {
00094 break;
00095 }
00096 *output++ = s.substr(left, right - left);
00097 left = right + 1;
00098 }
00099 *output++ = s.substr(left);
00100 return i;
00101 }
00102 };
00103
00104 }
00105
00106 #endif // _LOG4TANGO_STRINGUTIL_HH
00107