string ValidateInput(string source)
{
if (_restrict != null)
{
StringBuilder sb = new StringBuilder();
Match mc = _restrictPattern.Match(source);
int lastPos = 0;
string s;
while (mc != Match.Empty)
{
if (mc.Index != lastPos)
{
//保留tab和回车
for (int i = lastPos; i < mc.Index; i++)
{
if (source[i] == '\n' || source[i] == '\t')
sb.Append(source[i]);
}
}
s = mc.ToString();
lastPos = mc.Index + s.Length;
sb.Append(s);
mc = mc.NextMatch();
}
for (int i = lastPos; i < source.Length; i++)
{
if (source[i] == '\n' || source[i] == '\t')
sb.Append(source[i]);
}
return sb.ToString();
}
else
return source;
}