pub fn core_join(
        &mut self,
        scopes: &mut Vec<RefCell<HashMap<String, Rc<RefCell<Value>>>>>,
        global_functions: &mut RefCell<HashMap<String, Chunk>>,
        prev_localvarstacks: &mut Vec<Rc<RefCell<Vec<Rc<RefCell<Value>>>>>>,
        chunk: &Chunk, i: usize, line_col: (u32, u32),
        running: Arc<AtomicBool>,
    ) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "join requires two arguments");
            return 0;
        }

        let separator_rr = self.stack.pop().unwrap();
        let separator_rrb = separator_rr.borrow();
        let separator_pre = separator_rrb.to_string();
        let separator_opt = to_string_2(&separator_pre);

        let esc_quotes = Regex::new(r#"""#).unwrap();

        match separator_opt {
            Some(separator) => {
                // If the separator is an empty string, then matching
                // it against the values to determine whether they
                // need quoting won't work, so skip that in that case.
                let separator_is_empty_string = separator.len() == 0;
                let separator_regex_res = Regex::new(separator);
                let mut final_elements = Vec::new();
                match separator_regex_res {
                    Ok(separator_regex) => loop {
                        let dup_res = self.opcode_dup(chunk, i);
                        if dup_res == 0 {
                            return 0;
                        }
                        let shift_res = self.opcode_shift(
                            scopes,
                            global_functions,
                            prev_localvarstacks,
                            chunk,
                            i,
                            line_col,
                            running.clone(),
                        );
                        if shift_res == 0 {
                            return 0;
                        }
                        let element_rr = self.stack.pop().unwrap();
                        let element_rrb = element_rr.borrow();
                        match &*element_rrb {
                            Value::Null => {
                                break;
                            }
                            Value::String(s, _) => {
                                if !separator_is_empty_string &&
                                        (separator_regex.is_match(&s) ||
                                         esc_quotes.is_match(&s)) {
                                    let s2 = esc_quotes.replace_all(s, "\\\"");
                                    final_elements.push(format!("\"{}\"", s2));
                                } else {
                                    final_elements.push(s.to_string());
                                }
                            }
                            _ => {
                                let element_pre = element_rrb.to_string();
                                let element_opt = to_string_2(&element_pre);
                                match element_opt {
                                    Some(s) => {
                                        if !separator_is_empty_string &&
                                                (separator_regex.is_match(&s) ||
                                                 esc_quotes.is_match(&s)) {
                                            let s2 = esc_quotes
                                                .replace_all(s, "\\\"");
                                            final_elements
                                                .push(format!("\"{}\"", s2));
                                        } else {
                                            final_elements.push(s.to_string());
                                        }
                                    }
                                    _ => {
                                        print_error(
                                            chunk,
                                            i,
                                            "cannot join non-string",
                                        );
                                        return 0;
                                    }
                                }
                            }
                        }
                    },
                    Err(_) => {
                        print_error(
                            chunk,
                            i,
                            "invalid separator regular expression",
                        );
                        return 0;
                    }
                }
                let drop_res = self.opcode_drop(chunk, i);
                if drop_res == 0 {
                    return 0;
                }
                let final_str = final_elements.join(separator);
                self.stack
                    .push(Rc::new(RefCell::new(Value::String(final_str, None))));
            }
            _ => {
                print_error(chunk, i, "second join argument must be string");
                return 0;
            }
        }
        return 1;
    }
