mirror of
https://github.com/Pmodules/Pmodules.git
synced 2026-07-02 04:00:48 +02:00
Merge branch '140-std-split_fname-remove-leading-slash' into 'master'
Resolve "std:split_fname(): remove leading slash" Closes #140 See merge request Pmodules/src!110
This commit is contained in:
+20
-7
@@ -133,16 +133,29 @@ std::replace_path () {
|
||||
}
|
||||
|
||||
#
|
||||
# split file name
|
||||
# split an absolute path
|
||||
#
|
||||
std::split_fname() {
|
||||
local -r savedIFS="${IFS}"
|
||||
# Args:
|
||||
# $1 upvar
|
||||
# $2 absolute path
|
||||
# $3 opt upvar: number of components
|
||||
#
|
||||
std::split_abspath() {
|
||||
local parts="$1"
|
||||
local -r path="$2"
|
||||
if [[ "${path:0:1}" == '/' ]]; then
|
||||
local -r std__split_path_tmp="${path:1}"
|
||||
else
|
||||
std::die 255 "Oops: Internal error in '${FUNCNAME[0]}' called by '${FUNCNAME[1]}' }"
|
||||
fi
|
||||
|
||||
IFS='/'
|
||||
local std__split_fname_result__=( $(echo "${@: -1}") )
|
||||
IFS=${savedIFS}
|
||||
eval $1=\(\"\${std__split_fname_result__[@]}\"\)
|
||||
local std__split_path_result=( ${std__split_path_tmp} )
|
||||
unset IFS
|
||||
std::upvar ${parts} "${std__split_path_result[@]}"
|
||||
if (( $# >= 3 )); then
|
||||
eval $2=${#std__split_fname_result__[@]}
|
||||
# return number of parts
|
||||
std::upvar "$3" ${#std__split_path_result[@]}
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user