| 1125 | } |
| 1126 | |
| 1127 | StringVal StringFunctions::RegexpReplace(FunctionContext* context, const StringVal& str, |
| 1128 | const StringVal& pattern, const StringVal& replace) { |
| 1129 | if (str.is_null || pattern.is_null || replace.is_null) return StringVal::null(); |
| 1130 | |
| 1131 | re2::RE2* re = reinterpret_cast<re2::RE2*>( |
| 1132 | context->GetFunctionState(FunctionContext::THREAD_LOCAL)); |
| 1133 | scoped_ptr<re2::RE2> scoped_re; // destroys re if state->re is NULL |
| 1134 | if (re == NULL) { |
| 1135 | DCHECK(!context->IsArgConstant(1)); |
| 1136 | string error_str; |
| 1137 | re = CompileRegex(pattern, &error_str, StringVal::null()); |
| 1138 | if (re == NULL) { |
| 1139 | context->AddWarning(error_str.c_str()); |
| 1140 | return StringVal::null(); |
| 1141 | } |
| 1142 | scoped_re.reset(re); |
| 1143 | } |
| 1144 | |
| 1145 | re2::StringPiece replace_str = |
| 1146 | re2::StringPiece(reinterpret_cast<char*>(replace.ptr), replace.len); |
| 1147 | string result_str = AnyValUtil::ToString(str); |
| 1148 | re2::RE2::GlobalReplace(&result_str, *re, replace_str); |
| 1149 | return AnyValUtil::FromString(context, result_str); |
| 1150 | } |
| 1151 | |
| 1152 | void StringFunctions::RegexpMatchCountPrepare(FunctionContext* context, |
| 1153 | FunctionContext::FunctionStateScope scope) { |
nothing calls this directly
no test coverage detected