System.Net.Http.Headers.NameValueHeaderValue.GetNameValueListLength C# (CSharp) Method

GetNameValueListLength() static private method

static private GetNameValueListLength ( string input, int startIndex, char delimiter, ObjectCollection nameValueCollection ) : int
input string
startIndex int
delimiter char
nameValueCollection ObjectCollection
return int
        internal static int GetNameValueListLength(string input, int startIndex, char delimiter,
            ObjectCollection<NameValueHeaderValue> nameValueCollection)
        {
            Debug.Assert(nameValueCollection != null);
            Debug.Assert(startIndex >= 0);

            if ((string.IsNullOrEmpty(input)) || (startIndex >= input.Length))
            {
                return 0;
            }

            int current = startIndex + HttpRuleParser.GetWhitespaceLength(input, startIndex);
            while (true)
            {
                NameValueHeaderValue parameter = null;
                int nameValueLength = NameValueHeaderValue.GetNameValueLength(input, current,
                    s_defaultNameValueCreator, out parameter);

                if (nameValueLength == 0)
                {
                    return 0;
                }

                nameValueCollection.Add(parameter);
                current = current + nameValueLength;
                current = current + HttpRuleParser.GetWhitespaceLength(input, current);

                if ((current == input.Length) || (input[current] != delimiter))
                {
                    // We're done and we have at least one valid name/value pair.
                    return current - startIndex;
                }

                // input[current] is 'delimiter'. Skip the delimiter and whitespace and try to parse again.
                current++; // skip delimiter.
                current = current + HttpRuleParser.GetWhitespaceLength(input, current);
            }
        }

Usage Example

Ejemplo n.º 1
0
        internal static int GetTransferCodingLength(string input, int startIndex,
                                                    Func <TransferCodingHeaderValue> transferCodingCreator, out TransferCodingHeaderValue?parsedValue)
        {
            Debug.Assert(transferCodingCreator != null);
            Debug.Assert(startIndex >= 0);

            parsedValue = null;

            if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
            {
                return(0);
            }

            // Caller must remove leading whitespace. If not, we'll return 0.
            int valueLength = HttpRuleParser.GetTokenLength(input, startIndex);

            if (valueLength == 0)
            {
                return(0);
            }

            string value   = input.Substring(startIndex, valueLength);
            int    current = startIndex + valueLength;

            current = current + HttpRuleParser.GetWhitespaceLength(input, current);
            TransferCodingHeaderValue transferCodingHeader;

            // If we're not done and we have a parameter delimiter, then we have a list of parameters.
            if ((current < input.Length) && (input[current] == ';'))
            {
                transferCodingHeader        = transferCodingCreator();
                transferCodingHeader._value = value;

                current++; // skip delimiter.
                int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';',
                                                                                  (UnvalidatedObjectCollection <NameValueHeaderValue>)transferCodingHeader.Parameters);

                if (parameterLength == 0)
                {
                    return(0);
                }

                parsedValue = transferCodingHeader;
                return(current + parameterLength - startIndex);
            }

            // We have a transfer coding without parameters.
            transferCodingHeader        = transferCodingCreator();
            transferCodingHeader._value = value;
            parsedValue = transferCodingHeader;
            return(current - startIndex);
        }
All Usage Examples Of System.Net.Http.Headers.NameValueHeaderValue::GetNameValueListLength