git-hulk commented on code in PR #2873:
URL: https://github.com/apache/kvrocks/pull/2873#discussion_r2041610209
##########
src/common/string_util.cc:
##########
@@ -276,6 +276,71 @@ std::pair<std::string, std::string>
SplitGlob(std::string_view glob) {
return {prefix, ""};
}
+StatusOr<std::vector<std::string>> SplitArguments(std::string_view in) {
+ std::vector<std::string> arguments;
+ std::string current_string;
+
+ enum State { NORMAL, DOUBLE_QUOTED, SINGLE_QUOTED, ESCAPE } state = NORMAL;
+
+ State state_before_escape = NORMAL;
+ for (const char c : in) {
+ switch (state) {
+ case NORMAL:
+ if (std::isspace(c)) {
+ if (!current_string.empty()) {
+ arguments.emplace_back(std::move(current_string));
+ current_string.clear();
+ }
+ // skip spaces
+ } else if (c == '"' || c == '\'') {
+ state = c == '"' ? DOUBLE_QUOTED : SINGLE_QUOTED;
+ } else {
+ current_string.push_back(c);
+ }
+ break;
+ case DOUBLE_QUOTED:
+ case SINGLE_QUOTED:
+ if (c == '\\') {
+ state_before_escape = state;
+ state = ESCAPE;
+ } else if ((c == '"' && state == DOUBLE_QUOTED) || (c == '\'' && state
== SINGLE_QUOTED)) {
+ state = NORMAL;
+ } else {
+ current_string.push_back(c);
+ }
+ break;
+ case ESCAPE:
+ if (c == '"' || c == '\'' || c == '\\') {
+ current_string.push_back(c);
+ } else if (c == 't') {
+ current_string.push_back('\t');
+ } else if (c == 'r') {
+ current_string.push_back('\r');
+ } else if (c == 'n') {
+ current_string.push_back('\n');
+ } else if (c == 'v') {
+ current_string.push_back('\v');
+ } else if (c == 'f') {
+ current_string.push_back('\f');
+ } else if (c == 'b') {
+ current_string.push_back('\b');
+ }
Review Comment:
Oh, I see. Good point. It's now ignored, and we should continue to behave
the same way with Redis. I will fix them when I have time later.
--
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]