Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions lib/bash/str/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ base_str_join joined "|" parts
- Predicate helpers require exactly two arguments, return shell status, and do
not print output.
- `base_str_split` preserves empty fields between repeated delimiters.
- `base_str_split` preserves an empty first field when the input begins with the
separator.
- `base_str_split` preserves a trailing empty field when the input ends with the
separator.
- `base_str_join` preserves empty array elements, including trailing empty elements.
Expand Down
11 changes: 11 additions & 0 deletions lib/bash/str/tests/lib_str.bats
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ EOF
[ "${parts[2]}" = "" ]
}

@test "base_str_split preserves a leading empty field before the first separator" {
local -a parts=()

base_str_split parts ",alpha,beta" ","

[ "${#parts[@]}" -eq 3 ]
[ "${parts[0]}" = "" ]
[ "${parts[1]}" = "alpha" ]
[ "${parts[2]}" = "beta" ]
}

@test "base_str_split can store results in an array named fields" {
local -a fields=()

Expand Down
Loading