System.Net.Http.Headers.ProductHeaderValue.GetProductLength C# (CSharp) Method

GetProductLength() static private method

static private GetProductLength ( string input, int startIndex, ProductHeaderValue &parsedValue ) : int
input string
startIndex int
parsedValue ProductHeaderValue
return int
        internal static int GetProductLength(string input, int startIndex, out ProductHeaderValue parsedValue)
        {
            Debug.Assert(startIndex >= 0);

            parsedValue = null;

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

            // Parse the name string: <name> in '<name>/<version>'.
            int nameLength = HttpRuleParser.GetTokenLength(input, startIndex);

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

            ProductHeaderValue result = new ProductHeaderValue();
            result._name = input.Substring(startIndex, nameLength);
            int current = startIndex + nameLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            if ((current == input.Length) || (input[current] != '/'))
            {
                parsedValue = result;
                return current - startIndex;
            }

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

            // Parse the name string: <version> in '<name>/<version>'.
            int versionLength = HttpRuleParser.GetTokenLength(input, current);

            if (versionLength == 0)
            {
                return 0; // If there is a '/' separator it must be followed by a valid token.
            }

            result._version = input.Substring(current, versionLength);

            current = current + versionLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            parsedValue = result;
            return current - startIndex;
        }

Usage Example

Esempio n. 1
0
        private static int ParseProduct(string value, int startIndex, out object?parsedValue)
        {
            int resultLength = ProductHeaderValue.GetProductLength(value, startIndex, out ProductHeaderValue? temp);

            parsedValue = temp;
            return(resultLength);
        }
All Usage Examples Of System.Net.Http.Headers.ProductHeaderValue::GetProductLength