From 938e91e5e621e13add4379ebb448016dc7c535a8 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Wed, 8 Dec 2021 21:47:22 +0200 Subject: [PATCH] feat: normalize line endings --- .gitattributes | 8 ++ Lab4/Lab4.RemoveLines/InOut.cs | 190 ++++++++++++++++----------------- 2 files changed, 103 insertions(+), 95 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..193b226 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# We'll let Git's auto-detection algorithm infer if a file is text. If it is, +# enforce LF line endings regardless of OS or git configurations. +* text=auto eol=lf + +# Isolate binary files in case the auto-detection algorithm fails and +# marks them as text files (which could brick them). +*.{png,jpg,jpeg,gif,webp,woff,woff2} binary + diff --git a/Lab4/Lab4.RemoveLines/InOut.cs b/Lab4/Lab4.RemoveLines/InOut.cs index 094d744..79bf145 100644 --- a/Lab4/Lab4.RemoveLines/InOut.cs +++ b/Lab4/Lab4.RemoveLines/InOut.cs @@ -1,95 +1,95 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - -namespace Lab4.RemoveLines -{ - class InOut - { - public static int LongestLine(string fin) - { - int No = -1; - using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) - { - string line; - int length = 0; - int lineNo = 0; - while ((line = reader.ReadLine()) != null) - { - if (line.Length > length) - { - length = line.Length; - No = lineNo; - } - lineNo++; - } - } - return No; - } public static List LongestLines(string fin) - { - List lines = new List(); - int longestLength = 0; - - using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) - { - string line; - int lineNo = 0; - while ((line = reader.ReadLine()) != null) - { - if (line.Length > longestLength) - { - longestLength = line.Length; - lines.Clear(); - lines.Add(lineNo); - } - else if (line.Length == longestLength) - { - lines.Add(lineNo); - } - lineNo++; - } - } - - return lines; - } public static void RemoveLine(string fin, string fout, int No) - { - using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) - { - string line; - int lineNo = 0; - using (var writer = File.CreateText(fout)) - { - while ((line = reader.ReadLine()) != null) - { - if (No != lineNo) - { - writer.WriteLine(line); - } - lineNo++; - } - } - } - } - - public static void RemoveLines(string fin, string fout, List lines) - { - using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) - { - string line; - int lineNo = 0; - using (var writer = File.CreateText(fout)) - { - while ((line = reader.ReadLine()) != null) - { - if (!lines.Contains(lineNo)) - { - writer.WriteLine(line); - } - lineNo++; - } - } - } - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace Lab4.RemoveLines +{ + class InOut + { + public static int LongestLine(string fin) + { + int No = -1; + using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) + { + string line; + int length = 0; + int lineNo = 0; + while ((line = reader.ReadLine()) != null) + { + if (line.Length > length) + { + length = line.Length; + No = lineNo; + } + lineNo++; + } + } + return No; + } public static List LongestLines(string fin) + { + List lines = new List(); + int longestLength = 0; + + using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) + { + string line; + int lineNo = 0; + while ((line = reader.ReadLine()) != null) + { + if (line.Length > longestLength) + { + longestLength = line.Length; + lines.Clear(); + lines.Add(lineNo); + } + else if (line.Length == longestLength) + { + lines.Add(lineNo); + } + lineNo++; + } + } + + return lines; + } public static void RemoveLine(string fin, string fout, int No) + { + using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) + { + string line; + int lineNo = 0; + using (var writer = File.CreateText(fout)) + { + while ((line = reader.ReadLine()) != null) + { + if (No != lineNo) + { + writer.WriteLine(line); + } + lineNo++; + } + } + } + } + + public static void RemoveLines(string fin, string fout, List lines) + { + using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) + { + string line; + int lineNo = 0; + using (var writer = File.CreateText(fout)) + { + while ((line = reader.ReadLine()) != null) + { + if (!lines.Contains(lineNo)) + { + writer.WriteLine(line); + } + lineNo++; + } + } + } + } + } +}