tDisplay utf8 char from specified range - scripts - various script and utils
 (HTM) git clone git://z3bra.org/scripts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit f9eb8574d39e0cbcb5aff083e8dd1c62570aab02
 (DIR) parent df123e5abf212e2a893be14930d1faff88aeaf89
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Wed, 19 Mar 2014 13:43:07 +0100
       
       Display utf8 char from specified range
       
       Diffstat:
         A utf8.sh                             |      52 +++++++++++++++++++++++++++++++
       
       1 file changed, 52 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/utf8.sh b/utf8.sh
       t@@ -0,0 +1,52 @@
       +#!/bin/bash
       +
       +usage() {
       +
       +    echo "`basename $0` [min max] (min, max: 0x0000..0xffff)"
       +
       +}
       +
       +fast_chr() {
       +    local __octal
       +    local __char
       +    printf -v __octal '%03o' $1
       +    printf -v __char \\$__octal
       +    REPLY=$__char
       +}
       +
       +function unichr {
       +    local c=$1  # ordinal of char
       +    local l=0   # byte ctr
       +    local o=63  # ceiling
       +    local p=128 # accum. bits
       +    local s=''  # output string
       +
       +    (( c < 0x80 )) && { fast_chr "$c"; echo -n "$REPLY"; return; }
       +
       +    while (( c > o )); do
       +        fast_chr $(( t = 0x80 | c & 0x3f ))
       +        s="$REPLY$s"
       +        (( c >>= 6, l++, p += o+1, o>>=1 ))
       +    done
       +
       +    fast_chr $(( t = p | c ))
       +    echo -n "$REPLY$s "
       +}
       +
       +min=0xe000
       +max=0xe1a0
       +
       +if test $# -gt 1; then
       +    if test $# -eq 2; then
       +        min=$1
       +        max=$2
       +    fi
       +else
       +    usage
       +    exit 1
       +fi
       +
       +## test harness
       +for (( i=$min; i<$max; i++ )); do
       +    unichr $i
       +done