From 39bb7e32b46c09f98918f51f37a0f9d4d94b3b5f Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 29 Apr 2023 12:33:34 +0900 Subject: [PATCH] pass same file line --- tools/ConvertVector/Program.cs | 114 ++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/tools/ConvertVector/Program.cs b/tools/ConvertVector/Program.cs index f0a46c8..35dc635 100644 --- a/tools/ConvertVector/Program.cs +++ b/tools/ConvertVector/Program.cs @@ -4,62 +4,72 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; +public class FileLocation +{ + public required string Path { get; init; } + public required int Line { get; init; } + public required int Column { get; init; } + public required string Letter { get; init; } +}; + + public static class Program { - private static List CreateLocations(string path) - { - List list = ((IEnumerable) File.ReadAllLines(path)).Where((Func) (line => line.Contains("error CS1061: "))).ToList(); - List locations = new List(); - foreach (string input in list) + private static List CreateLocations(string path) { - string pattern = "([A-Za-z]:\\\\[^\\\\]+\\\\[^\\\\]+(?:\\\\[^\\\\]+)*\\\\[^\\\\]+\\.cs)\\((\\d+),(\\d+)\\)"; - Match match = Regex.Match(input, pattern); - if (match.Success) - { - string str1 = match.Groups[1].Value; - string s1 = match.Groups[2].Value; - string s2 = match.Groups[3].Value; - string str2 = ""; - if (input.Contains("'x'에 대한")) - str2 = "x"; - if (input.Contains("'y'에 대한")) - str2 = "y"; - if (input.Contains("'z'에 대한")) - str2 = "z"; - FileLocation fileLocation = new FileLocation() + List list = ((IEnumerable)File.ReadAllLines(path)).Where((Func)(line => line.Contains("error CS1061: "))).ToList(); + List locations = new List(); + foreach (string input in list) { - Path = str1, - Line = int.Parse(s1), - Column = int.Parse(s2), - Letter = str2 - }; - locations.Add(fileLocation); - } + string pattern = "([A-Za-z]:\\\\[^\\\\]+\\\\[^\\\\]+(?:\\\\[^\\\\]+)*\\\\[^\\\\]+\\.cs)\\((\\d+),(\\d+)\\)"; + Match match = Regex.Match(input, pattern); + if (match.Success) + { + string str1 = match.Groups[1].Value; + string s1 = match.Groups[2].Value; + string s2 = match.Groups[3].Value; + string str2 = ""; + if (input.Contains("'x'에 대한")) + str2 = "x"; + if (input.Contains("'y'에 대한")) + str2 = "y"; + if (input.Contains("'z'에 대한")) + str2 = "z"; + FileLocation fileLocation = new FileLocation() + { + Path = str1, + Line = int.Parse(s1), + Column = int.Parse(s2), + Letter = str2 + }; + locations.Add(fileLocation); + } + } + + return locations; } - return locations; - } - private static void Change(FileLocation location) - { - string[] contents = File.ReadAllLines(location.Path); - List list = ((IEnumerable) contents[location.Line - 1].ToCharArray()).Select((Func) (x => x.ToString() ?? "")).ToList(); - list[location.Column - 2] = "["; - if (location.Letter == "x") - list[location.Column - 1] = "0]"; - else if (location.Letter == "y") - list[location.Column - 1] = "1]"; - else if (location.Letter == "z") - list[location.Column - 1] = "2]"; - string str = string.Join("", (IEnumerable) list); - contents[location.Line - 1] = str; - //File.WriteAllLines(location.Path, contents); - } + private static void Change(FileLocation location) + { + string[] contents = File.ReadAllLines(location.Path); + List list = ((IEnumerable)contents[location.Line - 1].ToCharArray()).Select((Func)(x => x.ToString() ?? "")).ToList(); + list[location.Column - 2] = "["; + if (location.Letter == "x") + list[location.Column - 1] = "0]"; + else if (location.Letter == "y") + list[location.Column - 1] = "1]"; + else if (location.Letter == "z") + list[location.Column - 1] = "2]"; + string str = string.Join("", (IEnumerable)list); + contents[location.Line - 1] = str; + + File.WriteAllLines(location.Path, contents); + } - public static void Main(string[] args) - { - var locations = Program.CreateLocations("../../../../../error.log"); - foreach (FileLocation location in locations) - Program.Change(location); - } -} - \ No newline at end of file + public static void Main(string[] args) + { + var locations = Program.CreateLocations("../../../../../error.log"); + foreach (FileLocation location in locations.DistinctBy(x => x.Path + x.Line)) + Change(location); + } +} \ No newline at end of file