Skip to content

Commit

Permalink
drop: clean_array() function - not needed
Browse files Browse the repository at this point in the history
Since we are using git with `-z` flag, we no longer need `clean_array()` functionality.
  • Loading branch information
jamacku committed Aug 10, 2023
1 parent ac11e6a commit 5fe0863
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 86 deletions.
32 changes: 1 addition & 31 deletions src/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,37 +227,7 @@ file_to_array () {

[[ ${UNIT_TESTS:-1} -eq 0 ]] && echo "${output[@]}"

clean_array "$2" "${output[@]}" && return 0
}

# Function to trim spaces and new lines from array elements
# https://stackoverflow.com/a/9715377
# https://stackoverflow.com/a/19347380
# https://unix.stackexchange.com/a/225517
# https://unix.stackexchange.com/a/360648
# $1 - name of a variable where the result array will be stored
# $@ - source array
# $? - return value - 0 on success
clean_array () {
[[ $# -le 1 ]] && return 1
local output="$1"
shift
local input=("$@")

local extglob_state=0
if ! shopt -q extglob; then
extglob_state=1
shopt -s extglob
fi

for i in "${input[@]}"; do
local cleaned_item=""
cleaned_item=$(printf '%s' "${i##+([[:space:]])}") \
&& cleaned_item=$(printf '%s' "${cleaned_item%%+([[:space:]])}")
eval "${output}"+=\("$(printf '%q' "${cleaned_item}")"\)
done

[[ ${extglob_state} -ne 0 ]] && shopt -u extglob
eval "${2}"=\("${output[*]@Q}"\)
}

# Evaluate if variable contains true value
Expand Down
55 changes: 0 additions & 55 deletions test/clean_array.bats

This file was deleted.

0 comments on commit 5fe0863

Please sign in to comment.