MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / operation

Method operation

src/function/vector_string_functions.cpp:198–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196
197struct 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
226function_set ReplaceFunction::getFunctionSet() {

Callers

nothing calls this directly

Calls 6

getAsStringMethod · 0.80
lengthMethod · 0.80
reserveMethod · 0.45
findMethod · 0.45
appendMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected