WikiFunctions.Summary.IsCorrect C# (CSharp) Method

IsCorrect() public static method

returns true if given string has matching double square brackets and is within the maximum permitted length
public static IsCorrect ( string s ) : bool
s string
return bool
        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;
        }