log4cpp 1.1.6
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 <climits>
14#include <stdarg.h>
15#include <string>
16#include <vector>
17
18namespace log4cpp {
19
20 class StringUtil {
21 public:
28 static std::string vform(const char* format, va_list args);
29
34 static std::string trim(const std::string& s);
35
49 static unsigned int split(std::vector<std::string>& v, const std::string& s, char delimiter,
50 unsigned int maxSegments = INT_MAX);
61 template <typename T>
62 static unsigned int split(T& output, const std::string& s, char delimiter, unsigned int maxSegments = INT_MAX) {
63 std::string::size_type left = 0;
64 unsigned int i;
65 for (i = 1; i < maxSegments; i++) {
66 std::string::size_type right = s.find(delimiter, left);
67 if (right == std::string::npos) {
68 break;
69 }
70 *output++ = s.substr(left, right - left);
71 left = right + 1;
72 }
73
74 *output++ = s.substr(left);
75 return i;
76 }
77 };
78} // namespace log4cpp
79
80#endif // _LOG4CPP_STRINGUTIL_HH
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:78
static unsigned int split(std::vector< std::string > &v, const std::string &s, char delimiter, unsigned int maxSegments=INT_MAX)
splits a string into a vector of string segments based on the given delimiter.
Definition StringUtil.cpp:97
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:62
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:67