2
2
3
3
namespace cpptrace {
4
4
namespace detail {
5
- void replace_all (std::string& str, std:: string_view substr, std:: string_view replacement) {
5
+ void replace_all (std::string& str, string_view substr, string_view replacement) {
6
6
std::string::size_type pos = 0 ;
7
- while ((pos = str.find (substr.data (), pos, substr.length ())) != std::string::npos) {
8
- str.replace (pos, substr.length (), replacement.data (), replacement.length ());
9
- pos += replacement.length ();
7
+ while ((pos = str.find (substr.data (), pos, substr.size ())) != std::string::npos) {
8
+ str.replace (pos, substr.size (), replacement.data (), replacement.size ());
9
+ pos += replacement.size ();
10
10
}
11
11
}
12
12
13
- void replace_all (std::string& str, const std::regex& re, std:: string_view replacement) {
13
+ void replace_all (std::string& str, const std::regex& re, string_view replacement) {
14
14
std::smatch match;
15
15
std::size_t i = 0 ;
16
16
while (std::regex_search (str.cbegin () + i, str.cend (), match, re)) {
17
- str.replace (i + match.position (), match.length (), replacement);
18
- i += match.position () + replacement.length ();
17
+ str.replace (i + match.position (), match.length (), replacement. data (), replacement. size () );
18
+ i += match.position () + replacement.size ();
19
19
}
20
20
}
21
21
22
- void replace_all_dynamic (std::string& str, std:: string_view substr, std:: string_view replacement) {
22
+ void replace_all_dynamic (std::string& str, string_view substr, string_view replacement) {
23
23
std::string::size_type pos = 0 ;
24
- while ((pos = str.find (substr.data (), pos, substr.length ())) != std::string::npos) {
25
- str.replace (pos, substr.length (), replacement.data (), replacement.length ());
24
+ while ((pos = str.find (substr.data (), pos, substr.size ())) != std::string::npos) {
25
+ str.replace (pos, substr.size (), replacement.data (), replacement.size ());
26
26
// advancing by one rather than replacement.length() in case replacement leads to
27
27
// another replacement opportunity, e.g. folding > > > to >> > then >>>
28
28
pos++;
29
29
}
30
30
}
31
31
32
- void replace_all_template (std::string& str, const std::pair<std::regex, std:: string_view>& rule) {
32
+ void replace_all_template (std::string& str, const std::pair<std::regex, string_view>& rule) {
33
33
const auto & [re, replacement] = rule;
34
34
std::smatch match;
35
35
std::size_t cursor = 0 ;
@@ -45,8 +45,8 @@ namespace detail {
45
45
}
46
46
}
47
47
// make the replacement
48
- str.replace (match_begin, end - match_begin, replacement);
49
- cursor = match_begin + replacement.length ();
48
+ str.replace (match_begin, end - match_begin, replacement. data (), replacement. size () );
49
+ cursor = match_begin + replacement.size ();
50
50
}
51
51
}
52
52
}
0 commit comments