/// <summary> /// Private constructer for an ABC node. Use <see cref="ParseFile(string)"/> instead. /// </summary> /// <param name="key">This nodes key.</param> /// <param name="parent">The parent of this node.</param> private ABCFormat(string key, ABCFormat parent = null) { m_Key = key; m_Parent = parent; if (parent != null) { parent[key] = this; } }
/// <summary> /// Parses an .abc file. /// </summary> /// <param name="path">path to the .abc-file</param> /// <returns>The root node in the ABC-file format structure</returns> internal static ABCFormat ParseFile(string path) { if (!System.IO.File.Exists(path)) { return(NullNode); } var lines = System.IO.File.ReadAllLines(path); ABCFormat root = new ABCFormat("root"); ABCFormat currentNode = root; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (line.IndexOf('#') != -1) { line = line.Split('#')[0]; } if (line.Trim() == string.Empty) { continue; } if (line[0] != '\t') { currentNode = root; } for (int c = 0; c < line.Length; c++) { if (line[c] == '=') { string key = line.Substring(0, c).Trim(); if (key.Length == 0) { break; } string value = line.Substring(c + 1, line.Length - c - 1).Trim(); currentNode.Set(key, value); break; } else if (line[c] == ':') { string key = line.Substring(0, c).Trim(); if (key.Length == 0) { break; } currentNode = new ABCFormat(key, currentNode); break; } } } return(root); }