fgerlits commented on a change in pull request #964:
URL: https://github.com/apache/nifi-minifi-cpp/pull/964#discussion_r552482386
##########
File path: libminifi/src/utils/StringUtils.cpp
##########
@@ -94,37 +94,39 @@ bool StringUtils::StringToFloat(std::string input, float
&output, FailurePolicy
return true;
}
-std::string StringUtils::replaceEnvironmentVariables(std::string&
original_string) {
- int32_t beg_seq = 0;
- int32_t end_seq = 0;
- std::string source_string = original_string;
+std::string StringUtils::replaceEnvironmentVariables(std::string
source_string) {
+ std::string::size_type beg_seq = 0;
+ std::string::size_type end_seq = 0;
do {
beg_seq = source_string.find("${", beg_seq);
+ if (beg_seq == std::string::npos) {
+ break;
+ }
if (beg_seq > 0 && source_string.at(beg_seq - 1) == '\\') {
beg_seq += 2;
continue;
}
- if (beg_seq < 0)
- break;
end_seq = source_string.find("}", beg_seq + 2);
- if (end_seq < 0)
+ if (end_seq == std::string::npos) {
break;
- if (end_seq - (beg_seq + 2) < 0) {
+ }
+ if (end_seq <= beg_seq + 2) {
beg_seq += 2;
continue;
}
- const std::string env_field = source_string.substr(beg_seq + 2, end_seq -
(beg_seq + 2));
- const std::string env_field_wrapped = source_string.substr(beg_seq,
end_seq + 1);
- if (env_field.empty()) {
+ auto env_var_length = end_seq - (beg_seq + 2);
+ const std::string env_var = source_string.substr(beg_seq + 2,
env_var_length);
+ const std::string env_var_wrapped = source_string.substr(beg_seq,
env_var_length + 3);
+ if (env_var.empty()) {
Review comment:
Good point. I have removed it.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]