コード例 #1
0
        public JsonIdentityExtent(string json, int start, int length, JsonExtent identityExtent) : base(json, start, length)
        {
            this.identityExtent = identityExtent;

            var colonIndex = this.identityExtent.IndexOf(':');
            var quoteIndex = this.identityExtent.IndexOf('"', colonIndex + 1);

            valueStart  = quoteIndex + 1;
            valueLength = identityExtent.Length - valueStart - 1;
        }
コード例 #2
0
        private void EmitExtent(string json, int startIndex, int endIndex)
        {
            if (identityExtent != null)
            {
                if (canEmitIdentityExtent)
                {
                    matchedExtents.Add(new JsonIdentityExtent(json, startIndex, endIndex - startIndex, identityExtent) as T);
                    identityExtentCount++;
                }

                identityExtent = null;
            }
            else if (canEmitExtent)
            {
                matchedExtents.Add(new JsonExtent(json, startIndex, endIndex - startIndex) as T);
            }
        }
コード例 #3
0
        private int ParseObject(string json, int offset, bool parentPathMatched)
        {
            int i      = offset;
            int length = json.Length;
            int fields = 0;

            if (json[i] != '{')
            {
                throw new JsonParseException("Invalid object");
            }

            for (i++; i < length;)
            {
                if (json[i] == '}')
                {
                    break;
                }
                else if (IsWhiteSpace(json[i]))
                {
                    i++;
                }
                else
                {
                    if (fields > 0)
                    {
                        if (json[i++] != ',')
                        {
                            throw new JsonParseException("Invalid object; missing field delimiter");
                        }

                        if (i == length)
                        {
                            throw new JsonParseException("Invalid object; unexpected end of input");
                        }

                        while (i < length && IsWhiteSpace(json[i]))
                        {
                            i++;
                        }

                        if (i == length)
                        {
                            throw new JsonParseException("Invalid object; unexpected end of input");
                        }

                        if (json[i] == '}')
                        {
                            i++;
                            break;
                        }
                    }

                    var objectStartIndex = i;

                    JsonString name;
                    i = ParseString(json, i, out name);

                    if (i == length)
                    {
                        throw new JsonParseException("Invalid object; missing value");
                    }

                    pathStack.Push(name);

                    bool pathMatched = !parentPathMatched && pathMatch.IsMatch(pathStack.Path);

                    while (i < length && IsWhiteSpace(json[i]))
                    {
                        i++;
                    }

                    if (i == length)
                    {
                        throw new JsonParseException("Invalid object; unexpected end of input");
                    }

                    if (json[i++] != ':')
                    {
                        throw new JsonParseException("Invalid object; expected ':' field delimiter");
                    }

                    if (i == length)
                    {
                        throw new JsonParseException("Invalid object; unexpected end of input");
                    }

                    while (i < length && IsWhiteSpace(json[i]))
                    {
                        i++;
                    }

                    if (i == length)
                    {
                        throw new JsonParseException("Invalid object; unexpected end of input");
                    }

                    i = ParseValue(json, i, parentPathMatched);

                    var objectEndIndex = i;

                    if (pathMatched)
                    {
                        EmitExtent(json, objectStartIndex, objectEndIndex);
                    }
                    else if (parentPathMatched && string.CompareOrdinal(name, extentId) == 0)
                    {
                        identityExtent = new JsonExtent(json, objectStartIndex, objectEndIndex - objectStartIndex);
                    }

                    pathStack.Pop();

                    fields++;
                }
            }

            if (i >= length)
            {
                throw new JsonParseException("Invalid object; unexpected end of input");
            }

            return(i + 1);
        }