pub fn core_split(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "split requires two arguments");
            return 0;
        }

        let separator_rr = self.stack.pop().unwrap();
        let separator_rrb = separator_rr.borrow();
        let list_str_rr = self.stack.pop().unwrap();
        let list_str_rrb = list_str_rr.borrow();

        let separator_pre = separator_rrb.to_string();
        let separator_opt = to_string_2(&separator_pre);
        let list_str_pre = list_str_rrb.to_string();
        let list_str_opt = to_string_2(&list_str_pre);

        match (separator_opt, list_str_opt) {
            (Some(separator), Some(list_str)) => {
                let elements = list_str.split(separator);
                // The final set of separated elements.
                let mut final_elements = Vec::new();
                // A list containing a partially-complete element, if
                // applicable.
                let mut buffer = Vec::new();
                for e in elements {
                    let e_str = e.to_string();
                    if buffer.len() > 0 {
                        if e_str.len() > 0 {
                            if e_str.chars().last().unwrap() == '"' {
                                buffer.push(e_str);
                                let new_str = buffer.join(separator);
                                let new_str2 = START_QUOTE.replace(&new_str, "");
                                let new_str3 = END_QUOTE.replace(&new_str2, "");
                                final_elements.push(new_str3.to_string());
                                buffer.clear();
                            } else {
                                buffer.push(e_str);
                            }
                        }
                    } else if START_QUOTE.is_match(&e_str) && !END_QUOTE.is_match(&e_str) {
                        buffer.push(e_str);
                    } else {
                        let new_str = START_QUOTE.replace(&e_str, "");
                        let new_str2 = END_QUOTE.replace(&new_str, "");
                        final_elements.push(new_str2.to_string());
                    }
                }
                if buffer.len() > 0 {
                    print_error(chunk, i, "error in string syntax in split");
                    return 0;
                }

                let mut lst = VecDeque::new();
                for e in final_elements.iter() {
                    lst.push_back(Rc::new(RefCell::new(Value::String(
                        e.to_string(),
                        None,
                    ))));
                }
                self.stack.push(Rc::new(RefCell::new(Value::List(lst))));
            }
            (Some(_), _) => {
                print_error(chunk, i, "first split argument must be string");
                return 0;
            }
            _ => {
                print_error(chunk, i, "second split argument must be string");
                return 0;
            }
        }
        return 1;
    }
/// Takes a string and a separator as its arguments.  Splits the
/// string using the separator, and puts the resulting list onto
/// the stack.  Quotation by way of the double-quote character is
/// taken into account.
Takes a string and a separator as its arguments.  Splits the
string using the separator, and puts the resulting list onto
the stack.  Quotation by way of the double-quote character is
taken into account.
Takes a string and a separator as its arguments . Splits the string using the separator and puts the resulting list onto the stack . Quotation by way of the double - quote character is taken into account .
pub fn core_split(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "split requires two arguments");
            return 0;
        }
        let separator_rr = self.stack.pop().unwrap();
        let separator_rrb = separator_rr.borrow();
        let list_str_rr = self.stack.pop().unwrap();
        let list_str_rrb = list_str_rr.borrow();
        let separator_pre = separator_rrb.to_string();
        let separator_opt = to_string_2(&separator_pre);
        let list_str_pre = list_str_rrb.to_string();
        let list_str_opt = to_string_2(&list_str_pre);
        match (separator_opt, list_str_opt) {
            (Some(separator), Some(list_str)) => {
                let elements = list_str.split(separator);
                // The final set of separated elements.
                let mut final_elements = Vec::new();
                // A list containing a partially-complete element, if
                // applicable.
                let mut buffer = Vec::new();
                for e in elements {
                    let e_str = e.to_string();
                    if buffer.len() > 0 {
                        if e_str.len() > 0 {
                            if e_str.chars().last().unwrap() == '"' {
                                buffer.push(e_str);
                                let new_str = buffer.join(separator);
                                let new_str2 = START_QUOTE.replace(&new_str, "");
                                let new_str3 = END_QUOTE.replace(&new_str2, "");
                                final_elements.push(new_str3.to_string());
                                buffer.clear();
                            } else {
                                buffer.push(e_str);
                            }
                        }
                    } else if START_QUOTE.is_match(&e_str) && !END_QUOTE.is_match(&e_str) {
                        buffer.push(e_str);
                    } else {
                        let new_str = START_QUOTE.replace(&e_str, "");
                        let new_str2 = END_QUOTE.replace(&new_str, "");
                        final_elements.push(new_str2.to_string());
                    }
                }
                if buffer.len() > 0 {
                    print_error(chunk, i, "error in string syntax in split");
                    return 0;
                }
                let mut lst = VecDeque::new();
                for e in final_elements.iter() {
                    lst.push_back(Rc::new(RefCell::new(Value::String(
                        e.to_string(),
                        None,
                    ))));
                }
                self.stack.push(Rc::new(RefCell::new(Value::List(lst))));
            }
            (Some(_), _) => {
                print_error(chunk, i, "first split argument must be string");
                return 0;
            }
            _ => {
                print_error(chunk, i, "second split argument must be string");
                return 0;
            }
        }
        return 1;
    }
