fgerlits commented on code in PR #1987:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1987#discussion_r2549500280


##########
libminifi/src/utils/CProcessor.cpp:
##########
@@ -0,0 +1,55 @@
+/**
+* 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/CProcessor.h"
+
+namespace org::apache::nifi::minifi::utils {
+
+std::vector<minifi::state::PublishedMetric> CProcessor::getCustomMetrics() 
const {
+  if (class_description_.callbacks.calculateMetrics == nullptr) {
+    return {};
+  }
+  std::unique_ptr<std::vector<minifi::state::PublishedMetric>> 
metrics{reinterpret_cast<std::vector<minifi::state::PublishedMetric>*>(class_description_.callbacks.calculateMetrics(impl_))};
+  return *metrics;
+}
+
+std::vector<minifi::state::response::SerializedResponseNode> 
CProcessorMetricsWrapper::serialize() {
+  std::vector<minifi::state::response::SerializedResponseNode> nodes;
+  for (auto& custom_node : source_processor_.getCustomMetrics()) {
+    size_t transformed_name_length = 0;
+    bool should_uppercase_next_letter = true;
+    for (size_t i = 0; i < custom_node.name.size(); i++) {
+      if (should_uppercase_next_letter) {
+        custom_node.name[transformed_name_length++] = 
static_cast<char>(std::toupper(static_cast<unsigned 
char>(custom_node.name[i])));
+        should_uppercase_next_letter = false;
+      } else if (custom_node.name[i] == '_') {
+        should_uppercase_next_letter = true;

Review Comment:
   I would switch these two conditions, so that underscore characters get 
removed consistently:
   ```suggestion
         if (custom_node.name[i] == '_') {
           should_uppercase_next_letter = true;
         } else if (should_uppercase_next_letter) {
           custom_node.name[transformed_name_length++] = 
static_cast<char>(std::toupper(static_cast<unsigned 
char>(custom_node.name[i])));
           should_uppercase_next_letter = false;
   ```
   
   We could also convert names like `HTTP_GET_count` to `HttpGetCount` (i.e., 
change non-initial letters to lowercase).
   
   Also, this name conversion code should be in its own function, and unit 
tested with examples including multiple underscores, leading/trailing 
underscores, numbers etc.



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