pub fn splice(&mut self, range: Range<usize>, replacement: ByteString) {
        let is_splice_ascii_into_ascii = range.end <= self.ascii_len && replacement.ascii_len == replacement.len();
        if is_splice_ascii_into_ascii {
            // splice a full ASCII string into middle of ASCII region.
            self.ascii_len = self.ascii_len - range.len() + replacement.ascii_len;
        } else if range.start <= self.ascii_len {
            // splice replacement ends with non-ASCII text, but it overlaps with ASCII region.
            self.ascii_len = range.start + replacement.ascii_len;
        }
        // in other cases the ASCII region is untouched, thus not changing ascii_len.

        let is_splice_utf8_into_utf8 = self.is_utf8 && replacement.is_utf8;
        if is_splice_utf8_into_utf8 && !is_splice_ascii_into_ascii {
            // splicing UTF-8 text just requires the range to be at character boundaries.
            let s = unsafe { from_utf8_unchecked(&self.bytes) };
            self.is_utf8 = s.is_char_boundary(range.start) && s.is_char_boundary(range.end);
        }
        // if not splicing UTF-8 into UTF-8, just recompute validity afterwards.

        self.bytes.splice(range, replacement.bytes);

        if !is_splice_utf8_into_utf8 {
            self.is_utf8 = from_utf8(&self.bytes[self.ascii_len..]).is_ok();
        }

        self.debug_validate();
    }
/// Replaces the substring at `range` by a `replacement` string.
Replaces the substring at `range` by a `replacement` string.
Replaces the substring at ` range ` by a ` replacement ` string .
pub fn splice(&mut self, range: Range<usize>, replacement: ByteString) {
        let is_splice_ascii_into_ascii = range.end <= self.ascii_len && replacement.ascii_len == replacement.len();
        if is_splice_ascii_into_ascii {
            // splice a full ASCII string into middle of ASCII region.
            self.ascii_len = self.ascii_len - range.len() + replacement.ascii_len;
        } else if range.start <= self.ascii_len {
            // splice replacement ends with non-ASCII text, but it overlaps with ASCII region.
            self.ascii_len = range.start + replacement.ascii_len;
        }
        // in other cases the ASCII region is untouched, thus not changing ascii_len.
        let is_splice_utf8_into_utf8 = self.is_utf8 && replacement.is_utf8;
        if is_splice_utf8_into_utf8 && !is_splice_ascii_into_ascii {
            // splicing UTF-8 text just requires the range to be at character boundaries.
            let s = unsafe { from_utf8_unchecked(&self.bytes) };
            self.is_utf8 = s.is_char_boundary(range.start) && s.is_char_boundary(range.end);
        }
        // if not splicing UTF-8 into UTF-8, just recompute validity afterwards.
        self.bytes.splice(range, replacement.bytes);
        if !is_splice_utf8_into_utf8 {
            self.is_utf8 = from_utf8(&self.bytes[self.ascii_len..]).is_ok();
        }
        self.debug_validate();
    }
pub fn splice ( & mut self , range : Range < usize > , replacement : ByteString ) { let is_splice_ascii_into_ascii = range . end <= self . ascii_len && replacement . ascii_len == replacement . len ( ) ; if is_splice_ascii_into_ascii { // splice a full ASCII string into middle of ASCII region. self . ascii_len = self . ascii_len - range . len ( ) + replacement . ascii_len ; } else if range . start <= self . ascii_len { // splice replacement ends with non-ASCII text, but it overlaps with ASCII region. self . ascii_len = range . start + replacement . ascii_len ; } // in other cases the ASCII region is untouched, thus not changing ascii_len. let is_splice_utf8_into_utf8 = self . is_utf8 && replacement . is_utf8 ; if is_splice_utf8_into_utf8 && ! is_splice_ascii_into_ascii { // splicing UTF-8 text just requires the range to be at character boundaries. let s = unsafe { from_utf8_unchecked ( & self . bytes ) } ; self . is_utf8 = s . is_char_boundary ( range . start ) && s . is_char_boundary ( range . end ) ; } // if not splicing UTF-8 into UTF-8, just recompute validity afterwards. self . bytes . splice ( range , replacement . bytes ) ; if ! is_splice_utf8_into_utf8 { self . is_utf8 = from_utf8 ( & self . bytes [ self . ascii_len .. ] ) . is_ok ( ) ; } self . debug_validate ( ) ; }
Replaces the substring at `range` by a `replacement` string.
Replaces the substring at ` range ` by a ` replacement ` string .
&mut self
range
Range<usize>
replacement
ByteString
&mut self
range
Range<usize>
replacement
ByteString