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:
parent
42f95378ec
commit
5313601c79
1 changed files with 38 additions and 0 deletions
38
configure
vendored
38
configure
vendored
|
@ -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
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue