log4cpp 1.1.3
Loading...
Searching...
No Matches
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
18namespace 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
Definition StringUtil.hh:20
static std::string trim(const std::string &s)
Returns a string identical to the given string but without leading or trailing HTABs or spaces.
Definition StringUtil.cpp:71
static unsigned int split(std::vector< std::string > &v, const std::string &s, char delimiter, unsigned int maxSegments=INT_MAX)
Definition StringUtil.cpp:90
static std::string vform(const char *format, va_list args)
Returns a string contructed from the a format specifier and a va_list of arguments,...
Definition StringUtil.cpp:37
static unsigned int split(T &output, const std::string &s, char delimiter, unsigned int maxSegments=INT_MAX)
splits a string into string segments based on the given delimiter and assigns the segments through an...
Definition StringUtil.hh:63
The top level namespace for all 'Log for C++' types and classes.
Definition AbortAppender.hh:16
LOG4CPP_EXPORT CategoryStream & left(CategoryStream &os)
left manipulator
Definition CategoryStream.cpp:71