public void AddChild(string query, string value) { var pos = query.IndexOf(".", StringComparison.Ordinal); if (pos == -1) { ValTree yy = new ValTree(query, value); AddChild(yy); return; } string k = query.Substring(0, pos); string v = query.Substring(pos + 1); if (k.Length <= 0) return; ValTree child = GetChild(k); if (child == null) { ValTree xx = new ValTree(k, string.Empty); xx.AddChild(v, value); AddChild(xx); } else { child.AddChild(v, value); } }
public void TestGetValidViaQueryChild() { var v = new ValTree(); string path = Directory.GetCurrentDirectory(); var worked = v.Parse(path + "/TestData.txt"); Assert.IsTrue(worked, "ValTree failed to parse script"); var h = v.Query("key1.key2.key3"); Assert.IsNotNull(h, "Failed to get child"); }
public void TestGetInValidChild() { var v = new ValTree(); string path = Directory.GetCurrentDirectory(); var worked = v.Parse(path + "/TestData.txt"); Assert.IsTrue(worked, "ValTree failed to parse script"); var h = v.GetChild("asfdasdasd"); Assert.IsNull(h, "Got valid child when should not have"); }
public void TestAddViaValTreeChild() { var v = new ValTree(); string path = Directory.GetCurrentDirectory(); var worked = v.Parse(path + "/TestData.txt"); Assert.IsTrue(worked, "ValTree failed to parse script"); v.AddChild(new ValTree("l", "90,90")); var h = v.GetChild("l"); Assert.IsNotNull(h, "Failed to add child"); }
public void TestGetValueFloat() { var v = new ValTree(); string path = Directory.GetCurrentDirectory(); var worked = v.Parse(path + "/TestData.txt"); Assert.IsTrue(worked, "ValTree failed to parse script"); var h = v.Query("key1.key2.key3.key4"); Assert.IsNotNull(h, "Failed to add child"); Assert.AreEqual(h.GetFloat(), 17.8); }
static void Main(string[] args) { var v = new ValTree(); string path = Directory.GetCurrentDirectory(); var worked = v.Parse(path + "/TestData.txt"); var h = v.GetChild("g-is-long").GetChild("h"); Console.WriteLine("The value of 'g-is-long.h' is '" + h.GetValue() + "'"); var key41 = v.Query("key1.key2.key3.key4-1"); Console.WriteLine("The value of 'key1.key2.key3.key4-1' is '" + key41.GetValue() + "'"); v.AddChild(new ValTree("l", "90,90")); Console.WriteLine("After adding child 'l', new ValTree looks like this:"); v.Log(); v.AddChild("l.m.n.o.p", "q"); Console.WriteLine("After adding tree 'l.m.n.o.p', new ValTree looks like this:"); v.Log(); v.Save(path + "/TestData-modified.txt"); }
public void AddChild(ValTree v) { _children.Add(v); }
static void InternalLog(ref StringBuilder sb, ValTree inValue, int depth) { if (inValue.GetKey().Length > 0 || inValue.GetValue().Length > 0) { for (int i = 0; i < depth; i++) { sb.Append("\t"); } sb.AppendLine(inValue.GetKey() + " " + inValue.GetValue()); } for (int i = 0; i < inValue.Size(); i++) { var child = inValue.GetIndex(i); InternalLog(ref sb, child, depth + 1); } }
public void TestParse() { var v = new ValTree(); string path = Directory.GetCurrentDirectory(); var worked = v.Parse(path + "/TestData.txt"); Assert.IsTrue(worked, "ValTree failed to parse script"); }
public void TestGetValueString() { var v = new ValTree(); string path = Directory.GetCurrentDirectory(); var worked = v.Parse(path + "/TestData.txt"); Assert.IsTrue(worked, "ValTree failed to parse script"); var h = v.GetChild("key1"); Assert.IsNotNull(h, "Failed to add child"); Assert.AreEqual(h.GetValue(), "val1 "); }