Loading...
Searching...
No Matches
StringUtil.hh
Go to the documentation of this file.
/*
* StringUtil.hh
*
* Copyright 2002, Log4cpp Project. All rights reserved.
*
* See the COPYING file for the terms of usage and distribution.
*/
#ifndef _LOG4SHIB_STRINGUTIL_HH
#define _LOG4SHIB_STRINGUTIL_HH
#include "PortabilityImpl.hh"
#include <string>
#include <vector>
#include <climits>
#include <stdarg.h>
namespace log4shib {
class StringUtil {
public:
static std::string vform(const char* format, va_list args);
static std::string trim(const std::string& s);
static unsigned int split(std::vector<std::string>& v,
const std::string& s, char delimiter,
unsigned int maxSegments = INT_MAX);
template<typename T> static unsigned int split(T& output,
const std::string& s, char delimiter,
unsigned int maxSegments = INT_MAX) {
std::string::size_type left = 0;
unsigned int i;
for(i = 1; i < maxSegments; i++) {
std::string::size_type right = s.find(delimiter, left);
if (right == std::string::npos) {
break;
}
*output++ = s.substr(left, right - left);
left = right + 1;
}
*output++ = s.substr(left);
return i;
}
};
}
#endif // _LOG4SHIB_STRINGUTIL_HH
PortabilityImpl.hh
log4shib::StringUtil
Definition StringUtil.hh:20
log4shib::StringUtil::split
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
log4shib::StringUtil::trim
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:70
log4shib::StringUtil::vform
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
log4shib::StringUtil::split
static unsigned int split(std::vector< std::string > &v, const std::string &s, char delimiter, unsigned int maxSegments=INT_MAX)
Definition StringUtil.cpp:89
log4shib
The top level namespace for all 'Log for C++' types and classes.
Definition AbortAppender.hh:16