|
Lucio Andrés Illanes Albornoz |
2b85d0 |
#
|
|
|
8d7a8a |
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 LucĂa Andrea Illanes Albornoz <lucia@luciaillanes.de>
|
|
Lucio Andrés Illanes Albornoz |
e1d469 |
# set +o errexit -o noglob -o nounset is assumed.
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
#
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_isnumber() {
|
|
|
e9fa07 |
local _ri_s="${1}" \
|
|
|
e9fa07 |
_ri_rc=0;
|
|
|
e9fa07 |
|
|
|
e9fa07 |
while [ "${_ri_s:+1}" = 1 ]; do
|
|
|
e9fa07 |
case "${_ri_s}" in
|
|
|
e9fa07 |
[0-9]*) _ri_s="${_ri_s#[0-9]}"; ;;
|
|
|
e9fa07 |
*) _ri_rc=1; break; ;;
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
esac; done;
|
|
|
e9fa07 |
|
|
|
e9fa07 |
return "${_ri_rc}";
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
};
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
|
|
Lucio Andrés Illanes Albornoz |
0d1c4f |
rtl_match() {
|
|
|
e9fa07 |
local _rm_s="${1}" _rm_find="${2}";
|
|
|
e9fa07 |
|
|
|
e9fa07 |
if [ "${_rm_s#${_rm_find}}" != "${_rm_s}" ]; then
|
|
Lucio Andrés Illanes Albornoz |
0d1c4f |
return 0;
|
|
Lucio Andrés Illanes Albornoz |
0d1c4f |
else
|
|
Lucio Andrés Illanes Albornoz |
0d1c4f |
return 1;
|
|
Lucio Andrés Illanes Albornoz |
0d1c4f |
fi;
|
|
Lucio Andrés Illanes Albornoz |
0d1c4f |
};
|
|
Lucio Andrés Illanes Albornoz |
0d1c4f |
|
|
Lucio Andrés Illanes Albornoz |
b6a9a1 |
rtl_matchr() {
|
|
|
e9fa07 |
local _rmr_s="${1}" _rmr_find="${2}";
|
|
|
e9fa07 |
|
|
|
e9fa07 |
if [ "${_rmr_s%${_rmr_find}}" != "${_rmr_s}" ]; then
|
|
Lucio Andrés Illanes Albornoz |
b6a9a1 |
return 0;
|
|
Lucio Andrés Illanes Albornoz |
b6a9a1 |
else
|
|
Lucio Andrés Illanes Albornoz |
b6a9a1 |
return 1;
|
|
Lucio Andrés Illanes Albornoz |
b6a9a1 |
fi;
|
|
Lucio Andrés Illanes Albornoz |
b6a9a1 |
};
|
|
Lucio Andrés Illanes Albornoz |
b6a9a1 |
|
|
|
e9fa07 |
rtl_setrstatus() {
|
|
|
e9fa07 |
local _rsrs_rstatus="${1#\$}" _rsrs_status="${2}";
|
|
|
e9fa07 |
eval ${_rsrs_rstatus}=\"${_rsrs_status}\";
|
|
|
e9fa07 |
return 0;
|
|
|
e9fa07 |
};
|
|
|
e9fa07 |
|
|
Lucio Andrés Illanes Albornoz |
8a27f9 |
rtl_subst() {
|
|
|
e9fa07 |
rtl_subst2 "${1}" "${1}" "${2}" "${3}";
|
|
|
e9fa07 |
};
|
|
|
e9fa07 |
|
|
|
e9fa07 |
rtl_subst2() {
|
|
|
e9fa07 |
local _rs2_rs="${1#\$}" _rs2_rs_out="${2#\$}" _rs2_find="${3}" _rs2_replace="${4}" \
|
|
|
e9fa07 |
_rs2_prefix="" _rs2_s="" _rs2_s_new="";
|
|
|
e9fa07 |
|
|
|
e9fa07 |
eval _rs2_s="\${${_rs2_rs}}";
|
|
|
e9fa07 |
while [ "${_rs2_s:+1}" = 1 ]; do
|
|
|
e9fa07 |
case "${_rs2_s}" in
|
|
|
e9fa07 |
*${_rs2_find}*) _rs2_prefix="${_rs2_s%%${_rs2_find}*}"; _rs2_s="${_rs2_s#*${_rs2_find}}";
|
|
|
e9fa07 |
_rs2_s_new="${_rs2_s_new:+${_rs2_s_new}}${_rs2_prefix}${_rs2_replace}"; ;;
|
|
|
e9fa07 |
*) _rs2_s_new="${_rs2_s_new:+${_rs2_s_new}}${_rs2_s}"; _rs2_s=""; ;;
|
|
Lucio Andrés Illanes Albornoz |
8a27f9 |
esac; done;
|
|
|
e9fa07 |
eval ${_rs2_rs_out}='${_rs2_s_new}';
|
|
|
e9fa07 |
return 0;
|
|
Lucio Andrés Illanes Albornoz |
8a27f9 |
};
|
|
Lucio Andrés Illanes Albornoz |
8a27f9 |
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_tolower() {
|
|
|
e9fa07 |
rtl_tolower2 "${1}" "${1}";
|
|
|
e9fa07 |
};
|
|
|
e9fa07 |
|
|
|
e9fa07 |
rtl_tolower2() {
|
|
|
e9fa07 |
local _rtl2_rs="${1#\$}" _rtl2_rs_out="${2#\$}" \
|
|
|
e9fa07 |
_rtl2_s="" _rtl2_s_new="";
|
|
|
e9fa07 |
|
|
|
e9fa07 |
eval _rtl2_s="\${${_rtl2_rs}}";
|
|
|
e9fa07 |
|
|
|
e9fa07 |
while [ "${_rtl2_s:+1}" = 1 ]; do
|
|
|
e9fa07 |
case "${_rtl2_s}" in
|
|
|
e9fa07 |
A*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}a"; _rtl2_s="${_rtl2_s#A}"; ;;
|
|
|
e9fa07 |
B*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}b"; _rtl2_s="${_rtl2_s#B}"; ;;
|
|
|
e9fa07 |
C*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}c"; _rtl2_s="${_rtl2_s#C}"; ;;
|
|
|
e9fa07 |
D*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}d"; _rtl2_s="${_rtl2_s#D}"; ;;
|
|
|
e9fa07 |
E*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}e"; _rtl2_s="${_rtl2_s#E}"; ;;
|
|
|
e9fa07 |
F*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}f"; _rtl2_s="${_rtl2_s#F}"; ;;
|
|
|
e9fa07 |
G*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}g"; _rtl2_s="${_rtl2_s#G}"; ;;
|
|
|
e9fa07 |
H*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}h"; _rtl2_s="${_rtl2_s#H}"; ;;
|
|
|
e9fa07 |
I*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}i"; _rtl2_s="${_rtl2_s#I}"; ;;
|
|
|
e9fa07 |
J*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}j"; _rtl2_s="${_rtl2_s#J}"; ;;
|
|
|
e9fa07 |
K*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}k"; _rtl2_s="${_rtl2_s#K}"; ;;
|
|
|
e9fa07 |
L*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}l"; _rtl2_s="${_rtl2_s#L}"; ;;
|
|
|
e9fa07 |
M*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}m"; _rtl2_s="${_rtl2_s#M}"; ;;
|
|
|
e9fa07 |
N*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}n"; _rtl2_s="${_rtl2_s#N}"; ;;
|
|
|
e9fa07 |
O*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}o"; _rtl2_s="${_rtl2_s#O}"; ;;
|
|
|
e9fa07 |
P*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}p"; _rtl2_s="${_rtl2_s#P}"; ;;
|
|
|
e9fa07 |
Q*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}q"; _rtl2_s="${_rtl2_s#Q}"; ;;
|
|
|
e9fa07 |
R*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}r"; _rtl2_s="${_rtl2_s#R}"; ;;
|
|
|
e9fa07 |
S*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}s"; _rtl2_s="${_rtl2_s#S}"; ;;
|
|
|
e9fa07 |
T*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}t"; _rtl2_s="${_rtl2_s#T}"; ;;
|
|
|
e9fa07 |
U*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}u"; _rtl2_s="${_rtl2_s#U}"; ;;
|
|
|
e9fa07 |
V*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}v"; _rtl2_s="${_rtl2_s#V}"; ;;
|
|
|
e9fa07 |
W*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}w"; _rtl2_s="${_rtl2_s#W}"; ;;
|
|
|
e9fa07 |
X*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}x"; _rtl2_s="${_rtl2_s#X}"; ;;
|
|
|
e9fa07 |
Y*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}y"; _rtl2_s="${_rtl2_s#Y}"; ;;
|
|
|
e9fa07 |
Z*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}z"; _rtl2_s="${_rtl2_s#Z}"; ;;
|
|
Lucio Andrés Illanes Albornoz |
a7ecdc |
[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]*)
|
|
|
e9fa07 |
_rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}${_rtl2_s%%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*}";
|
|
|
e9fa07 |
while [ "${_rtl2_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}" != "${_rtl2_s}" ]; do
|
|
|
e9fa07 |
_rtl2_s="${_rtl2_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}";
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
done; ;;
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
esac; done;
|
|
|
e9fa07 |
eval ${_rtl2_rs_out}='${_rtl2_s_new}';
|
|
|
e9fa07 |
|
|
|
e9fa07 |
return 0;
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
};
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_toupper() {
|
|
|
e9fa07 |
rtl_toupper2 "${1}" "${1}";
|
|
|
e9fa07 |
};
|
|
|
e9fa07 |
|
|
|
e9fa07 |
rtl_toupper2() {
|
|
|
e9fa07 |
local _rtu2_rs="${1#\$}" _rtu2_rs_out="${2#\$}" _rtu2_s="" _rtu2_s_new="";
|
|
|
e9fa07 |
|
|
|
e9fa07 |
eval _rtu2_s="\${${_rtu2_rs}}";
|
|
|
e9fa07 |
|
|
|
e9fa07 |
while [ "${_rtu2_s:+1}" = 1 ]; do
|
|
|
e9fa07 |
case "${_rtu2_s}" in
|
|
|
e9fa07 |
a*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}A"; _rtu2_s="${_rtu2_s#a}"; ;;
|
|
|
e9fa07 |
b*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}B"; _rtu2_s="${_rtu2_s#b}"; ;;
|
|
|
e9fa07 |
c*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}C"; _rtu2_s="${_rtu2_s#c}"; ;;
|
|
|
e9fa07 |
d*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}D"; _rtu2_s="${_rtu2_s#d}"; ;;
|
|
|
e9fa07 |
e*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}E"; _rtu2_s="${_rtu2_s#e}"; ;;
|
|
|
e9fa07 |
f*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}F"; _rtu2_s="${_rtu2_s#f}"; ;;
|
|
|
e9fa07 |
g*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}G"; _rtu2_s="${_rtu2_s#g}"; ;;
|
|
|
e9fa07 |
h*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}H"; _rtu2_s="${_rtu2_s#h}"; ;;
|
|
|
e9fa07 |
i*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}I"; _rtu2_s="${_rtu2_s#i}"; ;;
|
|
|
e9fa07 |
j*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}J"; _rtu2_s="${_rtu2_s#j}"; ;;
|
|
|
e9fa07 |
k*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}K"; _rtu2_s="${_rtu2_s#k}"; ;;
|
|
|
e9fa07 |
l*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}L"; _rtu2_s="${_rtu2_s#l}"; ;;
|
|
|
e9fa07 |
m*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}M"; _rtu2_s="${_rtu2_s#m}"; ;;
|
|
|
e9fa07 |
n*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}N"; _rtu2_s="${_rtu2_s#n}"; ;;
|
|
|
e9fa07 |
o*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}O"; _rtu2_s="${_rtu2_s#o}"; ;;
|
|
|
e9fa07 |
p*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}P"; _rtu2_s="${_rtu2_s#p}"; ;;
|
|
|
e9fa07 |
q*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Q"; _rtu2_s="${_rtu2_s#q}"; ;;
|
|
|
e9fa07 |
r*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}R"; _rtu2_s="${_rtu2_s#r}"; ;;
|
|
|
e9fa07 |
s*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}S"; _rtu2_s="${_rtu2_s#s}"; ;;
|
|
|
e9fa07 |
t*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}T"; _rtu2_s="${_rtu2_s#t}"; ;;
|
|
|
e9fa07 |
u*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}U"; _rtu2_s="${_rtu2_s#u}"; ;;
|
|
|
e9fa07 |
v*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}V"; _rtu2_s="${_rtu2_s#v}"; ;;
|
|
|
e9fa07 |
w*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}W"; _rtu2_s="${_rtu2_s#w}"; ;;
|
|
|
e9fa07 |
x*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}X"; _rtu2_s="${_rtu2_s#x}"; ;;
|
|
|
e9fa07 |
y*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Y"; _rtu2_s="${_rtu2_s#y}"; ;;
|
|
|
e9fa07 |
z*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Z"; _rtu2_s="${_rtu2_s#z}"; ;;
|
|
Lucio Andrés Illanes Albornoz |
a7ecdc |
[!abcdefghijklmnopqrstuvwxyz]*)
|
|
|
e9fa07 |
_rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}${_rtu2_s%%[abcdefghijklmnopqrstuvwxyz]*}";
|
|
|
e9fa07 |
while [ "${_rtu2_s#[!abcdefghijklmnopqrstuvwxyz]}" != "${_rtu2_s}" ]; do
|
|
|
e9fa07 |
_rtu2_s="${_rtu2_s#[!abcdefghijklmnopqrstuvwxyz]}";
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
done; ;;
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
esac; done;
|
|
|
e9fa07 |
eval ${_rtu2_rs_out}='${_rtu2_s_new}';
|
|
|
e9fa07 |
|
|
|
e9fa07 |
return 0;
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
};
|
|
Lucio Andrés Illanes Albornoz |
2b85d0 |
|
|
|
64844b |
# vim:filetype=sh textwidth=0
|