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



##########
File path: extensions/standard-processors/processors/ReplaceText.h
##########
@@ -0,0 +1,102 @@
+/**
+ * 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 <memory>
+#include <regex>
+#include <string>
+#include <utility>
+
+#include "core/Annotation.h"
+#include "core/Processor.h"
+#include "core/ProcessContext.h"
+#include "core/ProcessSession.h"
+#include "core/ProcessSessionFactory.h"
+#include "core/Resource.h"
+#include "core/logging/Logger.h"
+#include "utils/Enum.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+SMART_ENUM(EvaluationModeType,
+  (LINE_BY_LINE, "Line-by-Line"),
+  (ENTIRE_TEXT, "Entire text")
+)
+
+SMART_ENUM(LineByLineEvaluationModeType,
+  (ALL, "All"),
+  (FIRST_LINE, "First-Line"),
+  (LAST_LINE, "Last-Line"),
+  (EXCEPT_FIRST_LINE, "Except-First-Line"),
+  (EXCEPT_LAST_LINE, "Except-Last-Line")
+)
+
+SMART_ENUM(ReplacementStrategyType,
+  (PREPEND, "Prepend"),
+  (APPEND, "Append"),
+  (REGEX_REPLACE, "Regex Replace"),
+  (LITERAL_REPLACE, "Literal Replace"),
+  (ALWAYS_REPLACE, "Always Replace"),
+  (SUBSTITUTE_VARIABLES, "Substitute Variables")
+)
+
+class ReplaceText : public core::Processor {
+ public:
+  static const core::Property EvaluationMode;
+  static const core::Property LineByLineEvaluationMode;
+  static const core::Property ReplacementStrategy;
+  static const core::Property MaximumBufferSize;
+  static const core::Property SearchValue;
+  static const core::Property ReplacementValue;
+
+  static const core::Relationship Success;
+  static const core::Relationship Failure;
+
+  explicit ReplaceText(const std::string& name, const utils::Identifier& uuid 
= {});
+  core::annotation::Input getInputRequirement() const override;
+  void initialize() override;
+  void onSchedule(const std::shared_ptr<core::ProcessContext>& context, const 
std::shared_ptr<core::ProcessSessionFactory>&) override;
+  void onTrigger(const std::shared_ptr<core::ProcessContext>& context, const 
std::shared_ptr<core::ProcessSession>& session) override;
+
+ private:
+  friend struct ReplaceTextTestAccessor;
+
+  void readSearchValueProperty(const std::shared_ptr<core::ProcessContext>& 
context, const std::shared_ptr<core::FlowFile>& flow_file);
+  void readReplacementValueProperty(const 
std::shared_ptr<core::ProcessContext>& context, const 
std::shared_ptr<core::FlowFile>& flow_file);
+
+  void replaceTextInEntireFile(const std::shared_ptr<core::FlowFile>& 
flow_file, const std::shared_ptr<core::ProcessSession>& session) const;
+  void replaceTextLineByLine(const std::shared_ptr<core::FlowFile>& flow_file, 
const std::shared_ptr<core::ProcessSession>& session) const;
+
+  std::string applyReplacements(const std::string& input, const 
std::shared_ptr<core::FlowFile>& flow_file) const;
+  std::string applyRegexReplace(const std::string& input) const;
+  std::string applyLiteralReplace(const std::string& input) const;
+  std::string applySubstituteVariables(const std::string& input, const 
std::shared_ptr<core::FlowFile>& flow_file) const;
+  std::string getAttributeValue(const std::shared_ptr<core::FlowFile>& 
flow_file, const std::smatch& match) const;
+
+  std::shared_ptr<logging::Logger> logger_;
+  std::string search_value_;
+  std::regex search_regex_;
+  std::string replacement_value_;
+  uint64_t maximum_buffer_size_ = 0;
+  EvaluationModeType evaluation_mode_ = EvaluationModeType::LINE_BY_LINE;
+  LineByLineEvaluationModeType line_by_line_evaluation_mode_ = 
LineByLineEvaluationModeType::ALL;
+  ReplacementStrategyType replacement_strategy_ = 
ReplacementStrategyType::REGEX_REPLACE;
+};
+
+REGISTER_RESOURCE(ReplaceText, "Updates the content of a FlowFile by replacing 
parts of it using various replacement strategies.");

Review comment:
       OK, I'll move it after #1138 is merged.




-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to