2305 |
02 Aug 10 |
peter |
// $Id$ |
2305 |
02 Aug 10 |
peter |
2 |
|
2305 |
02 Aug 10 |
peter |
3 |
/* |
4348 |
02 Jul 23 |
peter |
Copyright (C) 2010, 2012, 2022, 2023 Peter Johansson |
2305 |
02 Aug 10 |
peter |
5 |
|
2305 |
02 Aug 10 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2305 |
02 Aug 10 |
peter |
7 |
|
2305 |
02 Aug 10 |
peter |
The yat library is free software; you can redistribute it and/or |
2305 |
02 Aug 10 |
peter |
modify it under the terms of the GNU General Public License as |
2305 |
02 Aug 10 |
peter |
published by the Free Software Foundation; either version 3 of the |
2305 |
02 Aug 10 |
peter |
License, or (at your option) any later version. |
2305 |
02 Aug 10 |
peter |
12 |
|
2305 |
02 Aug 10 |
peter |
The yat library is distributed in the hope that it will be useful, |
2305 |
02 Aug 10 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2305 |
02 Aug 10 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2305 |
02 Aug 10 |
peter |
General Public License for more details. |
2305 |
02 Aug 10 |
peter |
17 |
|
2305 |
02 Aug 10 |
peter |
You should have received a copy of the GNU General Public License |
2305 |
02 Aug 10 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2305 |
02 Aug 10 |
peter |
20 |
*/ |
2305 |
02 Aug 10 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
2305 |
02 Aug 10 |
peter |
24 |
#include "split.h" |
2305 |
02 Aug 10 |
peter |
25 |
|
4193 |
12 Aug 22 |
peter |
26 |
#include <boost/algorithm/string/classification.hpp> |
4193 |
12 Aug 22 |
peter |
27 |
#include <boost/algorithm/string/split.hpp> |
4193 |
12 Aug 22 |
peter |
28 |
|
4197 |
14 Aug 22 |
peter |
29 |
#include <iterator> |
2305 |
02 Aug 10 |
peter |
30 |
#include <string> |
2305 |
02 Aug 10 |
peter |
31 |
#include <vector> |
2305 |
02 Aug 10 |
peter |
32 |
|
2305 |
02 Aug 10 |
peter |
33 |
namespace theplu { |
2305 |
02 Aug 10 |
peter |
34 |
namespace yat { |
2305 |
02 Aug 10 |
peter |
35 |
namespace utility { |
2305 |
02 Aug 10 |
peter |
36 |
|
4196 |
14 Aug 22 |
peter |
37 |
namespace detail { |
4196 |
14 Aug 22 |
peter |
38 |
|
4196 |
14 Aug 22 |
peter |
39 |
template<class Predicate> |
4196 |
14 Aug 22 |
peter |
40 |
void split(std::vector<std::string>& vec, const std::string& str, |
4196 |
14 Aug 22 |
peter |
41 |
const Predicate& pred) |
4196 |
14 Aug 22 |
peter |
42 |
{ |
4348 |
02 Jul 23 |
peter |
43 |
if (vec.empty()) { |
4348 |
02 Jul 23 |
peter |
44 |
boost::split(vec, str, pred); |
4348 |
02 Jul 23 |
peter |
45 |
} |
4196 |
14 Aug 22 |
peter |
46 |
else { |
4348 |
02 Jul 23 |
peter |
47 |
std::vector<std::string> v; |
4348 |
02 Jul 23 |
peter |
48 |
boost::split(v, str, pred); |
4196 |
14 Aug 22 |
peter |
49 |
vec.insert(vec.end(), std::make_move_iterator(v.begin()), |
4196 |
14 Aug 22 |
peter |
50 |
std::make_move_iterator(v.end())); |
4196 |
14 Aug 22 |
peter |
51 |
} |
4196 |
14 Aug 22 |
peter |
52 |
} |
4196 |
14 Aug 22 |
peter |
53 |
|
4196 |
14 Aug 22 |
peter |
54 |
} |
4196 |
14 Aug 22 |
peter |
55 |
|
2879 |
16 Nov 12 |
peter |
56 |
void split(std::vector<std::string>& vec, const std::string& str, char delim) |
2879 |
16 Nov 12 |
peter |
57 |
{ |
4196 |
14 Aug 22 |
peter |
58 |
detail::split(vec, str, [delim](char c) { return c==delim; }); |
2879 |
16 Nov 12 |
peter |
59 |
} |
2879 |
16 Nov 12 |
peter |
60 |
|
2879 |
16 Nov 12 |
peter |
61 |
|
2879 |
16 Nov 12 |
peter |
62 |
void split(std::vector<std::string>& vec, const std::string& str, |
2879 |
16 Nov 12 |
peter |
63 |
const std::string& delim) |
2879 |
16 Nov 12 |
peter |
64 |
{ |
4196 |
14 Aug 22 |
peter |
65 |
detail::split(vec, str, boost::is_any_of(delim)); |
2879 |
16 Nov 12 |
peter |
66 |
} |
2879 |
16 Nov 12 |
peter |
67 |
|
2305 |
02 Aug 10 |
peter |
68 |
}}} // of namespace utility, yat, and theplu |