Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add words function to standard library #75

Merged
merged 9 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/std/main.ab
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ pub fun lines(text: Text): [Text] {
return result
}

pub fun words(text: Text): [Text] {
let result = [Text]
kilianc marked this conversation as resolved.
Show resolved Hide resolved
kilianc marked this conversation as resolved.
Show resolved Hide resolved
unsafe $read -rd '' -a {nameof result} <<<"\${nameof text}"$
kilianc marked this conversation as resolved.
Show resolved Hide resolved
return result
kilianc marked this conversation as resolved.
Show resolved Hide resolved
}

pub fun join(list: [Text], delimiter: Text): Text {
return unsafe $IFS="{delimiter}" ; echo "\$\{{nameof list}[*]}"$
}
Expand Down
8 changes: 8 additions & 0 deletions src/tests/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -790,6 +794,10 @@ fn test_std_library() {
"he o wor d",
"hello",
"world",
"hello",
"world",
"ciao",
"mondo",
"hello world",
"hello world",
"HELLO WORLD",
Expand Down