private static string FixFilterQuotes(string filter)
{
StringBuilder newFilter = new StringBuilder(filter);
for (int i = 0; i < filter.Length; i++)
{
int length = 0;
bool isOperator = IsOperator(filter, i, out length);
if (isOperator)
{
i += length;
bool isInsideString = false;
for (; i < filter.Length; i++)
{
if (filter[i] == '\'' || filter[i] == '"')
{
if (isInsideString)
{
// check what's after the quote to see if we terminate the string
if (i >= filter.Length - 1)
{
// end of string
isInsideString = false;
break;
}
for (int j = i + 1; j < filter.Length; j++)
{
// continue along whitespace
if (filter[j] == ' ')
{
continue;
}
else
{
// if it's a logical operator, then we terminate
bool op = IsLogical(filter, j, out length);
if (op)
{
isInsideString = false;
j += length;
i = j;
}
break;
}
}
if (isInsideString)
{
// and if we're still inside the string, replace the quote with a wildcard character
newFilter[i] = '_';
}
continue;
}
else
{
isInsideString = true;
}
}
}
}
}
return newFilter.ToString();
}