< Summary

Class:Azure.Core.Http.Multipart.BaseHeaderParser`1
Assembly:Azure.Storage.Blobs.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\BaseHeaderParser.cs
Covered lines:0
Uncovered lines:25
Coverable lines:25
Total lines:77
Line coverage:0% (0 of 25)
Covered branches:0
Total branches:22
Branch coverage:0% (0 of 22)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%100%
TryParseValue(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\BaseHeaderParser.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// Copied from https://github.com/aspnet/AspNetCore/tree/master/src/Http/Headers/src
 5
 6#pragma warning disable IDE0018 // Inline declaration
 7#pragma warning disable IDE0034 // default can be simplified
 8#pragma warning disable IDE0054 // Use compound assignment
 9#pragma warning disable IDE0059 // Unnecessary assignment
 10
 11namespace Azure.Core.Http.Multipart
 12{
 13    internal abstract class BaseHeaderParser<T> : HttpHeaderParser<T>
 14    {
 15        protected BaseHeaderParser(bool supportsMultipleValues)
 016            : base(supportsMultipleValues)
 17        {
 018        }
 19
 20        protected abstract int GetParsedValueLength(StringSegment value, int startIndex, out T parsedValue);
 21
 22        public sealed override bool TryParseValue(StringSegment value, ref int index, out T parsedValue)
 23        {
 024            parsedValue = default(T);
 25
 26            // If multiple values are supported (i.e. list of values), then accept an empty string: The header may
 27            // be added multiple times to the request/response message. E.g.
 28            //  Accept: text/xml; q=1
 29            //  Accept:
 30            //  Accept: text/plain; q=0.2
 031            if (StringSegment.IsNullOrEmpty(value) || (index == value.Length))
 32            {
 033                return SupportsMultipleValues;
 34            }
 35
 036            var separatorFound = false;
 037            var current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(value, index, SupportsMultipleValues,
 038                out separatorFound);
 39
 040            if (separatorFound && !SupportsMultipleValues)
 41            {
 042                return false; // leading separators not allowed if we don't support multiple values.
 43            }
 44
 045            if (current == value.Length)
 46            {
 047                if (SupportsMultipleValues)
 48                {
 049                    index = current;
 50                }
 051                return SupportsMultipleValues;
 52            }
 53
 54            T result;
 055            var length = GetParsedValueLength(value, current, out result);
 56
 057            if (length == 0)
 58            {
 059                return false;
 60            }
 61
 062            current = current + length;
 063            current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(value, current, SupportsMultipleValues,
 064                out separatorFound);
 65
 66            // If we support multiple values and we've not reached the end of the string, then we must have a separator.
 067            if ((separatorFound && !SupportsMultipleValues) || (!separatorFound && (current < value.Length)))
 68            {
 069                return false;
 70            }
 71
 072            index = current;
 073            parsedValue = result;
 074            return true;
 75        }
 76    }
 77}

Methods/Properties

.ctor(...)
TryParseValue(...)