commit: f7a0474438f6571cf105fe7aa8bf3831f8bddb09 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Wed Sep 6 13:31:56 2017 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Wed Sep 6 13:31:56 2017 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f7a04744
eapi7-ver.eclass: Shift component indexes to account for possible s0 eclass/eapi7-ver.eclass | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/eclass/eapi7-ver.eclass b/eclass/eapi7-ver.eclass index 2485c45637b..e9f2c453514 100644 --- a/eclass/eapi7-ver.eclass +++ b/eclass/eapi7-ver.eclass @@ -34,12 +34,17 @@ _version_parse_range() { [[ ${start} -gt 0 ]] && [[ -z ${end} || ${start} -le ${end} ]] || die } +# RETURNS: +# comp=( s0 c1 s1 c2 s2... ) +# where s - separator, c - component _version_split() { local v=$1 LC_ALL=C + comp=("") + # get first component [[ ${v} =~ ^([A-Za-z]*|[0-9]*) ]] || die - comp=("${BASH_REMATCH[1]}") + comp+=("${BASH_REMATCH[1]}") v=${v:${#BASH_REMATCH[0]}} # get remaining separators and components @@ -59,9 +64,9 @@ version_cut() { local IFS= if [[ ${end} ]]; then - echo "${comp[*]:(start-1)*2:(end-start)*2+1}" + echo "${comp[*]:(start-1)*2+1:(end-start)*2+1}" else - echo "${comp[*]:(start-1)*2}" + echo "${comp[*]:(start-1)*2+1}" fi } @@ -74,7 +79,7 @@ version_rs() { while [[ $# -ge 2 ]]; do _version_parse_range "$1" [[ ${end} && ${end} -le $((${#comp[@]}/2)) ]] || end=$((${#comp[@]}/2)) - for (( i = start*2 - 1; i < end*2; i+=2 )); do + for (( i = start*2; i <= end*2; i+=2 )); do comp[i]=$2 done shift 2