| 237 | } |
| 238 | |
| 239 | int FindAndDelete(CScript& script, const CScript& b) |
| 240 | { |
| 241 | int nFound = 0; |
| 242 | if (b.empty()) |
| 243 | return nFound; |
| 244 | CScript result; |
| 245 | CScript::const_iterator pc = script.begin(), pc2 = script.begin(), end = script.end(); |
| 246 | opcodetype opcode; |
| 247 | do |
| 248 | { |
| 249 | result.insert(result.end(), pc2, pc); |
| 250 | while (static_cast<size_t>(end - pc) >= b.size() && std::equal(b.begin(), b.end(), pc)) |
| 251 | { |
| 252 | pc = pc + b.size(); |
| 253 | ++nFound; |
| 254 | } |
| 255 | pc2 = pc; |
| 256 | } |
| 257 | while (script.GetOp(pc, opcode)); |
| 258 | |
| 259 | if (nFound > 0) { |
| 260 | result.insert(result.end(), pc2, end); |
| 261 | script = std::move(result); |
| 262 | } |
| 263 | |
| 264 | return nFound; |
| 265 | } |
| 266 | |
| 267 | namespace { |
| 268 | /** A data type to abstract out the condition stack during script execution. |