File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -122,17 +122,14 @@ static std::string trim(const std::string & str) {
122
122
}
123
123
124
124
static void replace_all(std::string & s, const std::string & search, const std::string & replace) {
125
- std::string result;
126
- for (size_t pos = 0; ; pos += search.length()) {
127
- auto new_pos = s.find(search, pos);
128
- if (new_pos == std::string::npos) {
129
- result += s.substr(pos, s.size() - pos);
130
- break;
131
- }
132
- result += s.substr(pos, new_pos - pos) + replace;
133
- pos = new_pos;
125
+ if (search.empty()) {
126
+ return; // Avoid infinite loop if 'search' is an empty string
127
+ }
128
+ size_t pos = 0;
129
+ while ((pos = s.find(search, pos)) != std::string::npos) {
130
+ s.replace(pos, search.length(), replace);
131
+ pos += replace.length();
134
132
}
135
- s = std::move(result);
136
133
}
137
134
138
135
static bool is_float_close(float a, float b, float abs_tol) {
You can’t perform that action at this time.
0 commit comments