| 6221 | |
| 6222 | |
| 6223 | dsc* evlReplace(thread_db* tdbb, const SysFunction*, const NestValueArray& args, |
| 6224 | impure_value* impure) |
| 6225 | { |
| 6226 | fb_assert(args.getCount() == 3); |
| 6227 | |
| 6228 | Request* request = tdbb->getRequest(); |
| 6229 | dsc* values[3]; // 0 = searched, 1 = find, 2 = replacement |
| 6230 | const dsc* firstBlob = NULL; |
| 6231 | |
| 6232 | for (int i = 0; i < 3; ++i) |
| 6233 | { |
| 6234 | values[i] = EVL_expr(tdbb, request, args[i]); |
| 6235 | if (request->req_flags & req_null) // return NULL if values[i] is NULL |
| 6236 | return NULL; |
| 6237 | |
| 6238 | if (!firstBlob && values[i]->isBlob()) |
| 6239 | firstBlob = values[i]; |
| 6240 | } |
| 6241 | |
| 6242 | const USHORT ttype = values[0]->getTextType(); |
| 6243 | TextType* tt = INTL_texttype_lookup(tdbb, ttype); |
| 6244 | CharSet* cs = tt->getCharSet(); |
| 6245 | const UCHAR canonicalWidth = tt->getCanonicalWidth(); |
| 6246 | |
| 6247 | MoveBuffer buffers[3]; |
| 6248 | UCHAR* addresses[3]; |
| 6249 | ULONG lengths[3]; |
| 6250 | |
| 6251 | for (int i = 0; i < 3; ++i) |
| 6252 | { |
| 6253 | if (values[i]->isBlob()) |
| 6254 | { |
| 6255 | // values[i] is a blob |
| 6256 | blb* blob = blb::open(tdbb, tdbb->getRequest()->req_transaction, |
| 6257 | reinterpret_cast<bid*>(values[i]->dsc_address)); |
| 6258 | |
| 6259 | addresses[i] = buffers[i].getBuffer(blob->blb_length); |
| 6260 | lengths[i] = blob->BLB_get_data(tdbb, addresses[i], blob->blb_length, true); |
| 6261 | } |
| 6262 | else |
| 6263 | lengths[i] = MOV_make_string2(tdbb, values[i], ttype, &addresses[i], buffers[i]); |
| 6264 | } |
| 6265 | |
| 6266 | if (lengths[1] == 0) |
| 6267 | return values[0]; |
| 6268 | |
| 6269 | HalfStaticArray<UCHAR, BUFFER_SMALL> canonicals[2]; // searched, find |
| 6270 | for (int i = 0; i < 2; ++i) |
| 6271 | { |
| 6272 | canonicals[i].getBuffer(lengths[i] / cs->minBytesPerChar() * canonicalWidth); |
| 6273 | canonicals[i].resize(tt->canonical(lengths[i], addresses[i], |
| 6274 | canonicals[i].getCount(), canonicals[i].begin()) * canonicalWidth); |
| 6275 | } |
| 6276 | |
| 6277 | blb* newBlob = NULL; |
| 6278 | |
| 6279 | // make descriptor for return value |
| 6280 | if (!firstBlob) |
nothing calls this directly
no test coverage detected