pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
    if needle.len() > haystack.len() { return 0; }
    if needle.len() == 0 { 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;
            // This is ugly but prevents infinite loop in case of overflow
            let overflow = top < needle.len();
            top = top.wrapping_sub(needle.len());
            if overflow { break; }
        } else {
            i += match opcodes::All::from((*haystack)[i]).classify() {
                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
}
/// Search for `needle` in the vector `haystack` and remove every
/// instance of it, returning the number of instances removed.
/// Loops through the vector opcode by opcode, skipping pushed data.
Search for `needle` in the vector `haystack` and remove every
instance of it, returning the number of instances removed.
Loops through the vector opcode by opcode, skipping pushed data.
Search for ` needle ` in the vector ` haystack ` and remove every instance of it returning the number of instances removed . Loops through the vector opcode by opcode skipping pushed data .
pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
    if needle.len() > haystack.len() { return 0; }
    if needle.len() == 0 { 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;
            // This is ugly but prevents infinite loop in case of overflow
            let overflow = top < needle.len();
            top = top.wrapping_sub(needle.len());
            if overflow { break; }
        } else {
            i += match opcodes::All::from((*haystack)[i]).classify() {
                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
}
pub fn script_find_and_remove ( haystack : & mut Vec < u8 > , needle : & [ u8 ] ) -> usize { if needle . len ( ) > haystack . len ( ) { return 0 ; } if needle . len ( ) == 0 { 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 ; // This is ugly but prevents infinite loop in case of overflow let overflow = top < needle . len ( ) ; top = top . wrapping_sub ( needle . len ( ) ) ; if overflow { break ; } } else { i += match opcodes :: All :: from ( ( * haystack ) [ i ] ) . classify ( ) { 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 }
Search for `needle` in the vector `haystack` and remove every
instance of it, returning the number of instances removed.
Search for ` needle ` in the vector ` haystack ` and remove every instance of it returning the number of instances removed .
haystack
&mut Vec<u8>
needle
&[u8]
haystack
&mut Vec<u8>
needle
&[u8]