private void CheckInvalidParsedValue(string input, int startIndex)
        {
            HttpHeaderParser parser = GenericHeaderParser.MailAddressParser;
            object           result = null;
            int newIndex            = startIndex;

            Assert.False(parser.TryParseValue(input, null, ref newIndex, out result),
                         string.Format("TryParse returned true: {0}", input));
            Assert.Null(result);
            Assert.Equal(startIndex, newIndex);
        }
        private void CheckValidParsedValue(string input, int startIndex, string expectedResult,
                                           int expectedIndex)
        {
            HttpHeaderParser parser = GenericHeaderParser.MailAddressParser;
            object           result = null;

            Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
                        string.Format("TryParse returned false: {0}", input));
            Assert.Equal(expectedIndex, startIndex);
            Assert.Equal(expectedResult, result);
        }
Exemple #3
0
        private void CheckValidParsedValue(string input, int startIndex,
                                           NameValueWithParametersHeaderValue expectedResult, int expectedIndex)
        {
            HttpHeaderParser parser = GenericHeaderParser.MultipleValueNameValueWithParametersParser;
            object           result = null;

            Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
                        string.Format("TryParse returned false. Input: '{0}', Index: {1}", input, startIndex));
            Assert.Equal(expectedIndex, startIndex);
            Assert.Equal(result, expectedResult);
        }
Exemple #4
0
        private void CheckInvalidParsedValue(string input, int startIndex)
        {
            HttpHeaderParser parser = GenericHeaderParser.MultipleValueNameValueWithParametersParser;
            object           result = null;
            int newIndex            = startIndex;

            Assert.False(parser.TryParseValue(input, null, ref newIndex, out result),
                         string.Format("TryParse returned true. Input: '{0}', Index: {1}", input, startIndex));
            Assert.Null(result);
            Assert.Equal(startIndex, newIndex);
        }
Exemple #5
0
        private void CheckInvalidParsedValue(string input, int startIndex)
        {
            HttpHeaderParser parser = GenericHeaderParser.ContentRangeParser;
            object           result = null;
            int newIndex            = startIndex;

            Assert.False(parser.TryParseValue(input, null, ref newIndex, out result),
                         string.Format("TryParse returned true. Input: '{0}'", input));
            Assert.Equal(null, result);
            Assert.Equal(startIndex, newIndex);
        }
Exemple #6
0
        private void CheckValidParsedValue(string input, int startIndex, RangeConditionHeaderValue expectedResult,
                                           int expectedIndex)
        {
            HttpHeaderParser parser = GenericHeaderParser.RangeConditionParser;
            object           result = null;

            Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
                        string.Format("TryParse returned false. Input: '{0}'", input));
            Assert.Equal(expectedIndex, startIndex);
            Assert.Equal(expectedResult, result);
        }
