dot

packages and services management
Log | Files | Refs | README

commit 21fa348aabb5e237081713b517d6aadb2116b517
parent 9bc2b2e94487d80cc48d2fecdd864945764d4dda
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Wed, 23 Aug 2017 02:28:19 +0200

iomenu/bin/io-unicode: rune to UTF-8 implementation in shell script

Diffstat:
Miomenu/bin/io-unicode | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 56 insertions(+), 4 deletions(-)

diff --git a/iomenu/bin/io-unicode b/iomenu/bin/io-unicode @@ -1,8 +1,60 @@ # prompt for an unicode character -mkdir -p "$CACHE" +URL=http://www.unicode.org/Public/UNIDATA/UnicodeData.txt -[ -f "$ROOT/var/cache/unicode" ] || -wget -O- http://www.unicode.org/Public/UNIDATA/UnicodeData.txt | -cut -d ';' -f +if ! [ -f "$ROOT/var/cache/unicode" ] +then + mkdir -p "$ROOT/var/cache" + wget -O - "$URL" | while IFS=';' read -r hex str trail + do + r=$((0x$hex)) + + if [ $r -le $((0x0000007f)) ] + then + o=\\$((r)) + + elif [ $r -le $((0x000007ff)) ] + then + o=\\$((0xc0 | (0x1f & (r >> 6)))) + o=$o\\$((0x80 | (0x3f & (r)))) + + elif [ $r -le $((0x0000ffff)) ] + then + o=\\$((0xe0 | (0x0f & (r >> 12)))) + o=$o\\$((0x80 | (0x3f & (r >> 6 )))) + o=$o\\$((0x80 | (0x3f & (r )))) + + elif [ $r -le $((0x001fffff)) ] + then + o=\\$((0xf0 | (0x07 & (r >> 18)))) + o=$o\\$((0x80 | (0x3f & (r >> 12)))) + o=$o\\$((0x80 | (0x3f & (r >> 6 )))) + o=$o\\$((0x80 | (0x3f & (r )))) + + elif [ $r -le $((0x03ffffff)) ] + then + o=\\$((0xf0 | (0x03 & (r >> 24)))) + o=$o\\$((0x80 | (0x3f & (r >> 18)))) + o=$o\\$((0x80 | (0x3f & (r >> 12)))) + o=$o\\$((0x80 | (0x3f & (r >> 6)))) + o=$o\\$((0x80 | (0x3f & (r )))) + + elif [ $r -le $((0x7fffffff)) ] + then + o=\\$((0xfc | (0x01 & (r >> 30)))) + o=$o\\$((0x80 | (0x3f & (r >> 24)))) + o=$o\\$((0x80 | (0x3f & (r >> 18)))) + o=$o\\$((0x80 | (0x3f & (r >> 12)))) + o=$o\\$((0x80 | (0x3f & (r >> 6)))) + o=$o\\$((0x80 | (0x3f & (r )))) + else + o='' + fi + + printf '%s\n' "$o" + + done > "$ROOT/var/cache/unicode" +fi + +iomenu < "$ROOT/var/cache/unicode"