From 1e99d7d635a4721654279eb761d954acbfd961d6 Mon Sep 17 00:00:00 2001 From: akihiro17 <7583548+akihiro17@users.noreply.github.com> Date: Mon, 10 Jun 2024 02:12:25 +0900 Subject: [PATCH] split multiline strings --- src/std/main.ab | 2 +- src/tests/stdlib.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/std/main.ab b/src/std/main.ab index 48bb2760..6fd018b3 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -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 } diff --git a/src/tests/stdlib.rs b/src/tests/stdlib.rs index 1a024c80..ed116b4a 100644 --- a/src/tests/stdlib.rs +++ b/src/tests/stdlib.rs @@ -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 = "