private MiniYamlNode getParentNode(MiniYamlNode currentNode, int upTimes) { return(getSubParentNode(currentNode, upTimes)); }
public void Parse() { MiniYamlNode currentNode = null; using (StreamReader reader = new StreamReader(miniYamlFilePath)) { int lastCount = -1; while (reader.Peek() > -1) { string line = reader.ReadLine(); if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#")) { continue; } int count = line.StartsWithCharCount('\t'); if (count == 0) { currentNode = new MiniYamlNode(); var tokens = line.Split(':'); currentNode.Name = tokens[0].Replace("\t", null); if (tokens.Length > 1) { currentNode.Value = tokens[1].Trim(); } Nodes.Add(currentNode); } else { int c**t = line.StartsWithCharCount('\t'); MiniYamlNode yamlNode = new MiniYamlNode(); var tokens = line.Split(':'); yamlNode.Name = tokens[0].Replace("\t", null); if (tokens.Length > 1) { yamlNode.Value = tokens[1].Trim(); } if (c**t == lastCount) { yamlNode.ParentNode = currentNode.ParentNode; currentNode.ParentNode.ChildNodes.Add(yamlNode); } else if (c**t == lastCount + 1) { yamlNode.ParentNode = currentNode; currentNode.ChildNodes.Add(yamlNode); } else if (c**t == lastCount - 1) { yamlNode.ParentNode = currentNode.ParentNode.ParentNode; currentNode.ParentNode.ParentNode.ChildNodes.Add(yamlNode); } else if (c**t < lastCount) { if (c**t - 1 == 0) { var lastRootNode = Nodes.Last(); yamlNode.ParentNode = lastRootNode; lastRootNode.ChildNodes.Add(yamlNode); } else { var parentNode = getParentNode(currentNode, lastCount - 1); yamlNode.ParentNode = parentNode; parentNode.ChildNodes.Add(yamlNode); } } currentNode = yamlNode; } lastCount = count; } } }