@@ -15,12 +15,15 @@ INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _conv.inc.sh_"
1515
1616# #
1717# SUBPROCESS
18- # conv_chr_psst <charCode>
18+ # conv_chr_psst <charCode> [<charCode>] [<charCode>] ...
1919#
2020# SUMMARY
2121# Returns character whose character code is `charCode`.
2222# E.g `65` becomes `A`, `97` becomes `a` and `32` becomes space.
2323#
24+ # If multiple character codes are passed, the resulting characters are
25+ # returned as a concatinated string.
26+ #
2427# PARAMETERS
2528# charCode: Character code of desired character.
2629#
@@ -31,44 +34,43 @@ INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _conv.inc.sh_"
3134# 3: Character code is newline (`\n``), which cannot be captured.
3235#
3336# OUTPUT
34- # stdout: The characters whose code is `charCode`.
37+ # stdout: The character whose code is `charCode`.
3538#
3639# SAMPLE
3740# digit9=$( chr_psst 57 )
3841#
3942conv_chr_psst ()
4043(
4144 func=" chr_psst"
42- assert_argc_psst " $func " 1 $#
45+ assert_minargc_psst " $func " 1 $#
4346 assert_hasarg_psst " $func " " charCode" " $1 "
4447
45- charCode=$1
48+ while [ -n " ${1-} " ]
49+ do
50+ charCode=$1
51+ test_is_int_psst " $charCode " || return 1
52+ { [ " $charCode " -lt 0 ] || [ " $charCode " -gt 255 ]; } && return 2
53+ [ " $charCode " != " 10" ] || return 3
4654
47- test_is_int_psst " $charCode " || return 1
48- { [ " $charCode " -lt 0 ] || [ " $charCode " -gt 255 ]; } && return 2
49- [ " $charCode " != " 10" ] || return 3
50-
51- pattern=$( printf " %03o" " $charCode " )
52- # shellcheck disable=SC2059
53- printf " \\ ${pattern} "
55+ printf " %b" " $( printf ' \%o' " $charCode " ) "
56+ shift
57+ done
5458)
5559
5660
5761# #
5862# SUBPROCESS
59- # conv_ord_psst <char >
63+ # conv_ord_psst <chars >
6064#
6165# SUMMARY
6266# Returns character code of character.
6367# E.g `A` becomes `65`, `a` becomes `97`, and space becomes `32`.
6468#
65- # PARAMETERS
66- # char: Character whose code shall be returned .
69+ # If multiple characters are passed, the resulting character codes are
70+ # returned as a concatinated string separated by space .
6771#
68- # RETURNS
69- # 0: Argument was a valid character.
70- # 1: Argument contained zero characters.
71- # 2: Argument contained more than one character.
72+ # PARAMETERS
73+ # char: Characters whose code shall be returned.
7274#
7375# OUTPUT
7476# stdout: The character code of `char`.
@@ -78,13 +80,23 @@ conv_chr_psst()
7880#
7981conv_ord_psst ()
8082(
81- func_psst=" ord_psst"
82- assert_argc_psst " $func_psst " 1 $#
83+ func=" ord_psst"
84+ assert_argc_psst " $func " 1 $#
85+ assert_hasarg_psst " $func " " chars" " $1 "
8386
84- char=$1
87+ chars=$1
88+ [ ${# chars} -eq 1 ] && { LC_CTYPE=C printf " %d" " '$chars " ; return 0; }
8589
86- [ -n " $char " ] || return 1
87- [ ${# char} -eq 1 ] || return 2
90+ printf " %s" " $chars " | (
91+ sep=
92+ while read -r _unused_ octalValue << EOF
93+ $( dd bs=1 count=1 2> /dev/null | od -b )
94+ EOF
95+ do
96+ [ -n " $octalValue " ] || return 0
97+ LC_CTYPE=C printf " %s%d" " $sep " " 0$octalValue "
98+ sep=" "
99+ done
100+ )
88101
89- LC_CTYPE=C printf " %d" " '$char "
90102)
0 commit comments