< Summary

Information
Class: System.Net.Http.Headers.TransferCodingHeaderValue
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\TransferCodingHeaderValue.cs
Line coverage
48%
Covered lines: 40
Uncovered lines: 42
Coverable lines: 82
Total lines: 145
Line coverage: 48.7%
Branch coverage
60%
Covered branches: 12
Total branches: 20
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%110%
.ctor(...)100%110%
Parse(...)100%110%
TryParse(...)0%220%
GetTransferCodingLength(...)83.33%121293.54%
ToString()100%11100%
Equals(...)0%440%
GetHashCode()100%110%
System.ICloneable.Clone()100%110%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\TransferCodingHeaderValue.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Generic;
 5using System.Diagnostics;
 6using System.Diagnostics.CodeAnalysis;
 7using System.IO;
 8using System.Text;
 9
 10namespace System.Net.Http.Headers
 11{
 12    public class TransferCodingHeaderValue : ICloneable
 13    {
 14        // Use UnvalidatedObjectCollection<T> since we may have multiple parameters with the same name.
 15        private UnvalidatedObjectCollection<NameValueHeaderValue>? _parameters;
 35864816        private string _value = null!; // empty constructor only used internally and value set with non null
 17
 018        public string Value => _value;
 19
 9262820        public ICollection<NameValueHeaderValue> Parameters => _parameters ??= new UnvalidatedObjectCollection<NameValue
 21
 35864822        internal TransferCodingHeaderValue()
 35864823        {
 35864824        }
 25
 026        protected TransferCodingHeaderValue(TransferCodingHeaderValue source)
 027        {
 028            Debug.Assert(source != null);
 29
 030            _value = source._value;
 031            _parameters = source._parameters.Clone();
 032        }
 33
 034        public TransferCodingHeaderValue(string value)
 035        {
 036            HeaderUtilities.CheckValidToken(value);
 037            _value = value;
 038        }
 39
 40        public static TransferCodingHeaderValue Parse(string input)
 041        {
 042            int index = 0;
 043            return (TransferCodingHeaderValue)TransferCodingHeaderParser.SingleValueParser.ParseValue(
 044                input, null, ref index);
 045        }
 46
 47        public static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out TransferCodingHeaderValue
 048        {
 049            int index = 0;
 050            parsedValue = null;
 51
 052            if (TransferCodingHeaderParser.SingleValueParser.TryParseValue(input, null, ref index, out object? output))
 053            {
 054                parsedValue = (TransferCodingHeaderValue)output!;
 055                return true;
 56            }
 057            return false;
 058        }
 59
 60        internal static int GetTransferCodingLength(string input, int startIndex,
 61            Func<TransferCodingHeaderValue> transferCodingCreator, out TransferCodingHeaderValue? parsedValue)
 35882262        {
 35882263            Debug.Assert(transferCodingCreator != null);
 35882264            Debug.Assert(startIndex >= 0);
 65
 35882266            parsedValue = null;
 67
 35882268            if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
 069            {
 070                return 0;
 71            }
 72
 73            // Caller must remove leading whitespace. If not, we'll return 0.
 35882274            int valueLength = HttpRuleParser.GetTokenLength(input, startIndex);
 75
 35882276            if (valueLength == 0)
 17477            {
 17478                return 0;
 79            }
 80
 35864881            string value = input.Substring(startIndex, valueLength);
 35864882            int current = startIndex + valueLength;
 35864883            current += HttpRuleParser.GetWhitespaceLength(input, current);
 84            TransferCodingHeaderValue transferCodingHeader;
 85
 86            // If we're not done and we have a parameter delimiter, then we have a list of parameters.
 35864887            if ((current < input.Length) && (input[current] == ';'))
 9262888            {
 9262889                transferCodingHeader = transferCodingCreator();
 9262890                transferCodingHeader._value = value;
 91
 9262892                current++; // skip delimiter.
 9262893                int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';',
 9262894                    (UnvalidatedObjectCollection<NameValueHeaderValue>)transferCodingHeader.Parameters);
 95
 9262896                if (parameterLength == 0)
 33097                {
 33098                    return 0;
 99                }
 100
 92298101                parsedValue = transferCodingHeader;
 92298102                return current + parameterLength - startIndex;
 103            }
 104
 105            // We have a transfer coding without parameters.
 266020106            transferCodingHeader = transferCodingCreator();
 266020107            transferCodingHeader._value = value;
 266020108            parsedValue = transferCodingHeader;
 266020109            return current - startIndex;
 358822110        }
 111
 112        public override string ToString()
 548050113        {
 548050114            StringBuilder sb = StringBuilderCache.Acquire();
 548050115            sb.Append(_value);
 548050116            NameValueHeaderValue.ToString(_parameters, ';', true, sb);
 548050117            return StringBuilderCache.GetStringAndRelease(sb);
 548050118        }
 119
 120        public override bool Equals([NotNullWhen(true)] object? obj)
 0121        {
 0122            TransferCodingHeaderValue? other = obj as TransferCodingHeaderValue;
 123
 0124            if (other == null)
 0125            {
 0126                return false;
 127            }
 128
 0129            return string.Equals(_value, other._value, StringComparison.OrdinalIgnoreCase) &&
 0130                HeaderUtilities.AreEqualCollections(_parameters, other._parameters);
 0131        }
 132
 133        public override int GetHashCode()
 0134        {
 135            // The value string is case-insensitive.
 0136            return StringComparer.OrdinalIgnoreCase.GetHashCode(_value) ^ NameValueHeaderValue.GetHashCode(_parameters);
 0137        }
 138
 139        // Implement ICloneable explicitly to allow derived types to "override" the implementation.
 140        object ICloneable.Clone()
 0141        {
 0142            return new TransferCodingHeaderValue(this);
 0143        }
 144    }
 145}