public TextSearch(string pattern, bool ci = false)
 {
     this.patternLength  = pattern.Length;
     this.caseInsenstive = ci;
     if (ci)
     {
         this.CreateQSTable(pattern.ToLower());
         this.CreateQSTable(pattern.ToUpper());
         this.pattern = new char[pattern.Length];
         for (int i = 0; i < pattern.Length; i++)
         {
             this.pattern[i] = CharTool.ToUpperFastIf(pattern[i]);
         }
     }
     else
     {
         this.CreateQSTable(pattern);
         this.pattern = pattern.ToCharArray();
     }
 }
        public int IndexOf(GapBuffer <char> buf, int start, int end)
        {
            //QuickSearch法
            int buflen     = buf.Count - 1;
            int plen       = this.patternLength;
            int i          = start;
            int search_end = end - plen;

            //最適化のためわざとコピペした
            if (this.caseInsenstive)
            {
                while (i <= search_end)
                {
                    int j = 0;
                    while (j < plen)
                    {
                        if (CharTool.ToUpperFastIf(buf[i + j]) != this.pattern[j])
                        {
                            break;
                        }
                        j++;
                    }
                    if (j == plen)
                    {
                        return(i);
                    }
                    else
                    {
                        int k = i + plen;
                        if (k <= buflen)        //buffer以降にアクセスする可能性がある
                        {
                            int moveDelta;
                            if (this.qsTable.TryGetValue(buf[k], out moveDelta))
                            {
                                i += moveDelta;
                            }
                            else
                            {
                                i += plen;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                while (i <= search_end)
                {
                    int j = 0;
                    while (j < plen)
                    {
                        if (buf[i + j] != this.pattern[j])
                        {
                            break;
                        }
                        j++;
                    }
                    if (j == plen)
                    {
                        return(i);
                    }
                    else
                    {
                        int k = i + plen;
                        if (k <= buflen)        //buffer以降にアクセスする可能性がある
                        {
                            int moveDelta;
                            if (this.qsTable.TryGetValue(buf[k], out moveDelta))
                            {
                                i += moveDelta;
                            }
                            else
                            {
                                i += plen;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            return(-1);
        }