Thanks TheLinuxDuck! You showed me an excellent way to work around the index vs parenthesis gizmoidal thingoid.
Code:
-local str charPos charC; str=( $@ )
+local str charPos charC char; str=( $@ )
if [ -z "${str}" -o "${#str}" -gt "${str_len}" ]; then return 1; fi
let charC=${#str}-1; for charPos in $(seq 0 "$charC"); do
-expr index "${str[0]:${charPos}:1}" " ${static_char_restr}" >/dev/null
+char="${str[0]:${charPos}:1}"
+expr index "${char/[\(\)]/!}" "${static_char_restr} " >/dev/null
case "$?" in 0) ;; 1|*) return 1;; esac; done; }
If you leave the "expensive" char by char parsing vs string comparison approach there, there are small but notable differences:
Code:
~/shell/duckie> ./regexp.sh "" ; echo $?
input: : is good!
0
Code:
[unsp tmp]$ . f_valStr
[unsp tmp]$ valStr ""; echo $?
1
Ok, ok, we should prolly note both examples where not optimized against this kind of abuse, and using "openssl rand 100000" instead of perl would be too much fun:
Code:
~/shell/duckie> ./regexp.sh "`perl -e 'print "0" x 100000'`" ; echo $?
0000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000:
(kept goin, CTRL+C after 4m7.550s)
130
Code:
[unsp tmp]$ . f_valStr
[unsp tmp]$ time valStr "`perl -e 'print "0" x 100000'`" ; echo $?
real 0m0.146s
user 0m0.140s
sys 0m0.000s
1
I sincerely hope you don't see this as me slagging off your codes, I just wanted to share that... If you or anyone else got more stuff that might help improve this, BMG!