pub fn core_s(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 3 {
            print_error(chunk, i, "s requires three arguments");
            return 0;
        }

        let repl_rr = self.stack.pop().unwrap();
        let repl_str_rr_opt = to_string_value(repl_rr);
        if repl_str_rr_opt.is_none() {
            print_error(chunk, i, "replacement must be a string");
            return 0;
        }
        let repl_str_rr = repl_str_rr_opt.unwrap();

        let regex_rr = self.stack.pop().unwrap();
        let regex_str_rr_opt = to_string_value(regex_rr);
        if regex_str_rr_opt.is_none() {
            print_error(chunk, i, "regex must be a string");
            return 0;
        }
        let regex_str_rr = regex_str_rr_opt.unwrap();

        {
            let mut regex_str_rrb = regex_str_rr.borrow_mut();
            let res = regex_str_rrb.gen_regex(chunk, i);
            if !res {
                return 0;
            }
        }
        let regex_str_rrb = regex_str_rr.borrow();
        let regex_opt = regex_str_rrb.to_regex();

        let repl_str_rrb = repl_str_rr.borrow();
        let repl_str_pre = repl_str_rrb.to_string();
        let repl_str_opt = to_string_2(&repl_str_pre);

        let str_rr = self.stack.pop().unwrap();
        let str_rrb = str_rr.borrow();
        let str_pre = str_rrb.to_string();
        let str_opt = to_string_2(&str_pre);

        match (repl_str_opt, regex_opt, str_opt) {
            (Some(repl_str), Some(regex), Some(s)) => {
                let updated_repl = RE_ADJUST.replace_all(repl_str, "$${$1}");
                let updated_repl_str = updated_repl.to_string();
                let updated_str = regex.replace_all(s, &updated_repl_str[..]);
                self.stack.push(Rc::new(RefCell::new(Value::String(
                    updated_str.to_string(),
                    None,
                ))));
            }
            (_, _, Some(_)) => {
                print_error(chunk, i, "first s argument must be string");
                return 0;
            }
            (_, Some(_), _) => {
                print_error(chunk, i, "second s argument must be string");
                return 0;
            }
            (_, _, _) => {
                print_error(chunk, i, "third s argument must be string");
                return 0;
            }
        }
        return 1;
    }
/// Takes a value that can be stringified, a regex string, and a
/// replacement string as its arguments.  Runs a
/// search-and-replace against the string based on the regex, and
/// puts the resulting string onto the stack.
Takes a value that can be stringified, a regex string, and a
replacement string as its arguments.  Runs a
search-and-replace against the string based on the regex, and
puts the resulting string onto the stack.
Takes a value that can be stringified a regex string and a replacement string as its arguments . Runs a search - and - replace against the string based on the regex and puts the resulting string onto the stack .
pub fn core_s(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 3 {
            print_error(chunk, i, "s requires three arguments");
            return 0;
        }
        let repl_rr = self.stack.pop().unwrap();
        let repl_str_rr_opt = to_string_value(repl_rr);
        if repl_str_rr_opt.is_none() {
            print_error(chunk, i, "replacement must be a string");
            return 0;
        }
        let repl_str_rr = repl_str_rr_opt.unwrap();
        let regex_rr = self.stack.pop().unwrap();
        let regex_str_rr_opt = to_string_value(regex_rr);
        if regex_str_rr_opt.is_none() {
            print_error(chunk, i, "regex must be a string");
            return 0;
        }
        let regex_str_rr = regex_str_rr_opt.unwrap();
        {
            let mut regex_str_rrb = regex_str_rr.borrow_mut();
            let res = regex_str_rrb.gen_regex(chunk, i);
            if !res {
                return 0;
            }
        }
        let regex_str_rrb = regex_str_rr.borrow();
        let regex_opt = regex_str_rrb.to_regex();
        let repl_str_rrb = repl_str_rr.borrow();
        let repl_str_pre = repl_str_rrb.to_string();
        let repl_str_opt = to_string_2(&repl_str_pre);
        let str_rr = self.stack.pop().unwrap();
        let str_rrb = str_rr.borrow();
        let str_pre = str_rrb.to_string();
        let str_opt = to_string_2(&str_pre);
        match (repl_str_opt, regex_opt, str_opt) {
            (Some(repl_str), Some(regex), Some(s)) => {
                let updated_repl = RE_ADJUST.replace_all(repl_str, "$${$1}");
                let updated_repl_str = updated_repl.to_string();
                let updated_str = regex.replace_all(s, &updated_repl_str[..]);
                self.stack.push(Rc::new(RefCell::new(Value::String(
                    updated_str.to_string(),
                    None,
                ))));
            }
            (_, _, Some(_)) => {
                print_error(chunk, i, "first s argument must be string");
                return 0;
            }
            (_, Some(_), _) => {
                print_error(chunk, i, "second s argument must be string");
                return 0;
            }
            (_, _, _) => {
                print_error(chunk, i, "third s argument must be string");
                return 0;
            }
        }
        return 1;
    }
pub fn core_s ( & mut self , chunk : & Chunk , i : usize ) -> i32 { if self . stack . len ( ) < 3 { print_error ( chunk , i , " " ) ; return 0 ; } let repl_rr = self . stack . pop ( ) . unwrap ( ) ; let repl_str_rr_opt = to_string_value ( repl_rr ) ; if repl_str_rr_opt . is_none ( ) { print_error ( chunk , i , " " ) ; return 0 ; } let repl_str_rr = repl_str_rr_opt . unwrap ( ) ; let regex_rr = self . stack . pop ( ) . unwrap ( ) ; let regex_str_rr_opt = to_string_value ( regex_rr ) ; if regex_str_rr_opt . is_none ( ) { print_error ( chunk , i , " " ) ; return 0 ; } let regex_str_rr = regex_str_rr_opt . unwrap ( ) ; { let mut regex_str_rrb = regex_str_rr . borrow_mut ( ) ; let res = regex_str_rrb . gen_regex ( chunk , i ) ; if ! res { return 0 ; } } let regex_str_rrb = regex_str_rr . borrow ( ) ; let regex_opt = regex_str_rrb . to_regex ( ) ; let repl_str_rrb = repl_str_rr . borrow ( ) ; let repl_str_pre = repl_str_rrb . to_string ( ) ; let repl_str_opt = to_string_2 ( & repl_str_pre ) ; let str_rr = self . stack . pop ( ) . unwrap ( ) ; let str_rrb = str_rr . borrow ( ) ; let str_pre = str_rrb . to_string ( ) ; let str_opt = to_string_2 ( & str_pre ) ; match ( repl_str_opt , regex_opt , str_opt ) { ( Some ( repl_str ) , Some ( regex ) , Some ( s ) ) => { let updated_repl = RE_ADJUST . replace_all ( repl_str , " " ) ; let updated_repl_str = updated_repl . to_string ( ) ; let updated_str = regex . replace_all ( s , & updated_repl_str [ .. ] ) ; self . stack . push ( Rc :: new ( RefCell :: new ( Value :: String ( updated_str . to_string ( ) , None , ) ) ) ) ; } ( _ , _ , Some ( _ ) ) => { print_error ( chunk , i , " " ) ; return 0 ; } ( _ , Some ( _ ) , _ ) => { print_error ( chunk , i , " " ) ; return 0 ; } ( _ , _ , _ ) => { print_error ( chunk , i , " " ) ; return 0 ; } } return 1 ; }
Takes a value that can be stringified, a regex string, and a
replacement string as its arguments.
Takes a value that can be stringified a regex string and a replacement string as its arguments .
&mut self
chunk
&Chunk
i
usize