public static FunctionStackInfo Create(string suFileLine) { if (!LineRegex.IsMatch(suFileLine)) { throw new ArgumentException($"Line '{ suFileLine }' does not match SU file line", nameof(suFileLine)); } var matches = LineRegex.Match(suFileLine); var file = matches.Groups[1].Value; var line = uint.Parse(matches.Groups[2].Value); var column = uint.Parse(matches.Groups[3].Value); var name = matches.Groups[4].Value; var bytes = uint.Parse(matches.Groups[5].Value); var qualifier = ParseQualifier(matches.Groups[6].Value.Trim()); return(Create(file, name, line, column, bytes, qualifier)); }
public static FunctionStackInfo Create(LineInstance suFileLine) { if (!LineRegex.IsMatch(suFileLine.Line)) { throw new ArgumentException($"Line '{ suFileLine }' does not match SU file line", nameof(suFileLine)); } var matches = LineRegex.Match(suFileLine.Line); var file = matches.Groups[1].Value; var line = uint.Parse(matches.Groups[2].Value); var column = uint.Parse(matches.Groups[3].Value); var name = matches.Groups[4].Value; var bytes = uint.Parse(matches.Groups[5].Value); var qualifier = ParseQualifier(matches.Groups[6].Value.Trim()); return(Create(Path.Combine(Path.GetDirectoryName(suFileLine.FileName), file).Replace("\\Debug\\", "\\"), name, line, column, bytes, qualifier)); }
// ------ Ini Deserialization ------ /// <summary> /// Load the values in an Ini file into this value store instance, /// replacing the value store's contents. /// </summary> public static void Load(ValueStore store, string content) { // TODO: More input validation var lines = content.Split('\n'); foreach (var line in lines) { if (commentedLineRegex.IsMatch(line) || line.Trim().Length == 0) { continue; } var match = LineRegex.Match(line); if (!match.Success) { Debug.LogWarning("Failed to read line in Ini file: " + line); continue; } // Groups: // 1 = Regular Name // 2 = Child name // 3 = Quoted Parameter // 4 = Unquoted Parameter // 5 = Quoted Value // 6 = Unquoted Value var rootCapture = match.Groups[1]; var rootNode = store.GetOrCreateRoot(rootCapture.Value); var node = GetNodeRecursive(rootNode, match, rootCapture.Index + rootCapture.Length - 1); var isQuoted = true; var valueCapture = match.Groups[5]; if (!valueCapture.Success) { isQuoted = false; valueCapture = match.Groups[6]; } node.value = ProcessQuotedString(valueCapture.Value, isQuoted); } }
public void Parse() { if (Lines.Count > 0) { // First line var matchFirstLine = LineRegex.Match(Lines.First()); if (matchFirstLine.Success) { var date = matchFirstLine.Groups["date"].ToString(); var time = matchFirstLine.Groups["time"].ToString(); TimeStamp = CreateTimeStamp(date: date, time: time); Level = matchFirstLine.Groups["level"].ToString(); var data = matchFirstLine.Groups["data"].ToString(); var matchTypeAndData = TypeRegex.Match(data); if (matchTypeAndData.Success) { Type = matchTypeAndData.Groups["type"].ToString(); Data = matchTypeAndData.Groups["data"].ToString(); } else { Type = "undefined"; Data = data; } } foreach (var line in Lines.Skip(1)) { var matchLine = LineRegex.Match(line); if (matchLine.Success) { var data = matchLine.Groups["data"].ToString(); Data += data; } } } Parsed = true; }
protected override IList <string> SplitToLines(string serialized) { _sideboardIndicator = getSideboardIndicator(serialized); var lines = serialized.Trim().Split(Array.From("\r\n", "\r", "\n"), StringSplitOptions.None); var result = new List <string>(); foreach (string line in lines) { var match = LineRegex.Match(line); if (line == string.Empty) { if (result.Count > 0 && result[result.Count - 1] != string.Empty) { result.Add(line); } } else if (isSideboardIndicator(line)) { result.Add(line); } else if (match.Success) { result.Add(line); } else if (isKnownMtgoName(line.Trim())) { result.Add("1 " + line.Trim()); } else if (line.IndexOf("\t", Str.Comparison) >= 0) { var parts = line.Split(Array.From('\t'), StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < parts.Length; i++) { if (isKnownMtgoName(parts[i])) { if (i > 0 && parts[i - 1].All(char.IsDigit)) { result.Add(parts[i - 1] + ' ' + parts[i]); } else if (i < parts.Length - 1 && parts[i + 1].All(char.IsDigit)) { result.Add(parts[i + 1] + ' ' + parts[i]); } break; } } } else { var splits = _splitterRegex.Matches(line) .OfType <Match>() .Select(m => m.Index) .ToList(); if (splits.Count > 0) { splits.Add(line.Length); } for (int i = 0; i < splits.Count - 1; i++) { string substring = line.Substring(splits[i], splits[i + 1] - splits[i]).TrimEnd(); var substringMatch = LineRegex.Match(substring); if (substringMatch.Success) { result.Add(substring); } } } } return(result); }