private static string Preprocess(string pattern) {
StringBuilder bufBld = new StringBuilder();
bufBld.Append("^");
char[] source = pattern.ToCharArray();
int length = pattern.Length;
int copyPosition = 0;
for (int position = 0; position < length - 2; position ++) {
if (source[position] == '\\') {
if (source[position + 1] == '\\') {
position ++; // skip it
}
else {
char ch = source[position + 1];
for (int i = 0; i < c_map.Length; i++) {
if (c_map[i].match == ch) {
if (copyPosition < position) {
bufBld.Append(source, copyPosition, position - copyPosition);
}
bufBld.Append(c_map[i].replacement);
position ++;
copyPosition = position + 1;
break;
}
}
}
}
}
if (copyPosition < length) {
bufBld.Append(source, copyPosition, length - copyPosition);
}
bufBld.Append("$");
return bufBld.ToString();
}