Skip to content

Commit

Permalink
util (ble/string#split): optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jul 28, 2022
1 parent cc14f59 commit 5b3fc89
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ble-core.sh
Expand Up @@ -256,21 +256,23 @@ function ble/string#common-suffix {
## @param[in] str 分割する文字列を指定します。
##
function ble/string#split {
local IFS=$2
if [[ -o noglob ]]; then
# Note: 末尾の sep が無視されない様に、末尾に手で sep を 1 個追加している。
IFS=$2 builtin eval "$1=(\${*:3}\$2)"
builtin eval "$1=(\$3\$2)"
else
set -f
IFS=$2 builtin eval "$1=(\${*:3}\$2)"
builtin eval "$1=(\$3\$2)"
set +f
fi
}
function ble/string#split-words {
local IFS=$_ble_term_IFS
if [[ -o noglob ]]; then
IFS=$' \t\n' builtin eval "$1=(\${*:2})"
builtin eval "$1=(\$2)"
else
set -f
IFS=$' \t\n' builtin eval "$1=(\${*:2})"
builtin eval "$1=(\$2)"
set +f
fi
}
Expand Down

0 comments on commit 5b3fc89

Please sign in to comment.