fgerlits commented on a change in pull request #1138:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1138#discussion_r678420263



##########
File path: libminifi/src/utils/file/FileMatcher.cpp
##########
@@ -0,0 +1,273 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/file/FileMatcher.h"
+#include "utils/file/FileUtils.h"
+#include "utils/StringUtils.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace file {
+
+std::shared_ptr<core::logging::Logger> FileMatcher::FilePattern::logger_ = 
logging::LoggerFactory<FileMatcher::FilePattern>::getLogger();
+std::shared_ptr<core::logging::Logger> FileMatcher::logger_ = 
logging::LoggerFactory<FileMatcher>::getLogger();
+
+static bool isGlobPattern(const std::string& pattern) {
+  return pattern.find_first_of("?*") != std::string::npos;
+}
+
+static std::vector<std::string> split(const std::string& str, const 
std::vector<std::string>& delimiters) {
+  std::vector<std::string> result;
+
+  size_t prev_delim_end = 0;
+  size_t next_delim_begin = std::string::npos;
+  do {
+    for (const auto& delim : delimiters) {
+      next_delim_begin = str.find(delim, prev_delim_end);
+      if (next_delim_begin != std::string::npos) {
+        result.push_back(str.substr(prev_delim_end, next_delim_begin - 
prev_delim_end));
+        prev_delim_end = next_delim_begin + delim.length();
+        break;
+      }
+    }
+  } while (next_delim_begin != std::string::npos);
+  result.push_back(str.substr(prev_delim_end));
+  return result;
+}
+
+optional<FileMatcher::FilePattern> 
FileMatcher::FilePattern::fromPattern(std::string pattern, bool log_errors) {
+  bool excluding = false;
+  if (!pattern.empty() && pattern[0] == '!') {

Review comment:
       I would trim whitespace from around `pattern`, and also after `!`.

##########
File path: libminifi/include/utils/file/FileMatcher.h
##########
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <vector>
+#include <set>
+#include <utility>
+#include <memory>
+
+#include "utils/OptionalUtils.h"
+#include "core/logging/Logger.h"
+
+struct FileMatcherTestAccessor;
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace file {
+
+class FileMatcher {
+  friend struct ::FileMatcherTestAccessor;
+  class FilePattern {
+    FilePattern(std::vector<std::string> directory_segments, std::string 
file_pattern, bool excluding)
+      : directory_segments_(std::move(directory_segments)),
+        file_pattern_(std::move(file_pattern)),
+        excluding_(excluding) {}
+
+   public:
+    static optional<FilePattern> fromPattern(std::string pattern, bool 
log_errors = true);

Review comment:
       I couldn't find any place where we call this with `log_errors == false`. 
 If there isn't one, the parameter could be removed.




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