3 // namespace: System.Text.RegularExpressions
\r
4 // file: quicksearch.cs
\r
6 // author: Dan Lewis (dlewis@gmx.co.uk)
\r
10 using System.Collections;
\r
12 namespace System.Text.RegularExpressions {
\r
14 // TODO use simple test for single character strings
\r
17 // simplified boyer-moore for fast substring matching
\r
19 public QuickSearch (string str, bool ignore) {
\r
21 this.len = str.Length;
\r
22 this.ignore = ignore;
\r
27 public string String {
\r
35 public bool IgnoreCase {
\r
36 get { return ignore; }
\r
39 public int Search (string text, int start, int end) {
\r
40 if (end > text.Length - len)
\r
41 end = text.Length - len;
\r
45 while (ptr <= end) {
\r
47 while (str[i] == text[ptr + i]) {
\r
53 ptr += GetShiftDistance (text[ptr + len]);
\r
59 // ignore case: same as above, but we convert text
\r
60 // to lower case before doing the string compare
\r
62 while (ptr <= end) {
\r
64 while (str[i] == Char.ToLower (text[ptr + i])) {
\r
70 ptr += GetShiftDistance (text[ptr + len]);
\r
81 private void Setup () {
\r
83 str = str.ToLower ();
\r
85 shift = new Hashtable ();
\r
86 for (int i = 0; i < len; ++ i) {
\r
91 shift[Char.ToUpper (c)] = len - i;
\r
95 int GetShiftDistance (char c){
\r
96 object s = shift[c];
\r
97 return (s != null ? (int)s : len + 1);
\r
100 private string str;
\r
102 private bool ignore;
\r