pub(crate) fn new_with_range_at_byte(
        node: &Arc<Node>,
        at_byte: usize,
        byte_idx_range: (usize, usize),
        char_idx_range: (usize, usize),
        line_break_idx_range: (usize, usize),
    ) -> (Chunks, usize, usize, usize) {
        debug_assert!(at_byte >= byte_idx_range.0);
        debug_assert!(at_byte <= byte_idx_range.1);

        // For convenience/readability.
        let start_byte = byte_idx_range.0;
        let end_byte = byte_idx_range.1;

        // Special-case for empty text contents.
        if start_byte == end_byte {
            return (
                Chunks {
                    iter: ChunksEnum::Light {
                        text: "",
                        is_end: false,
                    },
                    is_reversed: false,
                },
                0,
                0,
                0,
            );
        }

        // If root is a leaf, return light version of the iter.
        if node.is_leaf() {
            let text = &node.leaf_text()[start_byte..end_byte];
            if at_byte == end_byte {
                return (
                    Chunks {
                        iter: ChunksEnum::Light {
                            text: text,
                            is_end: true,
                        },
                        is_reversed: false,
                    },
                    text.len(),
                    count_chars(text),
                    byte_to_line_idx(text, text.len()),
                );
            } else {
                return (
                    Chunks {
                        iter: ChunksEnum::Light {
                            text: text,
                            is_end: false,
                        },
                        is_reversed: false,
                    },
                    0,
                    0,
                    0,
                );
            }
        }

        // Create and populate the node stack, and determine the char index
        // within the first chunk, and byte index of the start of that chunk.
        let mut info = TextInfo::new();
        let mut byte_idx = at_byte as isize;
        let node_stack = {
            let mut node_stack: Vec<(&Arc<Node>, usize)> = Vec::new();
            let mut node_ref = node;
            loop {
                match **node_ref {
                    Node::Leaf(ref text) => {
                        if at_byte < end_byte || byte_idx == 0 {
                            byte_idx = info.bytes as isize - start_byte as isize;
                        } else {
                            byte_idx =
                                (info.bytes as isize + text.len() as isize) - start_byte as isize;
                            info = TextInfo {
                                bytes: byte_idx_range.1 as u64,
                                chars: char_idx_range.1 as u64,
                                utf16_surrogates: 0, // Bogus value, not needed
                                line_breaks: line_break_idx_range.1 as u64 - 1,
                            };
                            (*node_stack.last_mut().unwrap()).1 += 1;
                        }
                        break;
                    }
                    Node::Internal(ref children) => {
                        let (child_i, acc_info) = children.search_byte_idx(byte_idx as usize);
                        info += acc_info;
                        node_stack.push((node_ref, child_i));
                        node_ref = &children.nodes()[child_i];
                        byte_idx -= acc_info.bytes as isize;
                    }
                }
            }
            node_stack
        };

        // Create the iterator.
        (
            Chunks {
                iter: ChunksEnum::Full {
                    node_stack: node_stack,
                    total_bytes: end_byte - start_byte,
                    byte_idx: byte_idx,
                },
                is_reversed: false,
            },
            (info.bytes as usize).max(byte_idx_range.0),
            (info.chars as usize).max(char_idx_range.0),
            (info.line_breaks as usize).max(line_break_idx_range.0),
        )
    }
/// The main workhorse function for creating new `Chunks` iterators.
///
/// Creates a new `Chunks` iterator from the given node, starting the
/// iterator at the chunk containing the `at_byte` byte index (i.e. the
/// `next()` method will yield the chunk containing that byte).  The range
/// of the iterator is bounded by `byte_idx_range`.
///
/// Both `at_byte` and `byte_idx_range` are relative to the beginning of
/// of the passed node.
///
/// Passing an `at_byte` equal to the max of `byte_idx_range` creates an
/// iterator at the end of forward iteration.
///
/// Returns the iterator and the byte/char/line index of its start relative
/// to the start of the node.
The main workhorse function for creating new `Chunks` iterators.

Both `at_byte` and `byte_idx_range` are relative to the beginning of
of the passed node.

Passing an `at_byte` equal to the max of `byte_idx_range` creates an
iterator at the end of forward iteration.

