\r
internal void Replace(string target, string pattern,bool ci = false)\r
{\r
- TextSearch ts = new TextSearch(target);\r
+ TextSearch ts = new TextSearch(target,ci);\r
int left = 0, right = 0;\r
- while((right = ts.IndexOf(this.buf,left,ci)) != -1)\r
+ while((right = ts.IndexOf(this.buf,left)) != -1)\r
{\r
this.buf.RemoveRange(right, target.Length);\r
this.buf.InsertRange(right, pattern, pattern.Length);\r
\r
internal int IndexOf(string target, int start,bool ci = false)\r
{\r
- TextSearch ts = new TextSearch(target);\r
- return ts.IndexOf(this.buf, start,ci);\r
+ TextSearch ts = new TextSearch(target,ci);\r
+ return ts.IndexOf(this.buf, start);\r
}\r
\r
/// <summary>\r
string pattern;\r
int patternLength;\r
Dictionary<char, int> qsTable = new Dictionary<char, int>();\r
- public TextSearch(string pattern)\r
+ bool caseInsenstive;\r
+ public TextSearch(string pattern,bool ci = false)\r
{\r
this.pattern = pattern;\r
this.patternLength = pattern.Length;\r
- this.CreateQSTable(pattern);\r
+ this.caseInsenstive = ci;\r
+ if (ci)\r
+ {\r
+ this.CreateQSTable(pattern.ToLower());\r
+ this.CreateQSTable(pattern.ToUpper());\r
+ }\r
+ else\r
+ {\r
+ this.CreateQSTable(pattern);\r
+ }\r
}\r
void CreateQSTable(string pattern)\r
{\r
this.qsTable[pattern[i]] = len - i;\r
}\r
}\r
- public int IndexOf(GapBuffer<char> buf, int start, bool ci = false)\r
+ public int IndexOf(GapBuffer<char> buf, int start)\r
{\r
//QuickSearch法\r
int buflen = buf.Count - 1;\r
while (j < plen)\r
{\r
bool unmatch;\r
- if (ci)\r
+ if (this.caseInsenstive)\r
unmatch = Char.ToUpper(buf[i + j]) != Char.ToUpper(this.pattern[j]);\r
else\r
unmatch = buf[i + j] != this.pattern[j];\r
buf.Replace(0, 0, str, str.Length);
index = buf.IndexOf("ABC", 0);
Assert.IsTrue(index == 1);
+
+ index = buf.IndexOf("abc", 0,true);
+ Assert.IsTrue(index == 1);
+
+ index = buf.IndexOf("abc", 0);
+ Assert.IsTrue(index == -1);
}
[TestMethod]