pub mod misc {
use crate::prelude::*;
#[deprecated(since = "0.30.0", note = "No longer supported")]
pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
use crate::blockdata::opcodes;
if needle.len() > haystack.len() {
return 0;
}
if needle.is_empty() {
return 0;
}
let mut top = haystack.len() - needle.len();
let mut n_deleted = 0;
let mut i = 0;
while i <= top {
if &haystack[i..(i + needle.len())] == needle {
for j in i..top {
haystack.swap(j + needle.len(), j);
}
n_deleted += 1;
let overflow = top < needle.len();
top = top.wrapping_sub(needle.len());
if overflow {
break;
}
} else {
i += match opcodes::All::from((*haystack)[i]).classify(opcodes::ClassifyContext::Legacy) {
opcodes::Class::PushBytes(n) => n as usize + 1,
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA1) => 2,
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA2) => 3,
opcodes::Class::Ordinary(opcodes::Ordinary::OP_PUSHDATA4) => 5,
_ => 1
};
}
}
haystack.truncate(top.wrapping_add(needle.len()));
n_deleted
}
}