| 347 | } |
| 348 | |
| 349 | int FindAndDelete(CScript& script, const CScript& b) |
| 350 | { |
| 351 | int nFound = 0; |
| 352 | if (b.empty()) |
| 353 | return nFound; |
| 354 | CScript result; |
| 355 | CScript::const_iterator pc = script.begin(), pc2 = script.begin(), end = script.end(); |
| 356 | opcodetype opcode; |
| 357 | do |
| 358 | { |
| 359 | result.insert(result.end(), pc2, pc); |
| 360 | while (static_cast<size_t>(end - pc) >= b.size() && std::equal(b.begin(), b.end(), pc)) |
| 361 | { |
| 362 | pc = pc + b.size(); |
| 363 | ++nFound; |
| 364 | } |
| 365 | pc2 = pc; |
| 366 | } |
| 367 | while (script.GetOp(pc, opcode)); |
| 368 | |
| 369 | if (nFound > 0) { |
| 370 | result.insert(result.end(), pc2, end); |
| 371 | script = std::move(result); |
| 372 | } |
| 373 | |
| 374 | return nFound; |
| 375 | } |
| 376 | |
| 377 | namespace { |
| 378 | /** A data type to abstract out the condition stack during script execution. |