3 // namespace: System.Text.RegularExpressions
4 // file: quicksearch.cs
6 // Authors: Dan Lewis (dlewis@gmx.co.uk)
7 // Juraj Skripsky (juraj@hotfeet.ch)
10 // (c) 2003 Juraj Skripsky
14 using System.Collections;
16 namespace System.Text.RegularExpressions {
18 // simplified boyer-moore for fast substring matching
19 // (for short strings, we use simple scans)
21 public QuickSearch (string str, bool ignore) {
23 this.len = str.Length;
29 // create the shift table only for "long" search strings
34 public string String {
42 public bool IgnoreCase {
43 get { return ignore; }
46 public int Search (string text, int start, int end) {
49 // use simple scan for a single-character search string
52 if(str[0] == GetChar(text[ptr]))
60 if (end > text.Length - len)
61 end = text.Length - len;
65 while (str[i] == GetChar(text[ptr + i])) {
71 ptr += GetShiftDistance (text[ptr + len]);
81 private void SetupShiftTable () {
82 shift = new Hashtable ();
83 for (int i = 0; i < len; ++ i) {
85 shift[GetChar(c)] = len - i;
89 private int GetShiftDistance (char c) {
94 return (s != null ? (int)s : len + 1);
97 private char GetChar(char c) {
98 return (!ignore ? c : Char.ToLower(c));
105 private Hashtable shift;
106 private readonly static int THRESHOLD = 5;