|
1
|
1 #include "pfc-lite.h"
|
|
|
2 #include "pfc.h"
|
|
|
3 #include "splitString.h"
|
|
|
4 #include "splitString2.h"
|
|
|
5
|
|
|
6 namespace {
|
|
|
7 class counter_t {
|
|
|
8 public:
|
|
|
9 size_t count = 0;
|
|
|
10 inline void operator+=(pfc::string_part_ref const& p) { (void)p; ++count; }
|
|
|
11 };
|
|
|
12 template<typename ret_t>
|
|
|
13 class wrapper_t {
|
|
|
14 public:
|
|
|
15 ret_t * ret;
|
|
|
16
|
|
|
17 inline void operator+=(pfc::string_part_ref const & p) {
|
|
|
18 ret->emplace_back(p);
|
|
|
19 }
|
|
|
20 };
|
|
|
21 }
|
|
|
22
|
|
|
23 namespace pfc {
|
|
|
24
|
|
|
25 std::list<pfc::string8> splitString2(const char* str, const char* delim) {
|
|
|
26 std::list<pfc::string8> ret;
|
|
|
27 wrapper_t<decltype(ret)> w; w.ret = &ret;
|
|
|
28 pfc::splitStringBySubstring(w, str, delim);
|
|
|
29 return ret;
|
|
|
30 }
|
|
|
31 std::list<pfc::string8> splitStringByLines2(const char* str) {
|
|
|
32 std::list<pfc::string8> ret;
|
|
|
33 wrapper_t<decltype(ret)> w; w.ret = &ret;
|
|
|
34 pfc::splitStringByLines(w, str);
|
|
|
35 return ret;
|
|
|
36 }
|
|
|
37
|
|
|
38 std::vector<pfc::string8> splitString2v(const char* str, const char* delim) {
|
|
|
39 counter_t counter;
|
|
|
40 pfc::splitStringBySubstring(counter, str, delim);
|
|
|
41 std::vector<pfc::string8> ret; ret.reserve(counter.count);
|
|
|
42 wrapper_t<decltype(ret)> w; w.ret = &ret;
|
|
|
43 pfc::splitStringBySubstring(w, str, delim);
|
|
|
44 return ret;
|
|
|
45
|
|
|
46 }
|
|
|
47 std::vector<pfc::string8> splitStringByLines2v(const char* str) {
|
|
|
48 counter_t counter;
|
|
|
49 pfc::splitStringByLines(counter, str);
|
|
|
50 std::vector<pfc::string8> ret; ret.reserve(counter.count);
|
|
|
51 wrapper_t<decltype(ret)> w; w.ret = &ret;
|
|
|
52 pfc::splitStringByLines(w, str);
|
|
|
53 return ret;
|
|
|
54 }
|
|
|
55
|
|
|
56 } |