private static void CheckValidGetRangeItemListLength(string input, int startIndex, int expectedLength, params Tuple <long?, long?>[] expectedRanges) { List <RangeItemHeaderValue> ranges = new List <RangeItemHeaderValue>(); Assert.Equal(expectedLength, RangeItemHeaderValue.GetRangeItemListLength(input, startIndex, ranges)); Assert.Equal <int>(expectedRanges.Length, ranges.Count); for (int i = 0; i < expectedRanges.Length; i++) { Assert.Equal(expectedRanges[i].Item1, ranges[i].From); Assert.Equal(expectedRanges[i].Item2, ranges[i].To); } }
private static int GetRangeLength(StringSegment input, int startIndex, out RangeHeaderValue?parsedValue) { Contract.Requires(startIndex >= 0); parsedValue = null; if (StringSegment.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return(0); } // Parse the unit string: <unit> in '<unit>=<from1>-<to1>, <from2>-<to2>' var unitLength = HttpRuleParser.GetTokenLength(input, startIndex); if (unitLength == 0) { return(0); } RangeHeaderValue result = new RangeHeaderValue(); result._unit = input.Subsegment(startIndex, unitLength); var current = startIndex + unitLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); if ((current == input.Length) || (input[current] != '=')) { return(0); } current++; // skip '=' separator current = current + HttpRuleParser.GetWhitespaceLength(input, current); var rangesLength = RangeItemHeaderValue.GetRangeItemListLength(input, current, result.Ranges); if (rangesLength == 0) { return(0); } current = current + rangesLength; Contract.Assert(current == input.Length, "GetRangeItemListLength() should consume the whole string or fail."); parsedValue = result; return(current - startIndex); }
private static void CheckInvalidGetRangeItemListLength(string input, int startIndex) { List <RangeItemHeaderValue> ranges = new List <RangeItemHeaderValue>(); Assert.Equal(0, RangeItemHeaderValue.GetRangeItemListLength(input, startIndex, ranges)); }