using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace TheSlimesJourney { public static class Utils { //Removes leading and trailing spaces and tabs public static string Filter(string inputline) { bool startDone = false; while (!startDone) { startDone = true; if (inputline.StartsWith(" ")) startDone = false; if (inputline.StartsWith("\t")) startDone = false; if (!startDone) inputline = inputline.Substring(1); } bool endDone = false; while (!endDone) { endDone = true; if (inputline.EndsWith(" ")) endDone = false; if (inputline.EndsWith("\t")) endDone = false; if (!endDone) inputline = inputline.Substring(0, inputline.Length - 1); } return inputline; } //Read between quotes public static string RBQ(string inputline) { if (inputline.Contains("\"")) { int firstIndex = inputline.IndexOf("\""); int lastIndex = inputline.LastIndexOf("\""); if (firstIndex != lastIndex) { return inputline.Substring(firstIndex + 1, lastIndex - firstIndex - 1); } } return ""; } //Reads until fitting } public static string[] ReadScope(StreamReader sr) { int innerScopes = 0; List scriptLines = new List(); string currentLine = sr.ReadLine(); //Skip the { while (currentLine != "}") { currentLine = Utils.Filter(sr.ReadLine()); if (currentLine == "{") innerScopes++; if (currentLine != "}") scriptLines.Add(currentLine); else { //If it's a closing bracket of an in-script scope, add it anyways if (innerScopes > 0) { innerScopes--; scriptLines.Add(currentLine); currentLine = ""; //And don't trigger end of scope for script definition } } } return scriptLines.ToArray(); } } }