1
0

feat: normalize line endings

This commit is contained in:
Rokas Puzonas 2021-12-08 21:47:22 +02:00
parent a3a6052b54
commit 938e91e5e6
2 changed files with 103 additions and 95 deletions

8
.gitattributes vendored Normal file
View File

@ -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

View File

@ -1,95 +1,95 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
namespace Lab4.RemoveLines namespace Lab4.RemoveLines
{ {
class InOut class InOut
{ {
public static int LongestLine(string fin) public static int LongestLine(string fin)
{ {
int No = -1; int No = -1;
using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) using (StreamReader reader = new StreamReader(fin, Encoding.UTF8))
{ {
string line; string line;
int length = 0; int length = 0;
int lineNo = 0; int lineNo = 0;
while ((line = reader.ReadLine()) != null) while ((line = reader.ReadLine()) != null)
{ {
if (line.Length > length) if (line.Length > length)
{ {
length = line.Length; length = line.Length;
No = lineNo; No = lineNo;
} }
lineNo++; lineNo++;
} }
} }
return No; return No;
} public static List<int> LongestLines(string fin) } public static List<int> LongestLines(string fin)
{ {
List<int> lines = new List<int>(); List<int> lines = new List<int>();
int longestLength = 0; int longestLength = 0;
using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) using (StreamReader reader = new StreamReader(fin, Encoding.UTF8))
{ {
string line; string line;
int lineNo = 0; int lineNo = 0;
while ((line = reader.ReadLine()) != null) while ((line = reader.ReadLine()) != null)
{ {
if (line.Length > longestLength) if (line.Length > longestLength)
{ {
longestLength = line.Length; longestLength = line.Length;
lines.Clear(); lines.Clear();
lines.Add(lineNo); lines.Add(lineNo);
} }
else if (line.Length == longestLength) else if (line.Length == longestLength)
{ {
lines.Add(lineNo); lines.Add(lineNo);
} }
lineNo++; lineNo++;
} }
} }
return lines; return lines;
} public static void RemoveLine(string fin, string fout, int No) } public static void RemoveLine(string fin, string fout, int No)
{ {
using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) using (StreamReader reader = new StreamReader(fin, Encoding.UTF8))
{ {
string line; string line;
int lineNo = 0; int lineNo = 0;
using (var writer = File.CreateText(fout)) using (var writer = File.CreateText(fout))
{ {
while ((line = reader.ReadLine()) != null) while ((line = reader.ReadLine()) != null)
{ {
if (No != lineNo) if (No != lineNo)
{ {
writer.WriteLine(line); writer.WriteLine(line);
} }
lineNo++; lineNo++;
} }
} }
} }
} }
public static void RemoveLines(string fin, string fout, List<int> lines) public static void RemoveLines(string fin, string fout, List<int> lines)
{ {
using (StreamReader reader = new StreamReader(fin, Encoding.UTF8)) using (StreamReader reader = new StreamReader(fin, Encoding.UTF8))
{ {
string line; string line;
int lineNo = 0; int lineNo = 0;
using (var writer = File.CreateText(fout)) using (var writer = File.CreateText(fout))
{ {
while ((line = reader.ReadLine()) != null) while ((line = reader.ReadLine()) != null)
{ {
if (!lines.Contains(lineNo)) if (!lines.Contains(lineNo))
{ {
writer.WriteLine(line); writer.WriteLine(line);
} }
lineNo++; lineNo++;
} }
} }
} }
} }
} }
} }