/// Takes a shiftable object and a separator as its arguments.
/// Joins the elements retrieved from the shiftable object by
/// using the separator string between the elements, and puts the
/// resulting joined string onto the stack.
Takes a shiftable object and a separator as its arguments.
Joins the elements retrieved from the shiftable object by
using the separator string between the elements, and puts the
resulting joined string onto the stack.
Takes a shiftable object and a separator as its arguments . Joins the elements retrieved from the shiftable object by using the separator string between the elements and puts the resulting joined string onto the stack .
pub fn core_join(
        &mut self,
        scopes: &mut Vec<RefCell<HashMap<String, Rc<RefCell<Value>>>>>,
        global_functions: &mut RefCell<HashMap<String, Chunk>>,
        prev_localvarstacks: &mut Vec<Rc<RefCell<Vec<Rc<RefCell<Value>>>>>>,
        chunk: &Chunk, i: usize, line_col: (u32, u32),
        running: Arc<AtomicBool>,
    ) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "join requires two arguments");
            return 0;
        }
        let separator_rr = self.stack.pop().unwrap();
        let separator_rrb = separator_rr.borrow();
        let separator_pre = separator_rrb.to_string();
        let separator_opt = to_string_2(&separator_pre);
        let esc_quotes = Regex::new(r#"""#).unwrap();
        match separator_opt {
            Some(separator) => {
                // If the separator is an empty string, then matching
                // it against the values to determine whether they
                // need quoting won't work, so skip that in that case.
                let separator_is_empty_string = separator.len() == 0;
                let separator_regex_res = Regex::new(separator);
                let mut final_elements = Vec::new();
                match separator_regex_res {
                    Ok(separator_regex) => loop {
                        let dup_res = self.opcode_dup(chunk, i);
                        if dup_res == 0 {
                            return 0;
                        }
                        let shift_res = self.opcode_shift(
                            scopes,
                            global_functions,
                            prev_localvarstacks,
                            chunk,
                            i,
                            line_col,
                            running.clone(),
                        );
                        if shift_res == 0 {
                            return 0;
                        }
                        let element_rr = self.stack.pop().unwrap();
                        let element_rrb = element_rr.borrow();
                        match &*element_rrb {
                            Value::Null => {
                                break;
                            }
                            Value::String(s, _) => {
                                if !separator_is_empty_string &&
                                        (separator_regex.is_match(&s) ||
                                         esc_quotes.is_match(&s)) {
                                    let s2 = esc_quotes.replace_all(s, "\\\"");
                                    final_elements.push(format!("\"{}\"", s2));
                                } else {
                                    final_elements.push(s.to_string());
                                }
                            }
                            _ => {
                                let element_pre = element_rrb.to_string();
                                let element_opt = to_string_2(&element_pre);
                                match element_opt {
                                    Some(s) => {
                                        if !separator_is_empty_string &&
                                                (separator_regex.is_match(&s) ||
                                                 esc_quotes.is_match(&s)) {
                                            let s2 = esc_quotes
                                                .replace_all(s, "\\\"");
                                            final_elements
                                                .push(format!("\"{}\"", s2));
                                        } else {
                                            final_elements.push(s.to_string());
                                        }
                                    }
                                    _ => {
                                        print_error(
                                            chunk,
                                            i,
                                            "cannot join non-string",
                                        );
                                        return 0;
                                    }
                                }
                            }
                        }
                    },
                    Err(_) => {
                        print_error(
                            chunk,
                            i,
                            "invalid separator regular expression",
                        );
                        return 0;
                    }
                }
                let drop_res = self.opcode_drop(chunk, i);
                if drop_res == 0 {
                    return 0;
                }
                let final_str = final_elements.join(separator);
                self.stack
                    .push(Rc::new(RefCell::new(Value::String(final_str, None))));
            }
            _ => {
                print_error(chunk, i, "second join argument must be string");
                return 0;
            }
        }
        return 1;
    }
pub fn core_join ( & mut self , scopes : & mut Vec < RefCell < HashMap < String , Rc < RefCell < Value > > > > > , global_functions : & mut RefCell < HashMap < String , Chunk > > , prev_localvarstacks : & mut Vec < Rc < RefCell < Vec < Rc < RefCell < Value > > > > > > , chunk : & Chunk , i : usize , line_col : ( u32 , u32 ) , running : Arc < AtomicBool > , ) -> 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 separator_pre = separator_rrb . to_string ( ) ; let separator_opt = to_string_2 ( & separator_pre ) ; let esc_quotes = Regex :: new ( r#"""# ) . unwrap ( ) ; match separator_opt { Some ( separator ) => { // If the separator is an empty string, then matching // it against the values to determine whether they // need quoting won't work, so skip that in that case. let separator_is_empty_string = separator . len ( ) == 0 ; let separator_regex_res = Regex :: new ( separator ) ; let mut final_elements = Vec :: new ( ) ; match separator_regex_res { Ok ( separator_regex ) => loop { let dup_res = self . opcode_dup ( chunk , i ) ; if dup_res == 0 { return 0 ; } let shift_res = self . opcode_shift ( scopes , global_functions , prev_localvarstacks , chunk , i , line_col , running . clone ( ) , ) ; if shift_res == 0 { return 0 ; } let element_rr = self . stack . pop ( ) . unwrap ( ) ; let element_rrb = element_rr . borrow ( ) ; match & * element_rrb { Value :: Null => { break ; } Value :: String ( s , _ ) => { if ! separator_is_empty_string && ( separator_regex . is_match ( & s ) || esc_quotes . is_match ( & s ) ) { let s2 = esc_quotes . replace_all ( s , " \\ \" " ) ; final_elements . push ( format ! ( " \" \" " s2 ) ) ; } else { final_elements . push ( s . to_string ( ) ) ; } } _ => { let element_pre = element_rrb . to_string ( ) ; let element_opt = to_string_2 ( & element_pre ) ; match element_opt { Some ( s ) => { if ! separator_is_empty_string && ( separator_regex . is_match ( & s ) || esc_quotes . is_match ( & s ) ) { let s2 = esc_quotes . replace_all ( s , " \\ \" " ) ; final_elements . push ( format ! ( " \" \" " s2 ) ) ; } else { final_elements . push ( s . to_string ( ) ) ; } } _ => { print_error ( chunk , i , " " , ) ; return 0 ; } } } } } , Err ( _ ) => { print_error ( chunk , i , " " , ) ; return 0 ; } } let drop_res = self . opcode_drop ( chunk , i ) ; if drop_res == 0 { return 0 ; } let final_str = final_elements . join ( separator ) ; self . stack . push ( Rc :: new ( RefCell :: new ( Value :: String ( final_str , None ) ) ) ) ; } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } return 1 ; }
Takes a shiftable object and a separator as its arguments.
Takes a shiftable object and a separator as its arguments .
&mut self
scopes
&mut Vec<RefCell<HashMap<String, Rc<RefCell<Value>>>>>
global_functions
&mut RefCell<HashMap<String, Chunk>>
prev_localvarstacks
&mut Vec<Rc<RefCell<Vec<Rc<RefCell<Value>>>>>>
chunk
&Chunk
i
usize
line_col
(u32, u32)
running
Arc<AtomicBool>