Alexandria
2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
AlexandriaKernel
AlexandriaKernel
StringUtils.h
Go to the documentation of this file.
1
19
#ifndef _ALEXANDRIAKERNEL_STRINGUTILS_H
20
#define _ALEXANDRIAKERNEL_STRINGUTILS_H
21
22
#include <boost/algorithm/string/classification.hpp>
23
#include <boost/algorithm/string/split.hpp>
24
#include <boost/algorithm/string/trim.hpp>
25
#include <boost/lexical_cast.hpp>
26
#include <vector>
27
28
#include <
ElementsKernel/Exception.h
>
29
30
namespace
Euclid
{
31
43
template
<
typename
T>
44
std::vector<T>
stringToVector
(
std::string
str,
const
std::string
& separators =
std::string
(
", "
)) {
45
std::vector<std::string>
parts;
46
boost::trim(str);
47
boost::split(parts, str, boost::is_any_of(separators), boost::token_compress_on);
48
std::vector<T>
result(parts.
size
());
49
try
{
50
std::transform
(parts.
begin
(), parts.
end
(), result.
begin
(), boost::lexical_cast<T, const std::string&>);
51
}
catch
(
const
boost::bad_lexical_cast& e) {
52
throw
Elements::Exception
(e.what());
53
}
54
return
result;
55
}
56
57
}
/* namespace Euclid */
58
59
#endif
/* _ALEXANDRIAKERNEL_STRINGUTILS_H */
Exception.h
std::string
std::vector::begin
T begin(T... args)
Elements::Exception
std::vector::end
T end(T... args)
Euclid
Definition
index_sequence.h:27
Euclid::stringToVector
std::vector< T > stringToVector(std::string str, const std::string &separators=std::string(", "))
Definition
StringUtils.h:44
std::vector::size
T size(T... args)
std::transform
T transform(T... args)
std::vector
Generated by
1.9.8