示例#1
0
        public static VdfNode ParseVdfString(string vdfString)
        {
            vdfString = CleanUpInput(vdfString);

            var  rootNode    = new VdfNode(null, "Root");
            var  currentNode = new VdfNode(rootNode);
            bool readName    = false;
            var  i           = 0;

            while (i < vdfString.Length)
            {
                var c = vdfString[i];
                if (c == '"')
                {
                    var endQuoteIdx = vdfString.IndexOf('"', i + 1);
                    var name        = vdfString.Substring(i + 1, endQuoteIdx - i - 1);
                    if (readName)
                    {
                        currentNode.Value   = name;
                        currentNode.IsValue = true;
                        currentNode         = new VdfNode(currentNode.Parent);
                    }
                    else
                    {
                        currentNode.Name = name;
                        currentNode.Parent.Children.Add(currentNode);
                    }
                    readName = !readName;
                    i        = endQuoteIdx + 1;
                }
                else if (c == '{')
                {
                    currentNode = new VdfNode(currentNode, currentNode.Name);
                    readName    = false;
                    ++i;
                }
                else if (c == '}')
                {
                    if (currentNode.Parent == null)
                    {
                        break;
                    }
                    currentNode = new VdfNode(currentNode.Parent.Parent);
                    readName    = false;
                    ++i;
                }
            }

            return(rootNode);
        }
示例#2
0
 public VdfNode(VdfNode parent, string name)
 {
     Parent = parent;
     Name   = name;
 }
示例#3
0
 public VdfNode(VdfNode parent)
 {
     Parent = parent;
 }