File tree Expand file tree Collapse file tree 1 file changed +11
-13
lines changed
src/actions/transformations Expand file tree Collapse file tree 1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -25,29 +25,27 @@ CompressWhitespace::CompressWhitespace(const std::string &action)
25
25
}
26
26
27
27
bool CompressWhitespace::transform (std::string &value, const Transaction *trans) const {
28
+ bool inWhiteSpace = false ;
28
29
29
- std::string a;
30
- int inWhiteSpace = 0 ;
31
- int i = 0 ;
30
+ auto d = value.data ();
32
31
33
- while (i < value. size () ) {
34
- if (isspace (value[i] )) {
32
+ for ( const auto c : value) {
33
+ if (isspace (c )) {
35
34
if (inWhiteSpace) {
36
- i++;
37
35
continue ;
38
36
} else {
39
- inWhiteSpace = 1 ;
40
- a. append ( " " , 1 ) ;
37
+ inWhiteSpace = true ;
38
+ *d++ = ' ' ;
41
39
}
42
40
} else {
43
- inWhiteSpace = 0 ;
44
- a. append (&value. at (i), 1 ) ;
41
+ inWhiteSpace = false ;
42
+ *d++ = c ;
45
43
}
46
- i++;
47
44
}
48
45
49
- const auto changed = a != value;
50
- value = a;
46
+ const auto new_len = d - value.c_str ();
47
+ const auto changed = new_len != value.length ();
48
+ value.resize (new_len);
51
49
return changed;
52
50
}
53
51
You can’t perform that action at this time.
0 commit comments