Skip to content

Commit f3b4e20

Browse files
committed
readme
1 parent 13b88fc commit f3b4e20

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# String Split implementation in C++
2+
3+
### Source Code
4+
5+
```c++
6+
auto split(std::vector<std::string> &result, std::string_view s, std::string_view t) -> std::vector<std::string> &
7+
{
8+
9+
if (t.empty())
10+
{
11+
result.emplace_back(s);
12+
return result;
13+
}
14+
15+
result.reserve(s.size());
16+
17+
if (!s.empty())
18+
{
19+
std::size_t first = 0;
20+
while (first < s.size())
21+
{
22+
const auto foundIndex = s.find(t, first);
23+
const auto last = foundIndex < s.size() ? foundIndex : s.size();
24+
result.emplace_back(s.begin() + first, s.begin() + last);
25+
first = last + t.size();
26+
}
27+
}
28+
return result;
29+
}
30+
```
31+
32+
benchmark results between
33+
34+
> - Boost string split
35+
> - Stackoverflow solution for split
36+
> - Split function that I wrote
37+
38+
![](assets/benchmark.png)

assets/benchmark.png

14.3 KB
Loading

0 commit comments

Comments
 (0)