StringUtil.hh
Go to the documentation of this file.
1 /*
2  * StringUtil.hh
3  *
4  * Copyright 2002, Log4cpp Project. All rights reserved.
5  *
6  * See the COPYING file for the terms of usage and distribution.
7  */
8 
9 #ifndef _LOG4CPP_STRINGUTIL_HH
10 #define _LOG4CPP_STRINGUTIL_HH
11 
12 #include "PortabilityImpl.hh"
13 #include <string>
14 #include <vector>
15 #include <climits>
16 #include <stdarg.h>
17 
18 namespace log4cpp {
19 
20  class StringUtil {
21  public:
22 
29  static std::string vform(const char* format, va_list args);
30 
35  static std::string trim(const std::string& s);
36 
50  static unsigned int split(std::vector<std::string>& v,
51  const std::string& s, char delimiter,
52  unsigned int maxSegments = INT_MAX);
63  template<typename T> static unsigned int split(T& output,
64  const std::string& s, char delimiter,
65  unsigned int maxSegments = INT_MAX) {
66  std::string::size_type left = 0;
67  unsigned int i;
68  for(i = 1; i < maxSegments; i++) {
69  std::string::size_type right = s.find(delimiter, left);
70  if (right == std::string::npos) {
71  break;
72  }
73  *output++ = s.substr(left, right - left);
74  left = right + 1;
75  }
76 
77  *output++ = s.substr(left);
78  return i;
79  }
80  };
81 }
82 
83 #endif // _LOG4CPP_STRINGUTIL_HH
84 
static std::string vform(const char *format, va_list args)
Definition: StringUtil.cpp:37
static unsigned int split(T &output, const std::string &s, char delimiter, unsigned int maxSegments=INT_MAX)
Definition: StringUtil.hh:63
static std::string trim(const std::string &s)
Definition: StringUtil.cpp:71
LOG4CPP_EXPORT CategoryStream & left(CategoryStream &os)
static unsigned int split(std::vector< std::string > &v, const std::string &s, char delimiter, unsigned int maxSegments=INT_MAX)
Definition: StringUtil.cpp:90


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:10:00