// Parses the domain section of an address. The domain may be in dot-atom format or surrounded by square // brackets in domain-literal format. // e.g. <*****@*****.**> or <user@[whatever I want]> // // Preconditions: // - data[index] is just inside of the angle brackets (if any). // // Postconditions: // - data[index] should refer to the '@' symbol // - returns the parsed domain, including any square brackets for domain-literals // // Throws a FormatException: // - For invalid un-escaped chars, including Unicode // - If the start of the data string is reached 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)); }
// Parses the domain section of an address. The domain may be in dot-atom format or surrounded by square // brackets in domain-literal format. // e.g. <*****@*****.**> or <user@[whatever I want]> // // Preconditions: // - data[index] is just inside of the angle brackets (if any). // // Postconditions: // - data[index] should refer to the '@' symbol // - returns the parsed domain, including any square brackets for domain-literals // // Throws a FormatException or returns false: // - For invalid un-escaped chars, including Unicode // - If the start of the data string is reached private static bool TryParseDomain(string data, ref int index, [NotNullWhen(true)] out string?domain, bool throwExceptionIfFail) { // Skip comments and whitespace if (!TryReadCfwsAndThrowIfIncomplete(data, index, out index, throwExceptionIfFail)) { domain = default; return(false); } // 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) { if (!DomainLiteralReader.TryReadReverse(data, index, out index, throwExceptionIfFail)) { domain = default; return(false); } } else { if (!DotAtomReader.TryReadReverse(data, index, out index, throwExceptionIfFail)) { domain = default; return(false); } } domain = data.Substring(index + 1, startingIndex - index); // Skip comments and whitespace if (!TryReadCfwsAndThrowIfIncomplete(data, index, out index, throwExceptionIfFail)) { return(false); } if (!TryNormalizeOrThrow(domain, out domain, throwExceptionIfFail)) { return(false); } return(true); }
private static string ParseDomain(string data, ref int index) { index = ReadCfwsAndThrowIfIncomplete(data, index); int num = index; if (data[index] == MailBnfHelper.EndSquareBracket) { index = DomainLiteralReader.ReadReverse(data, index); } else { index = DotAtomReader.ReadReverse(data, index); } string str = data.Substring(index + 1, num - index); index = ReadCfwsAndThrowIfIncomplete(data, index); return(str); }