BraceMatch() public static method

public static BraceMatch ( String text, int start ) : int
text String
start int
return int
コード例 #1
0
        public bool parseNext(ref string buffer, out string cmd)
        {
            for (int i = 0; i < buffer.Length; i++)
            {
                string c = buffer.Substring(i, 1);

                if (c == "\"")
                {
                    i = Utils.FindEndOfString(buffer, i + 1);
                }
                else if (c == ".")
                {
                    int pTest;
                    if (i == buffer.Length - 1 || int.TryParse(buffer.Substring(i + 1, 1), out pTest) == false)
                    {
                        cmd    = buffer.Substring(0, i);
                        buffer = buffer.Substring(i + 1).Trim();
                        return(true);
                    }
                }
                else if (c == "{")
                {
                    i = Utils.BraceMatch(buffer, i);

                    if (i == -1)
                    {
                        cmd = "";
                        return(false);
                    }
                }
            }

            cmd = "";
            return(false);
        }
コード例 #2
0
        public bool parseNext(ref string buffer, out string cmd, ref int lineCount, out int lineStart)
        {
            lineStart = -1;

            for (int i = 0; i < buffer.Length; i++)
            {
                string c = buffer.Substring(i, 1);

                if (lineStart < 0 && Regex.Match(c, "\\S").Success)
                {
                    lineStart = lineCount;
                }
                else if (c == "\n")
                {
                    lineCount++;
                }

                if (c == "\"")
                {
                    i = Utils.FindEndOfString(buffer, i + 1);

                    if (i == -1)
                    {
                        cmd = "";
                        return(false);
                    }
                }
                else if (c == ".")
                {
                    int pTest;
                    if (i == buffer.Length - 1 || int.TryParse(buffer.Substring(i + 1, 1), out pTest) == false)
                    {
                        cmd    = buffer.Substring(0, i);
                        buffer = buffer.Substring(i + 1).Trim();

                        return(true);
                    }
                }
                else if (c == "{")
                {
                    i = Utils.BraceMatch(buffer, i);

                    if (i == -1)
                    {
                        cmd = "";
                        return(false);
                    }
                    else
                    {
                        // Do you see a period after this right brace? If not, let's just pretend there is one ok?
                        if (!buffer.Substring(i + 1).StartsWith("."))
                        {
                            cmd    = buffer.Substring(0, i + 1);
                            buffer = buffer.Substring(i + 1).Trim();

                            return(true);
                        }
                    }
                }
            }

            cmd = "";
            return(false);
        }