PragmaTwice commented on code in PR #2873:
URL: https://github.com/apache/kvrocks/pull/2873#discussion_r2036582765


##########
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 { NORMAL, QUOTED, SINGLE_QUOTED, ESCAPE } state = NORMAL;
+
+  bool is_quoted = false;
+  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 == '"' ? QUOTED : SINGLE_QUOTED;
+          is_quoted = c == '"';
+        } else {
+          current_string.push_back(c);
+        }
+        break;
+      case QUOTED:
+      case SINGLE_QUOTED:
+        if (c == '\\') {
+          state = ESCAPE;

Review Comment:
   ```suggestion
           if (c == '\\') {
             state_before_escape = state;
             state = ESCAPE;
   ```



-- 
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]

Reply via email to