tisonkun commented on code in PR #644:
URL: https://github.com/apache/incubator-kvrocks/pull/644#discussion_r902397536
##########
src/util.cc:
##########
@@ -371,7 +371,14 @@ std::string Trim(std::string in, const std::string &chars)
{
std::vector<std::string> Split(const std::string &in, const std::string
&delim) {
std::vector<std::string> out;
- if (in.empty() || delim.empty()) return out;
+ if (in.empty()) {
+ return out;
+ }
+
+ if (delim.empty()) {
Review Comment:
Sorry. After take a look at Java's `Spring.split` and C++20's
[`split_view`](https://en.cppreference.com/w/cpp/ranges/split_view), its seems
empty delim will cause output a string vector contains every character as a
string member.
```java
jshell> "123".split("")
$1 ==> String[3] { "1", "2", "3" }
jshell> "1 2 3".split("")
$2 ==> String[5] { "1", " ", "2", " ", "3" }
```
```cpp
#include <iostream>
#include <iomanip>
#include <ranges>
#include <string_view>
int main() {
constexpr std::string_view words{"Hello-_-C++-_-20-_-!"};
constexpr std::string_view delim{""};
for (const auto word : std::views::split(words, delim)) {
std::cout << std::quoted(std::string_view(word.begin(), word.end()))
<< ' ';
}
}
// "H" "e" "l" "l" "o" "-" "_" "-" "C" "+" "+" "-" "_" "-" "2" "0" "-" "_"
"-" "!"
// https://wandbox.org/permlink/5BZQHqUYd36t0WbQ
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]