From 4116afb86db767cf416e25cd42721b7f952c8fe7 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 29 Dec 2014 23:24:54 -0800 Subject: [PATCH] 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. --- modules/c11std.pl | 6 ++++-- modules/c99std.pl | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/c11std.pl b/modules/c11std.pl index b8d1d67e..f243f37d 100755 --- a/modules/c11std.pl +++ b/modules/c11std.pl @@ -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) { diff --git a/modules/c99std.pl b/modules/c99std.pl index 65c86b25..95f2103b 100755 --- a/modules/c99std.pl +++ b/modules/c99std.pl @@ -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) {