Improve text search in c99std/c11std modules

Regular expression special characters are now escaped.
A trailing word-boundary is added to limit results to exact matches.
This commit is contained in:
Pragmatic Software 2014-12-29 23:24:54 -08:00
parent f9e2c3fb49
commit 4116afb86d
2 changed files with 8 additions and 4 deletions

View File

@ -86,7 +86,9 @@ if($list_only) {
$result = "Sections containing '$search':\n ";
}
$search =~ s/\s/\\s+/g;
my $qsearch = quotemeta $search;
$qsearch =~ s/\\ / /g;
$qsearch =~ s/\s+/\\s+/g;
while($text =~ m/^\s{0,4}([0-9A-Z]+\.[0-9\.]*)/msg) {
$this_section = $1;
@ -138,7 +140,7 @@ while($text =~ m/^\s{0,4}([0-9A-Z]+\.[0-9\.]*)/msg) {
if(length $search) {
eval {
if($t =~ m/\b$search/mis or $section_title =~ m/\b$search/mis) {
if($t =~ m/\b$qsearch\b/mis or $section_title =~ m/\b$qsearch\b/mis) {
$matches++;
if($matches >= $match) {
if($list_only) {

View File

@ -86,7 +86,9 @@ if($list_only) {
$result = "Sections containing '$search':\n ";
}
$search =~ s/\s/\\s+/g;
my $qsearch = quotemeta $search;
$qsearch =~ s/\\ / /g;
$qsearch =~ s/\s+/\\s+/g;
while($text =~ m/^\s{0,4}([0-9A-Z]+\.[0-9\.]*)/msg) {
$this_section = $1;
@ -137,7 +139,7 @@ while($text =~ m/^\s{0,4}([0-9A-Z]+\.[0-9\.]*)/msg) {
if(length $search) {
eval {
if($t =~ m/\b$search/mis or $section_title =~ m/\b$search/mis) {
if($t =~ m/\b$qsearch\b/mis or $section_title =~ m/\b$qsearch\b/mis) {
$matches++;
if($matches >= $match) {
if($list_only) {