Commit 2502d7bb authored by Eric Coissac's avatar Eric Coissac

change IFS through calls to pushifs and popifs

parent adae0962
......@@ -10,6 +10,8 @@
#
include logging
include ifs
logdebug "Load sets package"
function newset() {
......@@ -25,29 +27,30 @@ function setaddvalue() {
local S="${1}"
local V="${2}"
eval $S[$(setsize $S)]=$V
local OIFS="$IFS"
IFS=$'\n'
pushifs $'\n'
eval "$S=(\$(echo \"\${$S[*]}\" | sort -u))"
IFS="$OIFS"
popifs
}
function setdelvalue() {
local S="${1}"
local V="${2}"
local OIFS="$IFS"
IFS=$'\n'
pushifs $'\n'
eval "$S=(\$(echo \"\${$S[*]}\" | grep -v \"$V\"))"
IFS="$OIFS"
popifs
}
function setcontains() {
local S="${1}"
local V="${2}"
local OIFS="$IFS"
IFS=$'\n'
pushifs $'\n'
eval "echo \"\${$S[*]}\" | grep -q \"$V\""
popifs
local status=$?
IFS="$OIFS"
return $status
}
......@@ -55,22 +58,22 @@ function setunion() {
local S="${1}"
local S1="${2}"
local S2="${3}"
local OIFS="$IFS"
IFS=$'\n'
pushifs $'\n'
eval "$S=(\$((echo \"\${$S1[*]}\";echo \"\${$S2[*]}\") | sort -u))"
IFS="$OIFS"
popifs
}
function setintersec() {
local S="${1}"
local S1="${2}"
local S2="${3}"
local OIFS="$IFS"
IFS=$'\n'
pushifs $'\n'
eval "$S=(\$((echo \"\${$S1[*]}\";echo \"\${$S2[*]}\") | \
sort | \
uniq -c | \
awk '(\$1==2)' | \
sed 's/^ *2 //'))"
IFS="$OIFS"
popifs
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment