| 12345678910111213141516171819202122232425262728293031323334 |
- using System.Text.RegularExpressions;
- namespace Day13;
- public partial class Parser
- {
- [GeneratedRegex(@".*")]
- private partial Regex LineMatch();
-
- public IEnumerable<Image> Parse(string inputFile)
- {
- using var reader = File.OpenText(inputFile);
- var buffer = new List<string>();
- while (!reader.EndOfStream)
- {
- var line = reader.ReadLine()!;
- if (string.IsNullOrEmpty(line) && buffer.Count > 0)
- {
- yield return new Image(buffer);
- buffer = new List<string>();
- }
- else
- {
- buffer.Add(line);
- }
- }
- if (buffer.Count > 0)
- {
- yield return new Image(buffer);
- }
- }
- }
|