/// <summary>
/// Tries to parse the given input buffer into a new <see cref="MimeKit.Header"/> instance.
/// </summary>
/// <returns><c>true</c>, if the header was successfully parsed, <c>false</c> otherwise.</returns>
/// <param name="options">The parser options to use.</param>
/// <param name="buffer">The input buffer.</param>
/// <param name="startIndex">The starting index of the input buffer.</param>
/// <param name="length">The number of bytes in the input buffer to parse.</param>
/// <param name="header">The parsed header.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="buffer"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="startIndex"/> and <paramref name="length"/> do not specify
/// a valid range in the byte array.
/// </exception>
public static bool TryParse(ParserOptions options, byte[] buffer, int startIndex, int length, out Header header)
{
if (options == null)
{
throw new ArgumentNullException("options");
}
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if (startIndex < 0 || startIndex > buffer.Length)
{
throw new ArgumentOutOfRangeException("startIndex");
}
if (length < 0 || startIndex + length > buffer.Length)
{
throw new ArgumentOutOfRangeException("length");
}
unsafe
{
fixed(byte *inptr = buffer)
{
return(TryParse(options.Clone(), inptr + startIndex, length, true, out header));
}
}
}