Skip to content

Commit

Permalink
Merge pull request #164 from akihiro17/split-multiline-string
Browse files Browse the repository at this point in the history
split multiline strings
  • Loading branch information
Ph0enixKM authored Jun 17, 2024
2 parents aabc712 + 1e99d7d commit a2f6f07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/std/main.ab
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fun file_append(path, content) {

pub fun split(text: Text, delimiter: Text): [Text] {
let result = [Text]
unsafe $IFS="{delimiter}" read -ra {nameof result} <<< "\${nameof text}"$
unsafe $IFS="{delimiter}" read -rd '' -a {nameof result} < <(printf %s "\${nameof text}")$
return result
}

Expand Down
12 changes: 12 additions & 0 deletions src/tests/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ fn split() {
test_amber!(code, "banana")
}

#[test]
fn split_multiline() {
let code = "
import * from \"std\"
main {
let array = split(\"apple,ban\nana,cherry\", \",\")
echo array
}
";
test_amber!(code, "apple ban\nana cherry")
}

#[test]
fn join() {
let code = "
Expand Down

0 comments on commit a2f6f07

Please sign in to comment.