sub bool_to_regexp { local($query) = @_; # Sanity check: query must not contain unescaped "/"! $query =~ s|^/|\\/|; $query =~ s|([^\\])/|\\/|g; # boolean expression (or single word) local($not, $join); #local($qrycmd) = "next unless ("; local($qrycmd) = ""; # $query =~ tr/A-Z/a-z/; $query =~ s/\(/ ( /g; # make sure brackets are separate "words" $query =~ s/\)/ ) /g; $query =~ s/["'`]//g; # quotes don't work (yet?) # for (split(/[+ \t]+/, $query)) { # Splitting on "+" is bad for queries like "C++"! $query =~ s/\+/\\+/g; for (split(/[ \t]+/, $query)) { # for each "word", do ... next if /^$/; if ($_ eq ")") { $qrycmd .= $_; next; } if ($_ eq "(") { $qrycmd .= "$join$_"; $join = ""; next; } if ($_ eq "NOT") { $not = "!"; next; } if ($_ eq "OR") { $join = " || "; next; } if ($_ eq "AND") { $join = " && "; next; } if (/\*/) { s/\*/\\w*/g; } # match word boundaries only if fully alphanumeric # (for queries like "C++") elsif (/^\w+$/) { s/(.*)/\\b\1\\b/; } $qrycmd .= "$join $not/$_/$caseSensitivity"; $join = " && "; # default to AND joins $not = ""; } $qrycmd .= ""; }