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


##########
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:

Review Comment:
   [nitpick] Consider handling unknown escape sequences explicitly in the 
ESCAPE state rather than silently ignoring unrecognized escape characters. This 
would improve the clarity and robustness of the parsing logic.



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