lordgamez commented on code in PR #1543:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1543#discussion_r1153389236


##########
libminifi/src/properties/Properties.cpp:
##########
@@ -62,8 +63,100 @@ int Properties::getInt(const std::string &key, int 
default_value) const {
   return it != properties_.end() ? std::stoi(it->second.active_value) : 
default_value;
 }
 
+namespace {
+const core::PropertyValidator* getValidator(const std::string& lookup_value) {
+  auto configuration_property = 
Configuration::CONFIGURATION_PROPERTIES.find(lookup_value);
+
+  if (configuration_property != Configuration::CONFIGURATION_PROPERTIES.end())
+    return configuration_property->second;
+  return nullptr;
+}
+
+std::optional<std::string> 
ensureTimePeriodValidatedPropertyHasExplicitUnit(const core::PropertyValidator* 
const validator, std::string& value) {
+  if (validator != core::StandardValidators::get().TIME_PERIOD_VALIDATOR.get())
+    return std::nullopt;
+  if (value.empty() || !std::all_of(value.begin(), value.end(), ::isdigit))
+    return std::nullopt;
+
+  return value + " ms";
+}
+
+std::optional<std::string> 
ensureDataSizeValidatedPropertyHasExplicitUnit(const core::PropertyValidator* 
const validator, std::string& value) {
+  if (validator != core::StandardValidators::get().DATA_SIZE_VALIDATOR.get())
+    return std::nullopt;
+  if (value.empty() || !std::all_of(value.begin(), value.end(), ::isdigit))
+    return std::nullopt;
+
+  return value + " B";
+}
+
+bool integerValidatedProperty(const core::PropertyValidator* const validator) {
+  return validator == core::StandardValidators::get().INTEGER_VALIDATOR.get()
+      || validator == 
core::StandardValidators::get().UNSIGNED_INT_VALIDATOR.get()
+      || validator == core::StandardValidators::get().LONG_VALIDATOR.get()
+      || validator == 
core::StandardValidators::get().UNSIGNED_LONG_VALIDATOR.get();
+}
+
+std::optional<uint64_t> stringToDataSize(std::string_view input) {
+  int64_t value;
+  std::string unit_str;
+  if (!utils::StringUtils::splitToUnitAndValue(input, unit_str, value))
+    return std::nullopt;
+  if (auto unit_multiplier = core::DataSizeValue::getUnitMultiplier(unit_str)) 
{
+    return value * *unit_multiplier;
+  }

Review Comment:
   Nitpick: inconsistent use of braces on oneliner ifs, same in 
ensureIntegerValidatedPropertyHasNoUnit



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