Ejemplo n.º 1
0
 public void Delete(KVNode node)
 {
     node.parent = null;
     if (node.Type == KVNodeType.Parent)
     {
         node.DeleteThis();
     }
 }
Ejemplo n.º 2
0
        public object GetValue(string key = null)
        {
            if (type != KVNodeType.Root && type != KVNodeType.Parent)
            {
                return(value.ToString());
            }
            KVNode bring = FindSingleNode(key, KVNodeType.KeyValue);

            if (bring != null)
            {
                return(bring.GetValue(null));
            }
            return(null);
        }
Ejemplo n.º 3
0
 public void Debug(KVNode start, int depth = 0)
 {
     foreach (KVNode node in start.FindNodes())
     {
         for (int i = 0; i < depth; i++)
         {
             Console.Write("=");
         }
         if (node.Type == KVNode.KVNodeType.Parent)
         {
             Console.WriteLine(node.KeyName);
             Debug(node, depth + 1);
         }
         else
         {
             Console.WriteLine(String.Format("{0} {1}", node.KeyName, node.GetValue()));
         }
     }
 }
Ejemplo n.º 4
0
 private static void NodeToFullFormatString(KVNode node, StringBuilder sb, int depth = 0)
 {
     if (node.Type == KVNode.KVNodeType.Root || node.Type == KVNode.KVNodeType.Parent)
     {
         sb.Append('	', depth);
         sb.AppendFormat("{0}\n", node.KeyName);
         sb.Append(' ', depth);
         sb.Append("{\n");
         foreach (var n in node.FindNodes())
         {
             NodeToFullFormatString(n, sb, depth + 1);
         }
         sb.Append('\n');
         sb.Append(' ', depth);
         sb.Append("}");
     }
     else
     {
         sb.Append(' ', depth);
         sb.AppendFormat("\"{0}\" \"{1}\"", node.KeyName, node.GetValue().ToString());
     }
 }
Ejemplo n.º 5
0
 public void AppendNode(KVNode node)
 {
     if (type != KVNodeType.Root)
     {
         type = KVNodeType.Parent;
     }
     node.SetParent(this);
     this.value = null;
     if (node.Type == KVNodeType.KeyValue)
     {
         if (!Child.Exists(x => x.KeyName.Equals(node.KeyName)))
         {
             Child.Add(node);
         }
         else
         {
             SetValue(node.GetValue(), node.KeyName);
         }
     }
     else
     {
         Child.Add(node);
     }
 }
Ejemplo n.º 6
0
 public void SetParent(KVNode node)
 {
     parent = node;
 }
Ejemplo n.º 7
0
        public static KeyValues ImportKeyValue(string content, bool overrideparentnode)
        {
            var rmvRemark = regKv.Matches(regRemark.Replace(content, ""));

            int       depth   = 0;
            KeyValues kv      = new KeyValues("RootKey");
            KVNode    current = null;

            for (int i = 0; i < rmvRemark.Count; i++)
            {
                string str = regQuote.Replace(rmvRemark[i].Value, "");
                if (str.Equals("}")) //single
                {
                    if (current.Type != KVNode.KVNodeType.Root)
                    {
                        current = current.Parent;
                        depth--;
                    }
                }
                else //two mixed
                {
                    string nxt_str = regQuote.Replace(rmvRemark[i + 1].Value, "");

                    if (str.Equals("#base")) //basefile
                    {
                        kv.AddBaseFile(nxt_str);
                        i++;
                    }
                    else if (nxt_str.Equals("{")) //parent
                    {
                        if (current == null)
                        {
                            kv.Root.KeyName = str;
                            current         = kv.Root;
                        }
                        else
                        {
                            if (overrideparentnode && current.FindSingleNode(str, KVNode.KVNodeType.Parent) != null)
                            {
                                current = current.FindSingleNode(str, KVNode.KVNodeType.Parent);
                            }
                            else
                            {
                                var node = new KVNode(str);
                                current.AppendNode(node);
                                current = node;
                            }
                        }
                        depth++;
                    }
                    else //child
                    {
                        current.SetValue(nxt_str, str, true);
                    }
                    i++;
                }
            }
            if (depth == 0)
            {
                return(kv);
            }
            return(null);
        }
Ejemplo n.º 8
0
 public KeyValues(string root)
 {
     basefile = new List <string>();
     Root     = new KVNode(root);
 }