pub fn core_split ( & mut self , chunk : & Chunk , i : usize ) -> i32 { if self . stack . len ( ) < 2 { print_error ( chunk , i , " " ) ; return 0 ; } let separator_rr = self . stack . pop ( ) . unwrap ( ) ; let separator_rrb = separator_rr . borrow ( ) ; let list_str_rr = self . stack . pop ( ) . unwrap ( ) ; let list_str_rrb = list_str_rr . borrow ( ) ; let separator_pre = separator_rrb . to_string ( ) ; let separator_opt = to_string_2 ( & separator_pre ) ; let list_str_pre = list_str_rrb . to_string ( ) ; let list_str_opt = to_string_2 ( & list_str_pre ) ; match ( separator_opt , list_str_opt ) { ( Some ( separator ) , Some ( list_str ) ) => { let elements = list_str . split ( separator ) ; // The final set of separated elements. let mut final_elements = Vec :: new ( ) ; // A list containing a partially-complete element, if // applicable. let mut buffer = Vec :: new ( ) ; for e in elements { let e_str = e . to_string ( ) ; if buffer . len ( ) > 0 { if e_str . len ( ) > 0 { if e_str . chars ( ) . last ( ) . unwrap ( ) == '"' { buffer . push ( e_str ) ; let new_str = buffer . join ( separator ) ; let new_str2 = START_QUOTE . replace ( & new_str , " " ) ; let new_str3 = END_QUOTE . replace ( & new_str2 , " " ) ; final_elements . push ( new_str3 . to_string ( ) ) ; buffer . clear ( ) ; } else { buffer . push ( e_str ) ; } } } else if START_QUOTE . is_match ( & e_str ) && ! END_QUOTE . is_match ( & e_str ) { buffer . push ( e_str ) ; } else { let new_str = START_QUOTE . replace ( & e_str , " " ) ; let new_str2 = END_QUOTE . replace ( & new_str , " " ) ; final_elements . push ( new_str2 . to_string ( ) ) ; } } if buffer . len ( ) > 0 { print_error ( chunk , i , " " ) ; return 0 ; } let mut lst = VecDeque :: new ( ) ; for e in final_elements . iter ( ) { lst . push_back ( Rc :: new ( RefCell :: new ( Value :: String ( e . to_string ( ) , None , ) ) ) ) ; } self . stack . push ( Rc :: new ( RefCell :: new ( Value :: List ( lst ) ) ) ) ; } ( Some ( _ ) , _ ) => { print_error ( chunk , i , " " ) ; return 0 ; } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } return 1 ; }
Takes a string and a separator as its arguments.
Takes a string and a separator as its arguments .
&mut self
chunk
&Chunk
i
usize