pass same file line

This commit is contained in:
ikpil 2023-04-29 12:33:34 +09:00
parent b30f3c7666
commit 39bb7e32b4
1 changed files with 62 additions and 52 deletions

View File

@ -4,62 +4,72 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; 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 public static class Program
{ {
private static List<FileLocation> CreateLocations(string path) private static List<FileLocation> CreateLocations(string path)
{
List<string> list = ((IEnumerable<string>) File.ReadAllLines(path)).Where<string>((Func<string, bool>) (line => line.Contains("error CS1061: "))).ToList<string>();
List<FileLocation> locations = new List<FileLocation>();
foreach (string input in list)
{ {
string pattern = "([A-Za-z]:\\\\[^\\\\]+\\\\[^\\\\]+(?:\\\\[^\\\\]+)*\\\\[^\\\\]+\\.cs)\\((\\d+),(\\d+)\\)"; List<string> list = ((IEnumerable<string>)File.ReadAllLines(path)).Where<string>((Func<string, bool>)(line => line.Contains("error CS1061: "))).ToList<string>();
Match match = Regex.Match(input, pattern); List<FileLocation> locations = new List<FileLocation>();
if (match.Success) foreach (string input in list)
{
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, string pattern = "([A-Za-z]:\\\\[^\\\\]+\\\\[^\\\\]+(?:\\\\[^\\\\]+)*\\\\[^\\\\]+\\.cs)\\((\\d+),(\\d+)\\)";
Line = int.Parse(s1), Match match = Regex.Match(input, pattern);
Column = int.Parse(s2), if (match.Success)
Letter = str2 {
}; string str1 = match.Groups[1].Value;
locations.Add(fileLocation); 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) private static void Change(FileLocation location)
{ {
string[] contents = File.ReadAllLines(location.Path); string[] contents = File.ReadAllLines(location.Path);
List<string> list = ((IEnumerable<char>) contents[location.Line - 1].ToCharArray()).Select<char, string>((Func<char, string>) (x => x.ToString() ?? "")).ToList<string>(); List<string> list = ((IEnumerable<char>)contents[location.Line - 1].ToCharArray()).Select<char, string>((Func<char, string>)(x => x.ToString() ?? "")).ToList<string>();
list[location.Column - 2] = "["; list[location.Column - 2] = "[";
if (location.Letter == "x") if (location.Letter == "x")
list[location.Column - 1] = "0]"; list[location.Column - 1] = "0]";
else if (location.Letter == "y") else if (location.Letter == "y")
list[location.Column - 1] = "1]"; list[location.Column - 1] = "1]";
else if (location.Letter == "z") else if (location.Letter == "z")
list[location.Column - 1] = "2]"; list[location.Column - 1] = "2]";
string str = string.Join("", (IEnumerable<string>) list); string str = string.Join("", (IEnumerable<string>)list);
contents[location.Line - 1] = str; contents[location.Line - 1] = str;
//File.WriteAllLines(location.Path, contents);
}
public static void Main(string[] args) File.WriteAllLines(location.Path, contents);
{ }
var locations = Program.CreateLocations("../../../../../error.log");
foreach (FileLocation location in locations) public static void Main(string[] args)
Program.Change(location); {
} var locations = Program.CreateLocations("../../../../../error.log");
foreach (FileLocation location in locations.DistinctBy(x => x.Path + x.Line))
Change(location);
}
} }