Ejemplo n.º 1
0
        public override void PopulateElement(JStream stream)
        {
            if (stream.Char == '"')
            {
                stream.Next();
            }
            else
            {
                throw new Exception(string.Format("String cannot start with '{0}' character", stream.Char));
            }

            var builder = new StringBuilder();

            while (stream.Char != '"')
            {
                if (stream.Char == '\\')
                {
                    builder.Append(stream.Char);
                    stream.Next();
                }

                builder.Append(stream.Char);
                stream.Next();
            }

            value = builder.ToString();
            stream.Next();
        }
Ejemplo n.º 2
0
        public override void PopulateElement(JStream stream)
        {
            var builder = new StringBuilder();

            while (Array.IndexOf(AvailableChars, stream.Char) >= 0)
            {
                builder.Append(stream.Char);
                stream.Next();
            }

            value = double.Parse(builder.ToString(), CultureInfo.InvariantCulture);
        }
Ejemplo n.º 3
0
        public override void PopulateElement(JStream stream)
        {
            if (stream.Char == '[')
            {
                stream.Next();
            }
            else
            {
                throw new Exception(string.Format("Cannot parse Array first character '{0}'", stream.Char));
            }

            value.Clear();

            var first = true;

            stream.SkipSpaces();
            while (stream.Char != ']')
            {
                if (!first)
                {
                    if (stream.Char != ',')
                    {
                        throw new Exception("Cannot parse array, no , (comma) found");
                    }

                    stream.Next();
                    stream.SkipSpaces();
                }

                var element = StringFactory.GetJElementFromJSON(stream);

                value.Add(element);

                stream.SkipSpaces();

                first = false;
            }

            stream.Next();
        }
Ejemplo n.º 4
0
        public override void PopulateElement(JStream stream)
        {
            if (stream.Char == '{')
            {
                stream.Next();
            }
            else
            {
                throw new Exception(string.Format("Cannot parse Object first character '{0}'", stream.Char));
            }

            value.Clear();

            stream.SkipSpaces();
            var first = true;

            while (stream.Char != '}')
            {
                if (!first)
                {
                    if (stream.Char != ',')
                    {
                        throw new Exception("Cannot parse object, no ,(comma) found");
                    }

                    stream.Next();
                    stream.SkipSpaces();
                }

                value.Add(ParseKeyValuePair(stream));

                stream.SkipSpaces();

                first = false;
            }

            stream.Next();
        }
Ejemplo n.º 5
0
        private KeyValuePair <string, Element> ParseKeyValuePair(JStream stream)
        {
            //TODO: just temporary
            var stringKey = new StringElement();

            stringKey.PopulateElement(stream);

            stream.SkipSpaces();

            if (stream.Char != ':')
            {
                throw new Exception("Cannot parse object, not found :");
            }

            stream.Next();

            stream.SkipSpaces();

            var key     = stringKey.Value;
            var element = StringFactory.GetJElementFromJSON(stream);

            return(new KeyValuePair <string, Element>(key, element));
        }