/// <summary>
 /// Sets <see cref="Value"/> after it has been quoted as defined by <see href="https://tools.ietf.org/html/rfc7230#section-3.2.6">the RFC specification</see>.
 /// </summary>
 /// <param name="value"></param>
 public void SetAndEscapeValue(StringSegment value)
 {
     HeaderUtilities.ThrowIfReadOnly(IsReadOnly);
     if (StringSegment.IsNullOrEmpty(value) || (GetValueLength(value, 0) == value.Length))
     {
         _value = value;
     }
     else
     {
         Value = HeaderUtilities.EscapeAsQuotedString(value);
     }
 }
 public void SetAndEscapeValue_ThrowsFormatExceptionOnDelCharacter()
 {
     Assert.Throws <FormatException>(() => { var actual = HeaderUtilities.EscapeAsQuotedString($"{(char)0x7F}"); });
 }
    public void SetAndEscapeValue_BehaviorCheck(string input, string expected)
    {
        var actual = HeaderUtilities.EscapeAsQuotedString(input);

        Assert.Equal(expected, actual);
    }
 public void SetAndEscapeValue_ControlCharactersThrowFormatException(string input)
 {
     Assert.Throws <FormatException>(() => { var actual = HeaderUtilities.EscapeAsQuotedString(input); });
 }
 public StringSegment EscapeAsQuotedString()
 {
     return(HeaderUtilities.EscapeAsQuotedString("\"hello\\\"foo\\\\bar\\\\baz\\\\\""));
 }