HuaHuaY commented on code in PR #51286:
URL: https://github.com/apache/arrow/pull/51286#discussion_r4399186738


##########
cpp/src/arrow/csv/lexing_internal.h:
##########
@@ -61,6 +64,58 @@ decltype(auto) DispatchBool(Fn&& fn, Rest... rest)
   }
 }
 
+inline std::string_view GetDelimiter(const ParseOptions& options) {
+  if (!options.delimiter_string.empty()) {
+    return options.delimiter_string;
+  }
+  return {&options.delimiter, 1};
+}
+
+inline char GetDelimiterFirstByte(const ParseOptions& options) {
+  if (!options.delimiter_string.empty()) {
+    return options.delimiter_string.front();
+  }
+  return options.delimiter;
+}
+
+class StreamingDelimiterMatcher {
+ public:
+  explicit StreamingDelimiterMatcher(std::string_view delimiter) : 
delimiter_(delimiter) {
+    DCHECK(!delimiter_.empty());
+  }
+
+  bool Consume(char c) {
+    if (c == delimiter_[matched_]) {
+      matched_++;
+      if (matched_ == delimiter_.size()) {
+        matched_ = 0;
+        return true;
+      }
+      return false;
+    }
+
+    const std::string_view delimiter(delimiter_);
+    for (size_t length = matched_; length > 0; --length) {
+      if (c == delimiter[length - 1] &&
+          delimiter.substr(0, length - 1) ==
+              delimiter.substr(matched_ - (length - 1), length - 1)) {

Review Comment:
   My thinking is that although the delimiter can consist of multiple 
characters, it’s usually not very long. I’m concerned that the constant-time 
overhead introduced by an algorithm like KMP might end up being greater than 
that of a straightforward search.



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