Skip to content

Commit

Permalink
global: use "local LC_*=C" instead of "LC_*=C func"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 16, 2020
1 parent 983e8a9 commit 4e67719
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
7 changes: 4 additions & 3 deletions src/color.sh
Expand Up @@ -783,15 +783,16 @@ function ble/highlight/layer:plain/update {
ch=${text:i:1}

# LC_COLLATE for cygwin collation
LC_COLLATE=C ble/highlight/layer:plain/update/.getch
local LC_ALL= LC_COLLATE=C
ble/highlight/layer:plain/update/.getch

_ble_highlight_layer_plain_buff[i]=$ch
done &>/dev/null # Note: suppress LC_COLLATE errors #D1205
done
fi

PREV_BUFF=_ble_highlight_layer_plain_buff
((PREV_UMIN=DMIN,PREV_UMAX=DMAX))
}
} 2>/dev/null # Note: suppress LC_COLLATE errors #D1205

## 関数 ble/highlight/layer:plain/getg index
## @var[out] g
Expand Down
4 changes: 2 additions & 2 deletions src/decode.sh
Expand Up @@ -2088,7 +2088,7 @@ function ble-decode-bind/.generate-source-to-unbind-default {
fi
echo '__BINDP__'
builtin bind -sp
} | LC_ALL=C ble-decode-bind/.generate-source-to-unbind-default/.process
} | ble-decode-bind/.generate-source-to-unbind-default/.process

# Note: 2>/dev/null は、(1) bind -X のエラーメッセージ、及び、
# (2) LC_ALL 復元時のエラーメッセージ (外側の値が不正な時) を捨てる為に必要。
Expand All @@ -2098,7 +2098,7 @@ function ble-decode-bind/.generate-source-to-unbind-default/.process {
# Note: Solaris xpg4 awk では gsub の置換後のエスケープシーケンスも処理される
[[ $_ble_bin_awk_solaris_xpg4 == yes ]] && Q="'$b$b''"
local QUOT_Q=\"${Q//"$b"/$b$b}\"
ble/bin/awk -v q="$q" '
LC_ALL=C ble/bin/awk -v q="$q" '
BEGIN {
Q = '"$QUOT_Q"';
mode = 1;
Expand Down
41 changes: 16 additions & 25 deletions src/util.sh
Expand Up @@ -554,7 +554,7 @@ function ble/string#toggle-case {
fi
ble/array#push buff "$ch"
done
IFS= eval 'ret="${buff[*]-}"'
IFS= builtin eval 'ret="${buff[*]-}"'
} 2>/dev/null
## 関数 ble/string#tolower text...
## 関数 ble/string#toupper text...
Expand Down Expand Up @@ -724,24 +724,16 @@ function ble/string#create-unicode-progress-bar {

ret=$out
}

if ((_ble_bash>=40200)); then
function ble/util/strlen {
LC_ALL= LC_CTYPE=C builtin eval 'ret=${#1}' 2>/dev/null
}
function ble/util/substr {
LC_ALL= LC_CTYPE=C builtin eval 'ret=${1:$2:$3}' 2>/dev/null
}
else
function ble/util/strlen {
local LC_ALL= LC_CTYPE=C
ret=${#1}
} 2>/dev/null
function ble/util/substr {
local LC_ALL= LC_CTYPE=C
ret=${1:$2:$3}
} 2>/dev/null
fi
# Note: Bash-4.1 以下では "LC_CTYPE=C 組み込みコマンド" の形式だと
# locale がその場で適用されないバグがある。
function ble/util/strlen {
local LC_ALL= LC_CTYPE=C
ret=${#1}
} 2>/dev/null
function ble/util/substr {
local LC_ALL= LC_CTYPE=C
ret=${1:$2:$3}
} 2>/dev/null

function ble/path#remove {
[[ $2 ]] || return
Expand Down Expand Up @@ -968,13 +960,11 @@ function ble/util/type {
}

if ((_ble_bash>=40000)); then
function ble/util/is-stdin-ready { IFS= LC_ALL= LC_CTYPE=C builtin read -t 0; } &>/dev/null
elif ((_ble_bash>=40000)); then
# #D1341 対策
# #D1341 対策 変数代入形式だと組み込みコマンドにロケールが適用されない。
function ble/util/is-stdin-ready {
local IFS= LC_ALL= LC_CTYPE=C
builtin read -t 0
} 2>/dev/null
} &>/dev/null
else
function ble/util/is-stdin-ready { false; }
fi
Expand Down Expand Up @@ -1179,8 +1169,9 @@ _ble_util_rex_isprint='^[ -~]+'
## @var[out] BASH_REMATCH ble-exit/text/update/position で使用する。
function ble/util/isprint+ {
# LC_COLLATE=C ... &>/dev/null for cygwin collation
LC_COLLATE=C ble/util/isprint+.impl "$@"
} &>/dev/null # Note: suppress LC_COLLATE errors #D1205
local LC_ALL= LC_COLLATE=C
ble/util/isprint+.impl "$@"
} 2>/dev/null # Note: suppress LC_COLLATE errors #D1205
function ble/util/isprint+.impl {
[[ $1 =~ $_ble_util_rex_isprint ]]
}
Expand Down

0 comments on commit 4e67719

Please sign in to comment.