From 4e67719d34b6507b1edd51ba0f623a834595f2b8 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 12 May 2020 11:48:31 +0900 Subject: [PATCH] global: use "local LC_*=C" instead of "LC_*=C func" --- src/color.sh | 7 ++++--- src/decode.sh | 4 ++-- src/util.sh | 41 ++++++++++++++++------------------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/color.sh b/src/color.sh index 9207ac40..390ffef5 100644 --- a/src/color.sh +++ b/src/color.sh @@ -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 diff --git a/src/decode.sh b/src/decode.sh index 19240f2f..d3ed588d 100644 --- a/src/decode.sh +++ b/src/decode.sh @@ -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 復元時のエラーメッセージ (外側の値が不正な時) を捨てる為に必要。 @@ -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; diff --git a/src/util.sh b/src/util.sh index f4a4d832..ad1f4f5e 100644 --- a/src/util.sh +++ b/src/util.sh @@ -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... @@ -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 @@ -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 @@ -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 ]] }