Esempio n. 1
0
        private static INode ReadNameValue(this Unpacker unpacker)
        {
            string name = unpacker.ReadQuoteString();
            Node   node = new Node();

            node.Name = name;
            unpacker.SkipWhiteSpace();
            if (unpacker.Read() != ':')
            {
                throw new FormatException("invalid json name:value format");
            }
            unpacker.SkipWhiteSpace();
            // json value
            char c = unpacker.Peek();

            if (c == '{')
            {
                node.SubNode = unpacker.ReadObject();
            }
            else if (c == '[')
            {
                node.SubNode = unpacker.ReadArray();
            }
            else
            {
                node.Value = unpacker.ReadWritable(); //fully compartale with json
            }
            return(node);
        }
Esempio n. 2
0
 /// <summary>
 /// Unpack json document.
 /// </summary>
 /// <remarks>
 /// Json support 110% some value not suppport in json format may not generate error and output perfactly
 /// <para> "name" : "value" output as INode with Name value</para>
 /// <para> </para>
 /// </remarks>
 /// <param name="unpacker"></param>
 /// <returns><see cref="Node"/> of json</returns>
 /// <exception cref="FormatException">document invalid format <seealso cref="Unpacker.LineCount"/> to find where error locate</exception>
 public static INode JsonDocument(this Unpacker unpacker)
 {
     if (unpacker.Peek() != '{')
     {
         throw new FormatException("json document must start with '{'");
     }
     else
     {
         INode json = new Node()
         {
             SubNode = unpacker.ReadObject()
         };
         return(json);
     }
 }
Esempio n. 3
0
 public void Read()
 {
     Create();
     Assert.AreEqual(unpacker.Read(), '0');
     Assert.AreEqual(unpacker.Peek(), '1');
     Assert.AreEqual(unpacker.ReadNext(), '2');
     Assert.AreEqual(unpacker.ReadString(), "23456");
     Assert.AreEqual(unpacker.Read(), ' ');
     unpacker.SkipWhiteSpace();
     Assert.AreEqual(unpacker.Read(), 'H');
     Assert.AreEqual(unpacker.ReadString("elo!"), "ello!");
     unpacker.SkipWhiteSpace();
     Assert.AreEqual(unpacker.Read(), 'W');
     Debug.WriteLine($"line :{unpacker.LineCount} col :{unpacker.CollumCount}");
     Assert.AreEqual(unpacker.CollumCount, 3);
     Assert.AreEqual(unpacker.LineCount, 2);
     Assert.AreEqual(unpacker.Indent, 1);
 }