예제 #1
0
        internal void RecursiveLoadFromBuffer(KeyValueReader kvr)
        {
            while (true)
            {
                // bool bAccepted = true;

                // get the key name
                var name = kvr.ReadToken(out var wasQuoted, out _);

                if (string.IsNullOrEmpty(name))
                {
                    throw new Exception("RecursiveLoadFromBuffer: got EOF or empty keyname");
                }

                if (name.StartsWith("}") && !wasQuoted)
                {
                    break;
                }
                var dat = new KeyValue(name)
                {
                    Children = new List <KeyValue>()
                };
                this.Children.Add(dat);
                // get the value
                var value = kvr.ReadToken(out wasQuoted, out var wasConditional);

                if (wasConditional && value != null)
                {
                    // bAccepted = ( value == "[$WIN32]" );
                    value = kvr.ReadToken(out wasQuoted, out wasConditional);
                }

                if (value == null)
                {
                    throw new Exception("RecursiveLoadFromBuffer:  got NULL key");
                }
                if (value.StartsWith("}") && !wasQuoted)
                {
                    throw new Exception("RecursiveLoadFromBuffer:  got } in key");
                }

                if (value.StartsWith("{") && !wasQuoted)
                {
                    dat.RecursiveLoadFromBuffer(kvr);
                }
                else
                {
                    if (wasConditional)
                    {
                        throw new Exception("RecursiveLoadFromBuffer:  got conditional between key and value");
                    }
                    dat.Value = value;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Populate this instance from the given <see cref="Stream"/> as a text <see cref="KeyValue"/>.
 /// </summary>
 /// <param name="input">The input <see cref="Stream"/> to read from.</param>
 /// <returns><c>true</c> if the read was successful; otherwise, <c>false</c>.</returns>
 public bool ReadAsText(Stream input)
 {
     this.Children = new List <KeyValue>();
     _             = new KeyValueReader(this, input);
     return(true);
 }