MCPcopy Create free account
hub / github.com/MariaDB/server / func_replace

Function func_replace

client/mysqltest.cc:6522–6551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6520*/
6521
6522void func_replace(Expression_value args[], int count, Expression_value *result)
6523{
6524 if (count != 3)
6525 die("replace() expects 3 arguments (str, from, to), got %d", count);
6526
6527 if (args[0].is_numeric || args[1].is_numeric || args[2].is_numeric)
6528 die("replace() arguments must be strings");
6529
6530 My_string str= args[0].to_string();
6531 My_string from_str= args[1].to_string();
6532 My_string to_str= args[2].to_string();
6533
6534 if (from_str.length() == 0)
6535 {
6536 result->set_string(str.ptr(), str.length());
6537 return;
6538 }
6539
6540 My_string result_str;
6541 result_str.copy(str);
6542
6543 int pos= 0;
6544 while ((pos= result_str.strstr(from_str, pos)) >= 0)
6545 {
6546 result_str.replace(pos, from_str.length(), to_str.ptr(), to_str.length());
6547 pos += to_str.length();
6548 }
6549
6550 result->set_string(result_str.ptr(), result_str.length());
6551}
6552
6553
6554/**

Callers 1

Calls 8

set_stringMethod · 0.80
dieFunction · 0.70
to_stringMethod · 0.45
lengthMethod · 0.45
ptrMethod · 0.45
copyMethod · 0.45
strstrMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected