feat: finish Lab4.RemoveComments
This commit is contained in:
parent
30a3aede90
commit
9ecf4ff17c
@ -3,16 +3,17 @@ void DuomenysInternet(Grybai & grybai)
|
|||||||
ifstream fd(u2);
|
ifstream fd(u2);
|
||||||
// string pav, tip;
|
// string pav, tip;
|
||||||
// GrybasInfo s1;
|
// GrybasInfo s1;
|
||||||
int ns = 0;
|
int ns = 0; /*
|
||||||
bool yra = true;
|
bool yra = true;
|
||||||
|
*/
|
||||||
while(!fd.eof() && yra) { // kol yra duomenų ir jie telpa į masyvą
|
while(!fd.eof() && yra) { // kol yra duomenų ir jie telpa į masyvą
|
||||||
fd >> pav >> tip;
|
fd >> pav >> tip;
|
||||||
s1.Dėti (pav, tip);
|
s1.Dėti (pav, tip);
|
||||||
if(!fd.eof() && (ns - 1 < Grybai::CMax ) )
|
if(!fd.eof() && (ns - 1 < Grybai::CMax ) )
|
||||||
grybai[ns++] = s1; // įrašo naują elementą
|
grybai[ns++] = s1; // įrašo naują elementą
|
||||||
else
|
else
|
||||||
yra = false;
|
yra = false;
|
||||||
}
|
}
|
||||||
fd.close();
|
fd.close();
|
||||||
grybai.Dėti(ns);
|
grybai.Dėti(ns);
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,17 @@ namespace Lab4.RemoveComments
|
|||||||
|
|
||||||
using (var writer = File.CreateText(finfo))
|
using (var writer = File.CreateText(finfo))
|
||||||
{
|
{
|
||||||
// Check line by line which differ
|
|
||||||
int j = 0; // Used for cleaned lines
|
int j = 0; // Used for cleaned lines
|
||||||
|
// Check line by line which differ
|
||||||
for (int i = 0; i < lines.Length && j < cleanedLines.Length; i++)
|
for (int i = 0; i < lines.Length && j < cleanedLines.Length; i++)
|
||||||
{
|
{
|
||||||
Console.WriteLine("{0} ============ {1}", lines[i], cleanedLines[j]);
|
|
||||||
if (lines[i] != cleanedLines[j])
|
if (lines[i] != cleanedLines[j])
|
||||||
{
|
{
|
||||||
writer.WriteLine(lines[i]);
|
writer.WriteLine(lines[i]);
|
||||||
|
if (lines[i].StartsWith(cleanedLines[j]))
|
||||||
|
{
|
||||||
|
j++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -31,30 +34,6 @@ namespace Lab4.RemoveComments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,39 @@ namespace Lab4.RemoveComments
|
|||||||
{
|
{
|
||||||
List<string> cleanedLines = new List<string>();
|
List<string> cleanedLines = new List<string>();
|
||||||
|
|
||||||
|
bool multiLineComment = false;
|
||||||
|
|
||||||
foreach (string line in lines)
|
foreach (string line in lines)
|
||||||
{
|
{
|
||||||
Match case1 = Regex.Match(line, @"^(.*)//.*$");
|
Match case1 = Regex.Match(line, @"^(.*)/\*.*$");
|
||||||
if (case1.Success)
|
Match case2 = Regex.Match(line, @"^.*\*/(.*)$");
|
||||||
|
Match case3 = Regex.Match(line, @"^(.*)//.*$");
|
||||||
|
|
||||||
|
if (case1.Success)
|
||||||
|
{
|
||||||
|
if (!multiLineComment) {
|
||||||
|
multiLineComment = true;
|
||||||
|
if (case1.Groups[1].Value.Length > 0)
|
||||||
|
{
|
||||||
|
cleanedLines.Add(case1.Groups[1].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (case2.Success)
|
||||||
|
{
|
||||||
|
if (multiLineComment) {
|
||||||
|
multiLineComment = false;
|
||||||
|
if (case2.Groups[1].Value.Length > 0)
|
||||||
|
{
|
||||||
|
cleanedLines.Add(case2.Groups[1].Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (case3.Success)
|
||||||
{
|
{
|
||||||
if (case1.Groups[1].Value.Length > 0)
|
if (case3.Groups[1].Value.Length > 0)
|
||||||
{
|
{
|
||||||
cleanedLines.Add(case1.Groups[1].Value);
|
cleanedLines.Add(case3.Groups[1].Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -30,35 +55,7 @@ namespace Lab4.RemoveComments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Match case1 = Regex.Match(line, @"^(.*)//.*$");
|
|
||||||
if (case1.Success)
|
|
||||||
{
|
|
||||||
newLine = case1.Groups[1].Value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return cleanedLines.ToArray();
|
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;*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user