Exemple #7
0
    /// <summary>
    /// Attempts to parse the specified <paramref name="input"/> as a <see cref="CacheControlHeaderValue"/>.
    /// </summary>
    /// <param name="input">The value to parse.</param>
    /// <param name="parsedValue">The parsed value.</param>
    /// <returns><see langword="true"/> if input is a valid <see cref="CacheControlHeaderValue"/>, otherwise <see langword="false"/>.</returns>
    public static bool TryParse(StringSegment input, [NotNullWhen(true)] out CacheControlHeaderValue?parsedValue)
    {
        var index = 0;

        // Cache-Control is unusual because there are no required values so the parser will succeed for an empty string, but still return null.
        if (Parser.TryParseValue(input, ref index, out parsedValue) && parsedValue != null)
        {
            return(true);
        }
        parsedValue = null;
        return(false);
    }
        private void CheckInvalidParsedValue(string input, int startIndex, bool supportMultipleValues)
        {
            HttpHeaderParser parser = null;

            if (supportMultipleValues)
            {
                parser = GenericHeaderParser.MultipleValueAuthenticationParser;
            }
            else
            {
                parser = GenericHeaderParser.SingleValueAuthenticationParser;
            }

            object result   = null;
            int    newIndex = startIndex;

            Assert.False(parser.TryParseValue(input, null, ref newIndex, out result),
                         string.Format("TryParse returned true. Input: '{0}'", input));
            Assert.Null(result);
            Assert.Equal(startIndex, newIndex);
        }
        private void CheckValidParsedValue(string input, int startIndex, AuthenticationHeaderValue expectedResult,
                                           int expectedIndex, bool supportMultipleValues)
        {
            HttpHeaderParser parser = null;

            if (supportMultipleValues)
            {
                parser = GenericHeaderParser.MultipleValueAuthenticationParser;
            }
            else
            {
                parser = GenericHeaderParser.SingleValueAuthenticationParser;
            }

            object result = null;

            Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
                        string.Format("TryParse returned false. Input: '{0}'", input));
            Assert.Equal(expectedIndex, startIndex);
            Assert.Equal(result, expectedResult);
        }
        private void CheckValidParsedValue(string input, int startIndex, EntityTagHeaderValue expectedResult,
                                           int expectedIndex, bool supportsMultipleValues)
        {
            HttpHeaderParser parser = null;

            if (supportsMultipleValues)
            {
                parser = GenericHeaderParser.MultipleValueEntityTagParser;
            }
            else
            {
                parser = GenericHeaderParser.SingleValueEntityTagParser;
            }

            object result = null;

            Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
                        string.Format("TryParse returned false. Input: '{0}', AllowMultipleValues/Any: {1}", input,
                                      supportsMultipleValues));
            Assert.Equal(expectedIndex, startIndex);
            Assert.Equal(result, expectedResult);
        }
        private void CheckInvalidParsedValue(string input, int startIndex, bool supportsMultipleValues)
        {
            HttpHeaderParser parser = null;

            if (supportsMultipleValues)
            {
                parser = GenericHeaderParser.MultipleValueEntityTagParser;
            }
            else
            {
                parser = GenericHeaderParser.SingleValueEntityTagParser;
            }

            object result   = null;
            int    newIndex = startIndex;

            Assert.False(parser.TryParseValue(input, null, ref newIndex, out result),
                         string.Format("TryParse returned true. Input: '{0}', AllowMultipleValues/Any: {1}", input,
                                       supportsMultipleValues));
            Assert.Equal(null, result);
            Assert.Equal(startIndex, newIndex);
        }
Exemple #12
0
    /// <summary>
    /// Attempts to parse the specified <paramref name="input"/> as a <see cref="RangeConditionHeaderValue"/>.
    /// </summary>
    /// <param name="input">The value to parse.</param>
    /// <param name="parsedValue">The parsed value.</param>
    /// <returns><see langword="true"/> if input is a valid <see cref="RangeConditionHeaderValue"/>, otherwise <see langword="false"/>.</returns>
    public static bool TryParse(StringSegment input, [NotNullWhen(true)] out RangeConditionHeaderValue?parsedValue)
    {
        var index = 0;

        return(Parser.TryParseValue(input, ref index, out parsedValue !));
    }
        public static bool TryParse(string input, out NameValueHeaderValue parsedValue)
        {
            var index = 0;

            return(SingleValueParser.TryParseValue(input, ref index, out parsedValue));
        }
    /// <summary>
    /// Attempts to parse the specified <paramref name="input"/> as a <see cref="StringWithQualityHeaderValue"/>.
    /// </summary>
    /// <param name="input">The value to parse.</param>
    /// <param name="parsedValue">The parsed value.</param>
    /// <returns><see langword="true"/> if input is a valid <see cref="StringWithQualityHeaderValue"/>, otherwise <see langword="false"/>.</returns>
    public static bool TryParse(StringSegment input, [NotNullWhen(true)] out StringWithQualityHeaderValue parsedValue)
    {
        var index = 0;

        return(SingleValueParser.TryParseValue(input, ref index, out parsedValue !));
    }