1
0

feat: add Lab4.RemoveComments

This commit is contained in:
Rokas Puzonas 2021-11-21 01:14:29 +02:00
parent cc64b2190f
commit 30a3aede90
6 changed files with 173 additions and 0 deletions

View File

@ -0,0 +1,18 @@
void DuomenysInternet(Grybai & grybai)
{
ifstream fd(u2);
// string pav, tip;
// GrybasInfo s1;
int ns = 0;
bool yra = true;
while(!fd.eof() && yra) { // kol yra duomenų ir jie telpa į masyvą
fd >> pav >> tip;
s1.Dėti (pav, tip);
if(!fd.eof() && (ns - 1 < Grybai::CMax ) )
grybai[ns++] = s1; // įrašo naują elementą
else
yra = false;
}
fd.close();
grybai.Dėti(ns);
}

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Lab4.RemoveComments
{
class InOut
{
public static void Process(string fin, string fout, string finfo)
{
string[] lines = File.ReadAllLines(fin, Encoding.UTF8);
string[] cleanedLines = TaskUtils.RemoveComments(lines);
File.WriteAllLines(fout, cleanedLines);
using (var writer = File.CreateText(finfo))
{
// Check line by line which differ
int j = 0; // Used for cleaned lines
for (int i = 0; i < lines.Length && j < cleanedLines.Length; i++)
{
Console.WriteLine("{0} ============ {1}", lines[i], cleanedLines[j]);
if (lines[i] != cleanedLines[j])
{
writer.WriteLine(lines[i]);
}
else
{
j++;
}
}
}
/*
using (var writerF = File.CreateText(fout))
{
using (var writerI = File.CreateText(finfo))
{
foreach (string line in lines)
{
if (line.Length > 0)
{
string newLine = line;
if (TaskUtils.RemoveComments(line, out newLine))
writerI.WriteLine(line);
if (newLine.Length > 0)
writerF.WriteLine(newLine);
}
else
{
writerF.WriteLine(line);
}
}
}
}
*/
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Update="Duomenys.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,15 @@
using System;
namespace Lab4.RemoveComments
{
class Program
{
static void Main(string[] args)
{
const string CFd = "Duomenys.txt";
const string CFr = "Rezultatai.txt";
const string CFa = "Analize.txt";
InOut.Process(CFd, CFr, CFa);
}
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Lab4.RemoveComments
{
class TaskUtils
{
/** Removes comments and returns an indication about performed activity.
@param line line having possible comments
@param newLine line without comments */
public static string[] RemoveComments(string[] lines)
{
List<string> cleanedLines = new List<string>();
foreach (string line in lines)
{
Match case1 = Regex.Match(line, @"^(.*)//.*$");
if (case1.Success)
{
if (case1.Groups[1].Value.Length > 0)
{
cleanedLines.Add(case1.Groups[1].Value);
}
}
else
{
cleanedLines.Add(line);
}
}
/*
Match case1 = Regex.Match(line, @"^(.*)//.*$");
if (case1.Success)
{
newLine = case1.Groups[1].Value;
return true;
}
*/
return cleanedLines.ToArray();
/*
Match case2 = Regex.Match(line, @"^$");
if (case2.Success)
{
newLine = case2.Captures[1].Value;
return true;
}
*/
/*newLine = line;
for (int i = 0; i < line.Length - 1; i++)
if (line[i] == '/' && line[i + 1] == '/')
{
newLine = line.Remove(i);
return true;
}
return false;*/
}
}
}

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.1525
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.RemoveLines", "Lab4.RemoveLines\Lab4.RemoveLines.csproj", "{5309D21D-2A14-4332-90EC-504AD89CE397}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab4.RemoveComments", "Lab4.RemoveComments\Lab4.RemoveComments.csproj", "{4D9B08C9-5735-4C95-8D2A-BDFC888B1E68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab4.LetterFrequency", "Lab4.LetterFrequency\Lab4.LetterFrequency.csproj", "{F1797B5C-1541-4821-9485-7C3520C5DD8D}"
EndProject
Global