mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-22 15:35:09 +00:00
bashbot.sh: jsonDecode: use printf
This commit is contained in:
parent
abe058a53a
commit
0794506753
@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb
|
|||||||
# 8 - curl/wget missing
|
# 8 - curl/wget missing
|
||||||
# 10 - not bash!
|
# 10 - not bash!
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.30-dev-13-g29fa5cf
|
#### $$VERSION$$ v1.30-dev-18-gabe058a
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
# emmbeded system may claim bash but it is not
|
# emmbeded system may claim bash but it is not
|
||||||
@ -146,7 +146,7 @@ export BASHBOTDEBUG
|
|||||||
# shellcheck disable=SC2094
|
# shellcheck disable=SC2094
|
||||||
debug_checks(){ {
|
debug_checks(){ {
|
||||||
[ -z "${BASHBOTDEBUG}" ] && return
|
[ -z "${BASHBOTDEBUG}" ] && return
|
||||||
local where token; where="$1"; shift
|
local token where="$1"; shift
|
||||||
printf "%(%c)T: debug_checks: %s: bashbot.sh %s\n" -1 "${where}" "${1##*/}"
|
printf "%(%c)T: debug_checks: %s: bashbot.sh %s\n" -1 "${where}" "${1##*/}"
|
||||||
# shellcheck disable=SC2094
|
# shellcheck disable=SC2094
|
||||||
[ -z "${DEBUGLOG}" ] && printf "%(%c)T: %s\n" -1 "DEBUGLOG not set! =========="
|
[ -z "${DEBUGLOG}" ] && printf "%(%c)T: %s\n" -1 "DEBUGLOG not set! =========="
|
||||||
@ -651,15 +651,14 @@ getBotName() {
|
|||||||
# pure bash implementation, done by KayM (@gnadelwartz)
|
# pure bash implementation, done by KayM (@gnadelwartz)
|
||||||
# see https://stackoverflow.com/a/55666449/9381171
|
# see https://stackoverflow.com/a/55666449/9381171
|
||||||
JsonDecode() {
|
JsonDecode() {
|
||||||
local out="$1" remain="" U=""
|
local remain U out="$1"
|
||||||
local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)'
|
local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)'
|
||||||
while [[ "${out}" =~ ${regexp} ]] ; do
|
while [[ "${out}" =~ ${regexp} ]] ; do
|
||||||
U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 ))
|
U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 ))
|
||||||
remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}"
|
remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}"
|
||||||
out="${BASH_REMATCH[1]}"
|
out="${BASH_REMATCH[1]}"
|
||||||
done
|
done
|
||||||
#printf "%b\n" "${out}${remain}" # seems to work ... dealyed to next dev
|
printf "%b\n" "${out}${remain}"
|
||||||
echo -e "${out}${remain}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonGetString() {
|
JsonGetString() {
|
||||||
|
Loading…
Reference in New Issue
Block a user