internal void ReadDebianParagraphs(TextReader reader) { string line; int lineNumber = 0; var state = ReadingState.BeginParagraph; DebianParagraph paragraph = null; DebianField field = null; while ((line = reader.ReadLine()) != null) { ++lineNumber; if (line.Trim().Length == 0) { state = ReadingState.BeginParagraph; continue; } switch (state) { case ReadingState.BeginParagraph: if (Char.IsLetter(line[0])) { paragraph = new DebianParagraph(); Paragraphs.Add(paragraph); field = new DebianField(line); paragraph.Fields.Add(field); state = ReadingState.FieldStarted; } else { Console.WriteLine("ERROR"); } break; case ReadingState.FieldStarted: if (line[0] == ' ' || line[0] == '\t') // I've only ever seen spaces, but the standard allows tabs. { field.FullDescription.Add(line.Substring(1)); } else { field = new DebianField(line); paragraph.Fields.Add(field); } break; } } }
internal void AddLicenseParagraphIfNeeded(string license, IEnumerable <string> detailLines) { // Check whether we need a license paragraph, and add it if needed. foreach (var p in Paragraphs) { if (p.Fields.Count == 1 && p.Fields[0].Tag == "License" && p.Fields[0].Value == license) { return; // license already written out } } var para = new DebianParagraph(); Paragraphs.Add(para); var field = new DebianField("License", license); para.Fields.Add(field); foreach (var line in detailLines) { field.FullDescription.Add(line); } }