Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
string.hh
Go to the documentation of this file.
1#ifndef UTOPIA_CORE_STRING_HH
2#define UTOPIA_CORE_STRING_HH
3
4#include <string>
5#include <vector>
6
7#include <boost/algorithm/string/join.hpp>
8#include <boost/algorithm/string/split.hpp>
9#include <boost/algorithm/string/classification.hpp>
10
11
12namespace Utopia {
13
15
17template<class Cont = std::vector<std::string>>
18std::string join (const Cont& cont, const std::string& delim = ", ") {
19 if (cont.empty()) {
20 return "";
21 }
22 return boost::algorithm::join(cont, delim);
23}
24
26
44template<class SeqCont = std::vector<std::string>>
45SeqCont split (const std::string& s, const std::string& delims = " ") {
46 auto segments = SeqCont{};
47
48 if (s.empty()) {
49 return segments;
50 }
51
52 boost::split(segments, s, boost::is_any_of(delims),
53 boost::algorithm::token_compress_on);
54 return segments;
55}
56
57
58} // namespace Utopia
59
60#endif // UTOPIA_CORE_STRING_HH
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Definition agent.hh:11
SeqCont split(const std::string &s, const std::string &delims=" ")
Splits a string and returns a container of string segments.
Definition string.hh:45
std::string join(const Cont &cont, const std::string &delim=", ")
Joins together the strings in a container.
Definition string.hh:18