Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main()
- {
- int count = int.Parse(Console.ReadLine());
- StringBuilder builder = new StringBuilder();
- string line;
- for (int i = 0; i < count; i++)
- {
- line = Console.ReadLine();
- if (line.Length>0)
- {
- builder.AppendLine(line);
- }
- }
- string content = builder.ToString();
- builder.Clear();
- char nextChar;
- bool inTotalQuote = false;
- bool inQuotes = false;
- bool inComment = false;
- bool inMultiComment = false;
- List<string> rows = new List<string>();
- for (int pos = 0; pos < content.Length; pos++)
- {
- nextChar = content[pos];
- if (nextChar == '\\' && !inTotalQuote && !inComment && !inMultiComment) //TODO: better
- {
- if (pos < content.Length -1 && content[pos+1] != '\n')
- {
- builder.Append("\\").Append(content[pos + 1]);
- }
- pos++;
- continue;
- }
- if (nextChar == '"')
- {
- if (inTotalQuote == true) //"" espaces quotes !
- {
- inTotalQuote = false;
- }
- else if (inQuotes == true)
- {
- inQuotes = false;
- }
- else if (inQuotes == false)
- {
- inQuotes = true;
- }
- }
- if (nextChar == '/' && !inQuotes && !inTotalQuote && !inComment && !inMultiComment)
- {
- if (pos < content.Length)
- {
- if (content[pos+1] == '/')
- {
- inComment = true;
- pos++;
- continue;
- }
- if (content[pos+1] == '*')
- {
- inMultiComment = true;
- pos++;
- continue;
- }
- }
- }
- if (nextChar == '*' && !inQuotes && !inTotalQuote && !inComment)
- {
- if (pos < content.Length)
- {
- if (content[pos+1] == '/')
- {
- inMultiComment = false;
- pos++;
- continue;
- }
- }
- }
- if (nextChar == '@' && !inQuotes && !inTotalQuote && !inComment && !inMultiComment)
- {
- if (pos < content.Length)
- {
- if (content[pos+1] == '"')
- {
- inTotalQuote = true;
- pos++;
- builder.Append("@\"");
- continue;
- }
- }
- }
- if (inComment == false && inMultiComment == false) //append current char
- {
- if (nextChar == '\n' && inMultiComment == false)
- {
- if (!string.IsNullOrWhiteSpace(builder.ToString()))
- {
- rows.Add(builder.ToString().TrimEnd('\r', '\n'));
- }
- builder.Clear();
- inQuotes = false;
- }
- else
- {
- builder.Append(nextChar);
- }
- continue;
- }
- if (nextChar == '\n' && inComment == true)
- {
- if (!string.IsNullOrWhiteSpace(builder.ToString().TrimEnd('\r','\n')))//builder.Length>0
- {
- rows.Add(builder.ToString());
- builder.Clear();
- inComment = false;
- inQuotes = false;
- }
- else
- {
- builder.Clear();
- inComment = false;
- inQuotes = false;
- }
- }
- }
- foreach (var item in rows)
- {
- if (!string.IsNullOrWhiteSpace(item))
- {
- Console.WriteLine(item);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement