예제 #1
0
        private static int GetTypeLength(string input, int offset, out StringSegment type)
        {
            if (offset < 0 || offset >= input.Length)
            {
                type = default(StringSegment);
                return(0);
            }

            var current = offset + HttpTokenParsingRules.GetWhitespaceLength(input, offset);

            var typeLength = HttpTokenParsingRules.GetTokenLength(input, current);

            if (typeLength == 0)
            {
                type = default(StringSegment);
                return(0);
            }

            type = new StringSegment(input, current, typeLength);

            current += typeLength;
            current += HttpTokenParsingRules.GetWhitespaceLength(input, current);

            return(current - offset);
        }
예제 #2
0
            private static int GetValueLength(string input, int startIndex, out StringSegment value)
            {
                var current = startIndex;

                current++;
                current += HttpTokenParsingRules.GetWhitespaceLength(input, current);

                var valueLength = HttpTokenParsingRules.GetTokenLength(input, current);

                if (valueLength == 0)
                {
                    var result = HttpTokenParsingRules.GetQuotedStringLength(input, current, out valueLength);
                    if (result != HttpParseResult.Parsed)
                    {
                        value = default(StringSegment);
                        return(0);
                    }

                    value = new StringSegment(input, current + 1, valueLength - 2);
                }
                else
                {
                    value = new StringSegment(input, current, valueLength);
                }

                current += valueLength;
                current += HttpTokenParsingRules.GetWhitespaceLength(input, current);

                return(current - startIndex);
            }
예제 #3
0
        private static int GetSubtypeLength(string input, int offset, out StringSegment subType)
        {
            var current = offset;

            if (current < 0 || current >= input.Length || input[current] != '/')
            {
                subType = default(StringSegment);
                return(0);
            }

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

            var subtypeLength = HttpTokenParsingRules.GetTokenLength(input, current);

            if (subtypeLength == 0)
            {
                subType = default(StringSegment);
                return(0);
            }

            subType = new StringSegment(input, current, subtypeLength);

            current += subtypeLength;
            current += HttpTokenParsingRules.GetWhitespaceLength(input, current);

            return(current - offset);
        }
예제 #4
0
            private static int GetNameLength(string input, int startIndex, out StringSegment name)
            {
                var current = startIndex;

                current++; // skip ';'
                current += HttpTokenParsingRules.GetWhitespaceLength(input, current);

                var nameLength = HttpTokenParsingRules.GetTokenLength(input, current);

                if (nameLength == 0)
                {
                    name = default(StringSegment);
                    return(0);
                }

                name = new StringSegment(input, current, nameLength);

                current += nameLength;
                current += HttpTokenParsingRules.GetWhitespaceLength(input, current);

                return(current - startIndex);
            }