using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Packaging.Targets.Deb
{
///
/// Supports reading and writing Debian control files.
///
///
internal static class ControlFileParser
{
///
/// Reads a control file from a .
///
///
/// A which represents the control file.
///
///
/// A which represents the contents of the control file.
///
internal static Dictionary Read(Stream stream)
{
Dictionary values = new Dictionary();
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8, false, bufferSize: 1024, leaveOpen: true))
{
string line;
string currentKey = null;
while (reader.Peek() > 0)
{
line = reader.ReadLine();
if (line.StartsWith("#"))
{
continue;
}
if (line.StartsWith(" ") || line.StartsWith("\t"))
{
// Continuation line
var value = values[currentKey];
value += '\n';
if (line.Trim() != ".")
{
value += line.Trim();
}
values[currentKey] = value;
}
else
{
string[] parts = line.Split(new char[] { ':' }, 2);
currentKey = parts[0].Trim();
string value = parts[1].Trim();
values.Add(currentKey, value);
}
}
}
return values;
}
}
}