diff --git a/src/std/main.ab b/src/std/main.ab index b2318c4e..b180bf17 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -40,6 +40,10 @@ pub fun lines(text: Text): [Text] { return result } +pub fun words(text: Text): [Text] { + return split(text, " ") +} + pub fun join(list: [Text], delimiter: Text): Text { return unsafe $IFS="{delimiter}" ; echo "\$\{{nameof list}[*]}"$ } diff --git a/src/tests/validity.rs b/src/tests/validity.rs index ce1e139b..8d9f8531 100644 --- a/src/tests/validity.rs +++ b/src/tests/validity.rs @@ -756,6 +756,10 @@ fn test_std_library() { loop line in lines(\"hello\nworld\") { echo line } + // Split a multiline string into a list of string by one or more spaces + loop word in words(\"hello world ciao mondo\") { + echo word + } // Join a list of strings into a string echo join(split(\"hello world\", \"l\"), \"l\") // Transform string into a lowercase string @@ -790,6 +794,10 @@ fn test_std_library() { "he o wor d", "hello", "world", + "hello", + "world", + "ciao", + "mondo", "hello world", "hello world", "HELLO WORLD",