| 196 | |
| 197 | struct Replace { |
| 198 | static void operation(string_t& input, string_t& source, string_t& target, string_t& result, |
| 199 | ValueVector& resultValueVector) { |
| 200 | if (source.len == 0) { |
| 201 | StringVector::addString(&resultValueVector, result, input); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | auto inputStr = input.getAsString(); |
| 206 | auto sourceStr = source.getAsString(); |
| 207 | auto targetStr = target.getAsString(); |
| 208 | std::string resultStr; |
| 209 | resultStr.reserve(inputStr.length()); |
| 210 | |
| 211 | size_t start = 0; |
| 212 | while (true) { |
| 213 | auto pos = inputStr.find(sourceStr, start); |
| 214 | if (pos == std::string::npos) { |
| 215 | resultStr.append(inputStr, start, std::string::npos); |
| 216 | break; |
| 217 | } |
| 218 | resultStr.append(inputStr, start, pos - start); |
| 219 | resultStr.append(targetStr); |
| 220 | start = pos + sourceStr.length(); |
| 221 | } |
| 222 | StringVector::addString(&resultValueVector, result, resultStr.data(), resultStr.length()); |
| 223 | } |
| 224 | }; |
| 225 | |
| 226 | function_set ReplaceFunction::getFunctionSet() { |