File tree Expand file tree Collapse file tree 4 files changed +29
-34
lines changed
src/actions/transformations Expand file tree Collapse file tree 4 files changed +29
-34
lines changed Original file line number Diff line number Diff line change 19
19
namespace modsecurity ::actions::transformations {
20
20
21
21
22
- std::string *Trim::ltrim (std::string *s) {
23
- s->erase (
24
- s->begin (),
25
- std::find_if (s->begin (), s->end (), [](unsigned char c) {
22
+ bool Trim::ltrim (std::string &s) {
23
+ auto it = std::find_if (s.begin (), s.end (), [](unsigned char c) {
26
24
return !std::isspace (c);
27
- })
28
- );
25
+ });
29
26
30
- return s;
27
+ const bool changed = it != s.begin ();
28
+
29
+ s.erase (s.begin (), it);
30
+
31
+ return changed;
31
32
}
32
33
33
34
34
- std::string *Trim::rtrim (std::string *s) {
35
- s->erase (
36
- std::find_if (s->rbegin (), s->rend (), [](unsigned char c) {
35
+ bool Trim::rtrim (std::string &s) {
36
+ auto it = std::find_if (s.rbegin (), s.rend (), [](unsigned char c) {
37
37
return !std::isspace (c);
38
- }).base (),
39
- s-> end ()
40
- );
38
+ }).base ();
39
+
40
+ const bool changed = it != s. end ( );
41
41
42
- return s;
42
+ s.erase (it, s.end ());
43
+
44
+ return changed;
43
45
}
44
46
45
47
46
- std::string *Trim::trim (std::string *s) {
47
- return ltrim (rtrim (s));
48
+ bool Trim::trim (std::string &s) {
49
+ bool changed = false ;
50
+ changed |= rtrim (s);
51
+ changed |= ltrim (s);
52
+ return changed;
48
53
}
49
54
50
55
@@ -55,11 +60,7 @@ Trim::Trim(const std::string &action)
55
60
56
61
57
62
bool Trim::transform (std::string &value, const Transaction *trans) const {
58
- std::string ret (value);
59
- this ->trim (&ret);
60
- const auto changed = ret != value;
61
- value = ret;
62
- return changed;
63
+ return trim (value);
63
64
}
64
65
65
66
Original file line number Diff line number Diff line change @@ -26,9 +26,11 @@ class Trim : public Transformation {
26
26
27
27
bool transform (std::string &value, const Transaction *trans) const override ;
28
28
29
- static std::string *ltrim (std::string *s);
30
- static std::string *rtrim (std::string *s);
31
- static std::string *trim (std::string *s);
29
+ protected:
30
+
31
+ static bool ltrim (std::string &s);
32
+ static bool rtrim (std::string &s);
33
+ static bool trim (std::string &s);
32
34
};
33
35
34
36
} // namespace modsecurity::actions::transformations
Original file line number Diff line number Diff line change @@ -26,11 +26,7 @@ TrimLeft::TrimLeft(const std::string &action)
26
26
}
27
27
28
28
bool TrimLeft::transform (std::string &value, const Transaction *trans) const {
29
- std::string ret (value);
30
- this ->ltrim (&ret);
31
- const auto changed = ret != value;
32
- value = ret;
33
- return changed;
29
+ return ltrim (value);
34
30
}
35
31
36
32
Original file line number Diff line number Diff line change @@ -25,11 +25,7 @@ TrimRight::TrimRight(const std::string &action)
25
25
}
26
26
27
27
bool TrimRight::transform (std::string &value, const Transaction *trans) const {
28
- std::string ret (value);
29
- this ->rtrim (&ret);
30
- const auto changed = ret != value;
31
- value = ret;
32
- return changed;
28
+ return rtrim (value);
33
29
}
34
30
35
31
You can’t perform that action at this time.
0 commit comments