configure: add basic list utilities

inlist determines whether an item is in a list
removefrom returns a list with an element removed
trim strips whitespace from a string, using xargs
This commit is contained in:
Jeremy Baxter 2024-02-27 17:59:19 +13:00
parent 42f95378ec
commit 5313601c79

38
configure vendored
View file

@ -25,6 +25,44 @@ throw () {
exit 1
}
#
## list utilities
#
# Returns 0 if the given item is in the given list, otherwise returns 1.
inlist () {
local item="$1"
local list="$2"
for elem in $list; do
if [ "$elem" = "$item" ]; then
return 0
fi
done
return 1
}
# Removes the given item from the given list and returns the new list.
removefrom () {
local item="$1"
local list="$2"
local newlist=""
for elem in $list; do
if ! [ "$elem" = "$item" ]; then
newlist="$newlist $elem"
fi
done
printf '%s' "$newlist"
}
# Trims the given string of leading and trailing whitespace.
trim () {
printf '%s' "$1" | xargs
}
#
## flag generators
#