log4tango 5.0.2
StringUtil.hh
Go to the documentation of this file.
1//
2// StringUtil.hh
3//
4// Copyright (C) : 2000 - 2002
5// LifeLine Networks BV (www.lifeline.nl). All rights reserved.
6// Bastiaan Bakker. All rights reserved.
7//
8// 2004,2005,2006,2007,2008,2009,2010,2011,2012
9// Synchrotron SOLEIL
10// L'Orme des Merisiers
11// Saint-Aubin - BP 48 - France
12//
13// This file is part of log4tango.
14//
15// Log4ango is free software: you can redistribute it and/or modify
16// it under the terms of the GNU Lesser General Public License as published by
17// the Free Software Foundation, either version 3 of the License, or
18// (at your option) any later version.
19//
20// Log4tango is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23// GNU Lesser General Public License for more details.
24//
25// You should have received a copy of the GNU Lesser General Public License
26// along with Log4Tango. If not, see <http://www.gnu.org/licenses/>.
27
28#ifndef _LOG4TANGO_STRINGUTIL_H
29#define _LOG4TANGO_STRINGUTIL_H
30
31#include "PortabilityImpl.hh"
32#include <string>
33#include <vector>
34#include <climits>
35#include <stdarg.h>
36
37namespace log4tango {
38
40{
41public:
42
49 static std::string vform(const char* format, va_list args);
50
55 static std::string trim(const std::string& s);
56
70 static unsigned int split(std::vector<std::string>& v,
71 const std::string& s, char delimiter,
72 unsigned int maxSegments = INT_MAX);
73
84 template<typename T>
85 static unsigned int split(T& output,
86 const std::string& s, char delimiter,
87 unsigned int maxSegments = INT_MAX)
88 {
89 std::string::size_type left = 0;
90 unsigned int i;
91 for (i = 1; i < maxSegments; i++) {
92 std::string::size_type right = s.find(delimiter, left);
93 if (right == std::string::npos) {
94 break;
95 }
96 *output++ = s.substr(left, right - left);
97 left = right + 1;
98 }
99 *output++ = s.substr(left);
100 return i;
101 }
102};
103
104} // namespace log4tango
105
106#endif // _LOG4TANGO_STRINGUTIL_HH
107
Definition: StringUtil.hh:40
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:98
static std::string vform(const char *format, va_list args)
Returns a string constructed from the a format specifier and a va_list of arguments,...
Definition: StringUtil.cpp:57
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:81
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:85
Definition: Appender.hh:40