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


##########
src/common/string_util.cc:
##########
@@ -276,6 +276,107 @@ std::pair<std::string, std::string> 
SplitGlob(std::string_view glob) {
   return {prefix, ""};
 }
 
+static int hexDigitToInt(const char c) {
+  if (c >= '0' && c <= '9') {
+    return c - '0';
+  } else if (c >= 'a' && c <= 'f') {
+    return c - 'a' + 10;
+  } else if (c >= 'A' && c <= 'F') {
+    return c - 'A' + 10;
+  }
+}
+
+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;
+
+  bool done = false;
+  for (size_t i = 0; i < in.size() && !done; i++) {
+    const auto c = in[i];
+    switch (state) {
+      case NORMAL:
+        if (std::isspace(c)) {
+          if (!current_string.empty()) {
+            arguments.emplace_back(std::move(current_string));
+            current_string.clear();
+          }
+        } else if (c == '\r' || c == '\n' || c == '\t') {
+          done = true;
+        } else if (c == '"') {
+          state = DOUBLE_QUOTED;
+        } else if (c == '\'') {
+          state = SINGLE_QUOTED;
+        } else {
+          current_string.push_back(c);
+        }
+        break;
+      case SINGLE_QUOTED:
+        if (c == '\\' && (i + 1) < in.size() && in[i + 1] == '\'') {
+          current_string.push_back('\'');
+          i++;
+        } else if (c == '\'') {
+          //
+          if (i + 1 < in.size() && !std::isspace(in[i + 1])) {
+            return {Status::NotOK, "the closed single quote must be followed 
by a space"};
+          }
+          state = NORMAL;
+        } else {
+          current_string.push_back(c);
+        }
+        break;
+      case DOUBLE_QUOTED:
+        if (c == '\\') {
+          state = ESCAPE;
+        } else if (c == '"') {
+          //

Review Comment:
   Remove this line?



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