File tree Expand file tree Collapse file tree 3 files changed +26
-24
lines changed
src/actions/transformations Expand file tree Collapse file tree 3 files changed +26
-24
lines changed Original file line number Diff line number Diff line change 16
16
17
17
#include " lower_case.h"
18
18
19
- #include < locale >
19
+ #include < cctype >
20
20
21
21
22
22
namespace modsecurity ::actions::transformations {
@@ -26,17 +26,9 @@ LowerCase::LowerCase(const std::string &a)
26
26
: Transformation(a) {
27
27
}
28
28
29
- bool LowerCase::transform (std::string &val, const Transaction *trans) const {
30
- std::locale loc;
31
- std::string value (val);
32
-
33
- for (std::string::size_type i=0 ; i < value.length (); ++i) {
34
- value[i] = std::tolower (value[i], loc);
35
- }
36
-
37
- const auto changed = val != value;
38
- val = value;
39
- return changed;
29
+ bool LowerCase::transform (std::string &value, const Transaction *trans) const {
30
+ return convert (value, [](auto c) {
31
+ return std::tolower (c); });
40
32
}
41
33
42
34
Original file line number Diff line number Diff line change 18
18
19
19
#include " transformation.h"
20
20
21
+ #include < algorithm>
22
+
21
23
namespace modsecurity ::actions::transformations {
22
24
23
25
class LowerCase : public Transformation {
24
26
public:
25
27
explicit LowerCase (const std::string &action);
26
28
27
29
bool transform (std::string &value, const Transaction *trans) const override ;
30
+
31
+ template <typename Operation>
32
+ static bool convert (std::string &val, Operation op) {
33
+ bool changed = false ;
34
+
35
+ std::transform (val.begin (), val.end (), val.data (),
36
+ [&](auto c) {
37
+ const auto nc = op (c);
38
+ if (nc != c) changed = true ;
39
+ return nc; });
40
+
41
+ return changed;
42
+ }
28
43
};
29
44
30
45
} // namespace modsecurity::actions::transformations
Original file line number Diff line number Diff line change 16
16
17
17
#include " upper_case.h"
18
18
19
- #include < locale>
19
+ #include < cctype>
20
+
21
+ #include " lower_case.h"
22
+
20
23
21
24
namespace modsecurity ::actions::transformations {
22
25
@@ -25,17 +28,9 @@ UpperCase::UpperCase(const std::string &a)
25
28
: Transformation(a) {
26
29
}
27
30
28
- bool UpperCase::transform (std::string &val, const Transaction *trans) const {
29
- std::string value (val);
30
- std::locale loc;
31
-
32
- for (std::string::size_type i=0 ; i < value.length (); ++i) {
33
- value[i] = std::toupper (value[i], loc);
34
- }
35
-
36
- const auto changed = val != value;
37
- val = value;
38
- return changed;
31
+ bool UpperCase::transform (std::string &value, const Transaction *trans) const {
32
+ return LowerCase::convert (value, [](auto c)
33
+ { return std::toupper (c); });
39
34
}
40
35
41
36
You can’t perform that action at this time.
0 commit comments