Returns the iterator and the byte/char/line index of its start relative
to the start of the node.
The main workhorse function for creating new ` Chunks ` iterators . Both ` at_byte ` and ` byte_idx_range ` are relative to the beginning of of the passed node . Passing an ` at_byte ` equal to the max of ` byte_idx_range ` creates an iterator at the end of forward iteration . Returns the iterator and the byte / char / line index of its start relative to the start of the node .
pub(crate) fn new_with_range_at_byte(
        node: &Arc<Node>,
        at_byte: usize,
        byte_idx_range: (usize, usize),
        char_idx_range: (usize, usize),
        line_break_idx_range: (usize, usize),
    ) -> (Chunks, usize, usize, usize) {
        debug_assert!(at_byte >= byte_idx_range.0);
        debug_assert!(at_byte <= byte_idx_range.1);
        // For convenience/readability.
        let start_byte = byte_idx_range.0;
        let end_byte = byte_idx_range.1;
        // Special-case for empty text contents.
        if start_byte == end_byte {
            return (
                Chunks {
                    iter: ChunksEnum::Light {
                        text: "",
                        is_end: false,
                    },
                    is_reversed: false,
                },
                0,
                0,
                0,
            );
        }
        // If root is a leaf, return light version of the iter.
        if node.is_leaf() {
            let text = &node.leaf_text()[start_byte..end_byte];
            if at_byte == end_byte {
                return (
                    Chunks {
                        iter: ChunksEnum::Light {
                            text: text,
                            is_end: true,
                        },
                        is_reversed: false,
                    },
                    text.len(),
                    count_chars(text),
                    byte_to_line_idx(text, text.len()),
                );
            } else {
                return (
                    Chunks {
                        iter: ChunksEnum::Light {
                            text: text,
                            is_end: false,
                        },
                        is_reversed: false,
                    },
                    0,
                    0,
                    0,
                );
            }
        }
        // Create and populate the node stack, and determine the char index
        // within the first chunk, and byte index of the start of that chunk.
        let mut info = TextInfo::new();
        let mut byte_idx = at_byte as isize;
        let node_stack = {
            let mut node_stack: Vec<(&Arc<Node>, usize)> = Vec::new();
            let mut node_ref = node;
            loop {
                match **node_ref {
                    Node::Leaf(ref text) => {
                        if at_byte < end_byte || byte_idx == 0 {
                            byte_idx = info.bytes as isize - start_byte as isize;
                        } else {
                            byte_idx =
                                (info.bytes as isize + text.len() as isize) - start_byte as isize;
                            info = TextInfo {
                                bytes: byte_idx_range.1 as u64,
                                chars: char_idx_range.1 as u64,
                                utf16_surrogates: 0, // Bogus value, not needed
                                line_breaks: line_break_idx_range.1 as u64 - 1,
                            };
                            (*node_stack.last_mut().unwrap()).1 += 1;
                        }
                        break;
                    }
                    Node::Internal(ref children) => {
                        let (child_i, acc_info) = children.search_byte_idx(byte_idx as usize);
                        info += acc_info;
                        node_stack.push((node_ref, child_i));
                        node_ref = &children.nodes()[child_i];
                        byte_idx -= acc_info.bytes as isize;
                    }
                }
            }
            node_stack
        };
        // Create the iterator.
        (
            Chunks {
                iter: ChunksEnum::Full {
                    node_stack: node_stack,
                    total_bytes: end_byte - start_byte,
                    byte_idx: byte_idx,
                },
                is_reversed: false,
            },
            (info.bytes as usize).max(byte_idx_range.0),
            (info.chars as usize).max(char_idx_range.0),
            (info.line_breaks as usize).max(line_break_idx_range.0),
        )
    }
pub ( crate ) fn new_with_range_at_byte ( node : & Arc < Node > , at_byte : usize , byte_idx_range : ( usize , usize ) , char_idx_range : ( usize , usize ) , line_break_idx_range : ( usize , usize ) , ) -> ( Chunks , usize , usize , usize ) { debug_assert ! ( at_byte byte_idx_range 0 ) ; debug_assert ! ( at_byte byte_idx_range 1 ) ; // For convenience/readability. let start_byte = byte_idx_range . 0 ; let end_byte = byte_idx_range . 1 ; // Special-case for empty text contents. if start_byte == end_byte { return ( Chunks { iter : ChunksEnum :: Light { text : " " , is_end : false , } , is_reversed : false , } , 0 , 0 , 0 , ) ; } // If root is a leaf, return light version of the iter. if node . is_leaf ( ) { let text = & node . leaf_text ( ) [ start_byte .. end_byte ] ; if at_byte == end_byte { return ( Chunks { iter : ChunksEnum :: Light { text : text , is_end : true , } , is_reversed : false , } , text . len ( ) , count_chars ( text ) , byte_to_line_idx ( text , text . len ( ) ) , ) ; } else { return ( Chunks { iter : ChunksEnum :: Light { text : text , is_end : false , } , is_reversed : false , } , 0 , 0 , 0 , ) ; } } // Create and populate the node stack, and determine the char index // within the first chunk, and byte index of the start of that chunk. let mut info = TextInfo :: new ( ) ; let mut byte_idx = at_byte as isize ; let node_stack = { let mut node_stack : Vec < ( & Arc < Node > , usize ) > = Vec :: new ( ) ; let mut node_ref = node ; loop { match * * node_ref { Node :: Leaf ( ref text ) => { if at_byte < end_byte || byte_idx == 0 { byte_idx = info . bytes as isize - start_byte as isize ; } else { byte_idx = ( info . bytes as isize + text . len ( ) as isize ) - start_byte as isize ; info = TextInfo { bytes : byte_idx_range . 1 as u64 , chars : char_idx_range . 1 as u64 , utf16_surrogates : 0 , // Bogus value, not needed line_breaks : line_break_idx_range . 1 as u64 - 1 , } ; ( * node_stack . last_mut ( ) . unwrap ( ) ) . 1 += 1 ; } break ; } Node :: Internal ( ref children ) => { let ( child_i , acc_info ) = children . search_byte_idx ( byte_idx as usize ) ; info += acc_info ; node_stack . push ( ( node_ref , child_i ) ) ; node_ref = & children . nodes ( ) [ child_i ] ; byte_idx -= acc_info . bytes as isize ; } } } node_stack } ; // Create the iterator. ( Chunks { iter : ChunksEnum :: Full { node_stack : node_stack , total_bytes : end_byte - start_byte , byte_idx : byte_idx , } , is_reversed : false , } , ( info . bytes as usize ) . max ( byte_idx_range . 0 ) , ( info . chars as usize ) . max ( char_idx_range . 0 ) , ( info . line_breaks as usize ) . max ( line_break_idx_range . 0 ) , ) }
The main workhorse function for creating new `Chunks` iterators.
The main workhorse function for creating new ` Chunks ` iterators .
node
&Arc<Node>
at_byte
usize
byte_idx_range
(usize, usize)
char_idx_range
(usize, usize)
line_break_idx_range
(usize, usize)