adamdebreceni commented on a change in pull request #1168:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1168#discussion_r739256508



##########
File path: libminifi/include/utils/StringUtils.h
##########
@@ -146,22 +160,28 @@ class StringUtils {
 
   static std::string& replaceAll(std::string& source_string, const std::string 
&from_string, const std::string &to_string);
 
-  inline static bool endsWithIgnoreCase(const std::string &value, const 
std::string & endString) {
-    if (endString.size() > value.size())
+  inline static bool startsWith(const std::string_view& value, const 
std::string_view& start, bool case_sensitive = true) {
+    if (start.length() > value.length()) {
       return false;
-    return std::equal(endString.rbegin(), endString.rend(), value.rbegin(), 
[](unsigned char lc, unsigned char rc) {return tolower(lc) == tolower(rc);});
+    }
+    if (case_sensitive) {
+      return std::equal(start.begin(), start.end(), value.begin());
+    }
+    return std::equal(start.begin(), start.end(), value.begin(), [](unsigned 
char lc, unsigned char rc) {return tolower(lc) == tolower(rc);});
   }
 
-  inline static bool startsWith(const std::string& value, const std::string& 
start_string) {
-    if (start_string.size() > value.size())
+  inline static bool endsWith(const std::string_view& value, const 
std::string_view& end, bool case_sensitive = true) {
+    if (end.length() > value.length()) {
       return false;
-    return std::equal(start_string.begin(), start_string.end(), value.begin());
+    }
+    if (case_sensitive) {
+      return std::equal(end.rbegin(), end.rend(), value.rbegin());
+    }
+    return std::equal(end.rbegin(), end.rend(), value.rbegin(), [](unsigned 
char lc, unsigned char rc) {return tolower(lc) == tolower(rc);});
   }
 
-  inline static bool endsWith(const std::string& value, const std::string& 
end_string) {
-    if (end_string.size() > value.size())
-      return false;
-    return std::equal(end_string.rbegin(), end_string.rend(), value.rbegin());
+  inline static bool endsWithIgnoreCase(const std::string_view& value, const 
std::string_view& endString) {

Review comment:
       removed it in favor of the more frequently used `endsWith`

##########
File path: libminifi/include/utils/StringUtils.h
##########
@@ -146,22 +160,28 @@ class StringUtils {
 
   static std::string& replaceAll(std::string& source_string, const std::string 
&from_string, const std::string &to_string);
 
-  inline static bool endsWithIgnoreCase(const std::string &value, const 
std::string & endString) {
-    if (endString.size() > value.size())
+  inline static bool startsWith(const std::string_view& value, const 
std::string_view& start, bool case_sensitive = true) {

Review comment:
       added tests




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