prevent "^((.*))$" in regex: easier to read, small perf improvement.
This commit is contained in:
@@ -21,7 +21,7 @@ function buildtree {
|
|||||||
local name="var_$prof" # local var name, w/ depth
|
local name="var_$prof" # local var name, w/ depth
|
||||||
eval "local $name" # ... declared here
|
eval "local $name" # ... declared here
|
||||||
shift 2
|
shift 2
|
||||||
local args=$* res="" arg tmp
|
local args=$* res="" arg t
|
||||||
|
|
||||||
for arg in $args; do
|
for arg in $args; do
|
||||||
if [[ -z "${arg/[|ab]}" ]]; then
|
if [[ -z "${arg/[|ab]}" ]]; then
|
||||||
@@ -29,9 +29,12 @@ function buildtree {
|
|||||||
else
|
else
|
||||||
if [[ ! -v MATCH[$arg] ]]; then
|
if [[ ! -v MATCH[$arg] ]]; then
|
||||||
buildtree "$((prof+1))" "$name" "${RULE[$arg]}"
|
buildtree "$((prof+1))" "$name" "${RULE[$arg]}"
|
||||||
tmp="${!name}"
|
t="${!name}"
|
||||||
[[ ! "$tmp" =~ ^.$ ]] && tmp="($tmp)"
|
#[[ ! "$t" =~ ^.$ ]] && t="($t)"
|
||||||
MATCH[$arg]="$tmp"
|
if [[ ! "$t" =~ ^[ab]+$ ]] && [[ "${t:0:1}${t: -1}" != "()" ]]; then
|
||||||
|
t="($t)"
|
||||||
|
fi
|
||||||
|
MATCH[$arg]="$t"
|
||||||
fi
|
fi
|
||||||
res+=${MATCH[$arg]}
|
res+=${MATCH[$arg]}
|
||||||
fi
|
fi
|
||||||
@@ -54,7 +57,7 @@ while read -r line; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
buildtree 1 var_0 0
|
buildtree 1 var_0 0
|
||||||
#printf "RULE ZERO = %s\n" "${MATCH[0]}"
|
printf "RULE ZERO = %s\n" "${MATCH[0]}"
|
||||||
|
|
||||||
for str in "${STRING[@]}"; do
|
for str in "${STRING[@]}"; do
|
||||||
[[ "$str" =~ ^${MATCH[0]}$ ]] && ((res++))
|
[[ "$str" =~ ^${MATCH[0]}$ ]] && ((res++))
|
||||||
|
Reference in New Issue
Block a user