private static string ParseDomain(string data, ref int index)
{
// Skip comments and whitespace
index = ReadCfwsAndThrowIfIncomplete(data, index);
// Mark one end of the domain component
int startingIndex = index;
// Is the domain component in domain-literal format or dot-atom format?
if (data[index] == MailBnfHelper.EndSquareBracket)
{
index = DomainLiteralReader.ReadReverse(data, index);
}
else
{
index = DotAtomReader.ReadReverse(data, index);
}
string domain = data.Substring(index + 1, startingIndex - index);
// Skip comments and whitespace
index = ReadCfwsAndThrowIfIncomplete(data, index);
return NormalizeOrThrow(domain);
}