summaryrefslogtreecommitdiffhomepage
path: root/tests/posix/charset.sh
blob: 53e519af5a26d1aa9af5bcfeff9d331b54e0c6bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Character classes and ranges must behave the same in ASCII and EBCDIC
# builds: in EBCDIC the letters are not contiguous (i|j and r|s have gaps).
all=abcdefghijklmnopqrstuvwxyz
n=0; rest=$all
while [ -n "$rest" ]; do
    c=${rest%"${rest#?}"}; rest=${rest#?}
    case $c in [a-z]) n=$((n+1)) ;; esac
done
echo "lower in [a-z]: $n"
ALL=ABCDEFGHIJKLMNOPQRSTUVWXYZ
n=0; rest=$ALL
while [ -n "$rest" ]; do
    c=${rest%"${rest#?}"}; rest=${rest#?}
    case $c in [A-Z]) n=$((n+1)) ;; esac
done
echo "upper in [A-Z]: $n"
n=0; rest=0123456789
while [ -n "$rest" ]; do
    c=${rest%"${rest#?}"}; rest=${rest#?}
    case $c in [0-9]) n=$((n+1)) ;; esac
done
echo "digits in [0-9]: $n"
for c in '{' '}' '~' '\' '^' '[' ']' '`' '|' '!' '#' '$' '@' ' ' _ . / -; do
    case $c in [a-z] | [A-Z] | [0-9]) echo "wrongly in a range: $c" ;; esac
done
for c in a i j r s z; do case $c in [a-i]) echo "$c in a-i" ;; [j-r]) echo "$c in j-r" ;; [s-z]) echo "$c in s-z" ;; esac; done
case j in [i-j]) echo "j in i-j" ;; esac
case k in [!a-j]) echo "k not in a-j" ;; esac
case B in [a-z]) echo "B wrongly lower" ;; *) echo "case sensitive" ;; esac
case m in [z-a]) echo "reversed range matched: $m" ;; *) echo "reversed range matches nothing" ;; esac
case _ in [[:alpha:]]) echo no ;; [[:punct:]]) echo "punct class" ;; esac
case x in [[:alpha:]]) echo "alpha class" ;; esac
case 5 in [[:digit:]]) echo "digit class" ;; esac
case ' ' in [[:space:]]) echo "space class" ;; esac
case Q in [[:upper:]]) echo "upper class" ;; esac
case q in [[:lower:][:digit:]]) echo "two classes" ;; esac
case f in [[:xdigit:]]) echo "xdigit class" ;; esac
x='{a}[b]~c^d|e\f'; echo "$x" ${#x}
echo "${x#\{}" "${x%\\f}" "${x##*|}"
IFS='|'; set -- $x; echo "$#"; unset IFS
printf '%s %c %5s|\n' 'tilde~' '^' '{}'
printf 'tab\there\nnewline done\n'
echo '!"#$%&()*+,-./:;<=>?@[\]^_`{|}~'
v='a	b'; set -- $v; echo $#
v='a
b'; set -- $v; echo $#
echo $((0x1F)) $((0Xff)) $((0xaBc))
i=0; while [ $i -lt 3 ]; do i=$((i+1)); done; echo "$i"
[ abc \< abd ] && echo "string less"
[ b \> a ] && echo "string greater"