示例#1
0
文件: JPath.cs 项目: cs130-w21/13
        private bool ParsePath(List <PathFilter> filters, int currentPartStartIndex, bool query)
        {
            bool scan  = false;
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;

            while (this._currentIndex < this._expression.Length && !flag3)
            {
                char indexerOpenChar = this._expression[this._currentIndex];
                switch (indexerOpenChar)
                {
                case ' ':
                    if (this._currentIndex < this._expression.Length)
                    {
                        flag3 = true;
                        continue;
                    }

                    continue;

                case '(':
                case '[':
                    if (this._currentIndex > currentPartStartIndex)
                    {
                        string member =
                            this._expression.Substring(currentPartStartIndex, this._currentIndex - currentPartStartIndex);
                        if (member == "*")
                        {
                            member = (string)null;
                        }
                        filters.Add(JPath.CreatePathFilter(member, scan));
                        scan = false;
                    }

                    filters.Add(this.ParseIndexer(indexerOpenChar, scan));
                    ++this._currentIndex;
                    currentPartStartIndex = this._currentIndex;
                    flag1 = true;
                    flag2 = false;
                    continue;

                case ')':
                case ']':
                    flag3 = true;
                    continue;

                case '.':
                    if (this._currentIndex > currentPartStartIndex)
                    {
                        string member =
                            this._expression.Substring(currentPartStartIndex, this._currentIndex - currentPartStartIndex);
                        if (member == "*")
                        {
                            member = (string)null;
                        }
                        filters.Add(JPath.CreatePathFilter(member, scan));
                        scan = false;
                    }

                    if (this._currentIndex + 1 < this._expression.Length && this._expression[this._currentIndex + 1] == '.')
                    {
                        scan = true;
                        ++this._currentIndex;
                    }

                    ++this._currentIndex;
                    currentPartStartIndex = this._currentIndex;
                    flag1 = false;
                    flag2 = true;
                    continue;

                default:
                    if (query && (indexerOpenChar == '=' || indexerOpenChar == '<' ||
                                  (indexerOpenChar == '!' || indexerOpenChar == '>') ||
                                  (indexerOpenChar == '|' || indexerOpenChar == '&')))
                    {
                        flag3 = true;
                        continue;
                    }

                    if (flag1)
                    {
                        throw new JsonException("Unexpected character following indexer: " + indexerOpenChar.ToString());
                    }
                    ++this._currentIndex;
                    continue;
                }
            }

            bool flag4 = this._currentIndex == this._expression.Length;

            if (this._currentIndex > currentPartStartIndex)
            {
                string member = this._expression.Substring(currentPartStartIndex, this._currentIndex - currentPartStartIndex)
                                .TrimEnd();
                if (member == "*")
                {
                    member = (string)null;
                }
                filters.Add(JPath.CreatePathFilter(member, scan));
            }
            else if (flag2 && flag4 | query)
            {
                throw new JsonException("Unexpected end while parsing path.");
            }

            return(flag4);
        }