1414 */
1515
1616#include < ctime>
17- #include < iostream>
1817#include < string>
1918#include < vector>
19+ #include < algorithm>
20+ #include < utility>
2021
2122#ifndef SRC_UTILS_STRING_H_
2223#define SRC_UTILS_STRING_H_
@@ -62,8 +63,6 @@ std::string limitTo(int amount, const std::string &str);
6263std::string removeBracketsIfNeeded (std::string a);
6364std::string string_to_hex (const std::string& input);
6465std::string toHexIfNeeded (const std::string &str, bool escape_spec = false );
65- std::string tolower (std::string str);
66- std::string toupper (std::string str);
6766std::vector<std::string> ssplit (std::string str, char delimiter);
6867std::pair<std::string, std::string> ssplit_pair (const std::string& str, char delimiter);
6968std::vector<std::string> split (std::string str, char delimiter);
@@ -77,6 +76,28 @@ unsigned char x2c(const unsigned char *what);
7776unsigned char xsingle2c (const unsigned char *what);
7877unsigned char *c2x (unsigned what, unsigned char *where);
7978
79+
80+ template <typename Operation>
81+ inline std::string toCaseHelper (std::string str, Operation op) {
82+ std::transform (str.begin (),
83+ str.end (),
84+ str.begin (),
85+ op);
86+
87+ return str;
88+ }
89+
90+
91+ inline std::string tolower (std::string str) { // cppcheck-suppress passedByValue ; copied value is used for in-place transformation
92+ return toCaseHelper (str, ::tolower);
93+ }
94+
95+
96+ inline std::string toupper (std::string str) { // cppcheck-suppress passedByValue ; copied value is used for in-place transformation
97+ return toCaseHelper (str, ::toupper);
98+ }
99+
100+
80101} // namespace string
81102} // namespace utils
82103} // namespace modsecurity
0 commit comments