14
14
*/
15
15
16
16
#include < ctime>
17
- #include < iostream>
18
17
#include < string>
19
18
#include < vector>
19
+ #include < algorithm>
20
+ #include < utility>
20
21
21
22
#ifndef SRC_UTILS_STRING_H_
22
23
#define SRC_UTILS_STRING_H_
@@ -62,8 +63,6 @@ std::string limitTo(int amount, const std::string &str);
62
63
std::string removeBracketsIfNeeded (std::string a);
63
64
std::string string_to_hex (const std::string& input);
64
65
std::string toHexIfNeeded (const std::string &str, bool escape_spec = false );
65
- std::string tolower (std::string str);
66
- std::string toupper (std::string str);
67
66
std::vector<std::string> ssplit (std::string str, char delimiter);
68
67
std::pair<std::string, std::string> ssplit_pair (const std::string& str, char delimiter);
69
68
std::vector<std::string> split (std::string str, char delimiter);
@@ -77,6 +76,28 @@ unsigned char x2c(const unsigned char *what);
77
76
unsigned char xsingle2c (const unsigned char *what);
78
77
unsigned char *c2x (unsigned what, unsigned char *where);
79
78
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
+
80
101
} // namespace string
81
102
} // namespace utils
82
103
} // namespace modsecurity
0 commit comments