public static bool IsCorrect(string s)
{
if (Encoding.UTF8.GetByteCount(s) > MaxLength)
return false;
bool res = true;
// check for unbalanced double brackets
int pos = s.IndexOf("[[");
while (pos >= 0)
{
s = s.Remove(0, pos);
if (res)
{
// if more double brackets opened before current one closed, summary is invalid
if (s.Substring(2, s.IndexOf("]]") >0 ? s.IndexOf("]]") : 0).Contains("[["))
return false;
pos = s.IndexOf("]]");
}
else
pos = s.IndexOf("[[");
res = !res;
}
return res;
}