Skip to content

Commit

Permalink
Merge remote-tracking branch 'cryshado/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 3, 2023
2 parents 7097194 + 8da0a67 commit bb0c183
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,31 @@ impl FiftModule for BaseModule {
stack.push_raw(tuple)
}

#[cmd(name = "[]>$", stack, args(pop_sep = false))] // []>$ (t[S0, S1, ..., Sn] -- S)
#[cmd(name = "[]>$by", stack, args(pop_sep = true))] // []>$by (t[S0, S1, ..., Sn] s -- S)
fn interpret_tuple_strings_join(stack: &mut Stack, pop_sep: bool) -> Result<()> {
let sep = if pop_sep {
Some(stack.pop_string()?)
} else {
None
};
let tuple = stack.pop_tuple_owned()?;

let mut result = String::new();

let mut first = true;
for item in tuple {
if let Some(sep) = sep.as_deref() {
if !std::mem::replace(&mut first, false) {
result.push_str(sep);
}
}
result.push_str(item.as_string()?);
}

stack.push(result)
}

#[cmd(name = "count", stack)]
fn interpret_tuple_len(stack: &mut Stack) -> Result<()> {
let len = stack.pop_tuple()?.len();
Expand Down
1 change: 1 addition & 0 deletions src/modules/string_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl StringUtils {

let substrings = string
.split(sep.as_str())
.filter(|s| !s.is_empty())
.map(|s| Rc::new(s.to_string()) as Rc<dyn StackValue>)
.collect::<Vec<_>>();

Expand Down

0 comments on commit bb0c183

Please sign in to comment.