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

GetNameValueLength() static private method

static private GetNameValueLength ( string input, int startIndex, Func nameValueCreator, NameValueHeaderValue &parsedValue ) : int
input string
startIndex int
nameValueCreator Func
parsedValue NameValueHeaderValue
return int
        internal static int GetNameValueLength(string input, int startIndex,
            Func<NameValueHeaderValue> nameValueCreator, out NameValueHeaderValue parsedValue)
        {
            Debug.Assert(input != null);
            Debug.Assert(startIndex >= 0);
            Debug.Assert(nameValueCreator != null);

            parsedValue = null;

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

            // Parse the name, i.e. <name> in name/value string "<name>=<value>". Caller must remove 
            // leading whitespace.
            int nameLength = HttpRuleParser.GetTokenLength(input, startIndex);

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

            string name = input.Substring(startIndex, nameLength);
            int current = startIndex + nameLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            // Parse the separator between name and value
            if ((current == input.Length) || (input[current] != '='))
            {
                // We only have a name and that's OK. Return.
                parsedValue = nameValueCreator();
                parsedValue._name = name;
                current = current + HttpRuleParser.GetWhitespaceLength(input, current); // skip whitespace
                return current - startIndex;
            }

            current++; // skip delimiter.
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            // Parse the value, i.e. <value> in name/value string "<name>=<value>"
            int valueLength = GetValueLength(input, current);

            if (valueLength == 0)
            {
                return 0; // We have an invalid value. 
            }

            // Use parameterless ctor to avoid double-parsing of name and value, i.e. skip public ctor validation.
            parsedValue = nameValueCreator();
            parsedValue._name = name;
            parsedValue._value = input.Substring(current, valueLength);
            current = current + valueLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current); // skip whitespace
            return current - startIndex;
        }

Same methods

NameValueHeaderValue::GetNameValueLength ( string input, int startIndex, NameValueHeaderValue &parsedValue ) : int

Usage Example

Esempio n. 1
0
        internal static int GetNameValueListLength(
            string input,
            int startIndex,
            char delimiter,
            ObjectCollection <NameValueHeaderValue> nameValueCollection)
        {
            if (string.IsNullOrEmpty(input) || startIndex >= input.Length)
            {
                return(0);
            }
            int startIndex1 = startIndex + HttpRuleParser.GetWhitespaceLength(input, startIndex);
            int index;

            while (true)
            {
                NameValueHeaderValue parsedValue = (NameValueHeaderValue)null;
                int nameValueLength = NameValueHeaderValue.GetNameValueLength(input, startIndex1, NameValueHeaderValue.s_defaultNameValueCreator, out parsedValue);
                if (nameValueLength != 0)
                {
                    nameValueCollection.Add(parsedValue);
                    int startIndex2 = startIndex1 + nameValueLength;
                    index = startIndex2 + HttpRuleParser.GetWhitespaceLength(input, startIndex2);
                    if (index != input.Length && (int)input[index] == (int)delimiter)
                    {
                        int startIndex3 = index + 1;
                        startIndex1 = startIndex3 + HttpRuleParser.GetWhitespaceLength(input, startIndex3);
                    }
                    else
                    {
                        goto label_6;
                    }
                }
                else
                {
                    break;
                }
            }
            return(0);

label_6:
            return(index - startIndex);
        }
All Usage Examples Of System.Net.Http.Headers.NameValueHeaderValue::GetNameValueLength