1 | #include <iostream>
|
---|
2 | #include <string>
|
---|
3 | #include <vector>
|
---|
4 |
|
---|
5 | #include <boost/algorithm/string.hpp>
|
---|
6 |
|
---|
7 | template <typename TCharString, typename TArg>
|
---|
8 | void Test(const TCharString& string_to_split, const TArg& split_by) {
|
---|
9 | std::vector<TCharString> result;
|
---|
10 |
|
---|
11 | boost::algorithm::split(result, string_to_split, boost::algorithm::is_any_of(split_by));
|
---|
12 |
|
---|
13 | std::cout << "[";
|
---|
14 | for (const auto& line : result) {
|
---|
15 | std::cout << "\"";
|
---|
16 |
|
---|
17 | for (const auto symbol : line) {
|
---|
18 | if (symbol == 0) {
|
---|
19 | std::cout << "\\0";
|
---|
20 | } else {
|
---|
21 | std::cout << (char)symbol; // Not very good with char16_t, but enough to show the problem
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | std::cout << "\", ";
|
---|
26 | }
|
---|
27 |
|
---|
28 | std::cout << "]" << std::endl;
|
---|
29 | }
|
---|
30 |
|
---|
31 | int main() {
|
---|
32 | {
|
---|
33 | std::string str_to_split("a\0b\tc", 5);
|
---|
34 |
|
---|
35 | Test(str_to_split, "\t"); // Outputs: ["a\0b", "c", ] --- correct
|
---|
36 | Test(str_to_split, std::string("\t")); // Outputs: ["a\0b", "c", ] --- correct
|
---|
37 | }
|
---|
38 |
|
---|
39 | {
|
---|
40 | std::u16string str_to_split(u"a\0b\tc", 5);
|
---|
41 |
|
---|
42 | Test(str_to_split, u"\t"); // Outputs: ["a", "b", "c", ] --- incorrect
|
---|
43 | Test(str_to_split, std::u16string(u"\t")); // Outputs: ["a\0b", "c", ] --- correct
|
---|
44 | }
|
---|
45 | }
|
---|