static private GetNameValueListLength ( string input, int startIndex, char delimiter, ObjectCollection |
||
input | string | |
startIndex | int | |
delimiter | char | |
nameValueCollection | ObjectCollection |
|
return | int |
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); }
internal static int GetMediaTypeLength(string input, int startIndex, Func <MediaTypeHeaderValue> mediaTypeCreator, out MediaTypeHeaderValue parsedValue) { Contract.Requires(mediaTypeCreator != null); Contract.Requires(startIndex >= 0); parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return(0); } // Caller must remove leading whitespaces. If not, we'll return 0. string mediaType = null; int mediaTypeLength = MediaTypeHeaderValue.GetMediaTypeExpressionLength(input, startIndex, out mediaType); if (mediaTypeLength == 0) { return(0); } int current = startIndex + mediaTypeLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); MediaTypeHeaderValue mediaTypeHeader = null; // If we're not done and we have a parameter delimiter, then we have a list of parameters. if ((current < input.Length) && (input[current] == ';')) { mediaTypeHeader = mediaTypeCreator(); mediaTypeHeader.mediaType = mediaType; current++; // skip delimiter. int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';', mediaTypeHeader.Parameters); if (parameterLength == 0) { return(0); } parsedValue = mediaTypeHeader; return(current + parameterLength - startIndex); } // We have a media type without parameters. mediaTypeHeader = mediaTypeCreator(); mediaTypeHeader.mediaType = mediaType; parsedValue = mediaTypeHeader; return(current - startIndex); }
internal static int GetNameValueWithParametersLength(string input, int startIndex, out object parsedValue) { Contract.Requires(input != null); Contract.Requires(startIndex >= 0); parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return(0); } NameValueHeaderValue nameValue = null; int nameValueLength = NameValueHeaderValue.GetNameValueLength(input, startIndex, nameValueCreator, out nameValue); if (nameValueLength == 0) { return(0); } int current = startIndex + nameValueLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); NameValueWithParametersHeaderValue nameValueWithParameters = nameValue as NameValueWithParametersHeaderValue; Contract.Assert(nameValueWithParameters != null); // So far we have a valid name/value pair. Check if we have also parameters for the name/value pair. If // yes, parse parameters. E.g. something like "name=value; param1=value1; param2=value2". if ((current < input.Length) && (input[current] == ';')) { current++; // skip delimiter. int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';', nameValueWithParameters.Parameters); if (parameterLength == 0) { return(0); } parsedValue = nameValueWithParameters; return(current + parameterLength - startIndex); } // We have a name/value pair without parameters. parsedValue = nameValueWithParameters; return(current - startIndex); }
internal static int GetDispositionTypeLength(string input, int startIndex, out object parsedValue) { Contract.Requires(startIndex >= 0); parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return(0); } // Caller must remove leading whitespace. If not, we'll return 0. string dispositionType = null; int dispositionTypeLength = GetDispositionTypeExpressionLength(input, startIndex, out dispositionType); if (dispositionTypeLength == 0) { return(0); } int current = startIndex + dispositionTypeLength; current = current + HttpRuleParser.GetWhitespaceLength(input, current); ContentDispositionHeaderValue contentDispositionHeader = new ContentDispositionHeaderValue(); contentDispositionHeader._dispositionType = dispositionType; // If we're not done and we have a parameter delimiter, then we have a list of parameters. if ((current < input.Length) && (input[current] == ';')) { current++; // Skip delimiter. int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';', (ObjectCollection <NameValueHeaderValue>)contentDispositionHeader.Parameters); if (parameterLength == 0) { return(0); } parsedValue = contentDispositionHeader; return(current + parameterLength - startIndex); } // We have a ContentDisposition header without parameters. parsedValue = contentDispositionHeader; return(current - startIndex); }
internal static int GetMediaTypeLength( string input, int startIndex, Func <MediaTypeHeaderValue> mediaTypeCreator, out MediaTypeHeaderValue parsedValue) { parsedValue = (MediaTypeHeaderValue)null; if (string.IsNullOrEmpty(input) || startIndex >= input.Length) { return(0); } string mediaType = (string)null; int expressionLength = MediaTypeHeaderValue.GetMediaTypeExpressionLength(input, startIndex, out mediaType); if (expressionLength == 0) { return(0); } int startIndex1 = startIndex + expressionLength; int index = startIndex1 + HttpRuleParser.GetWhitespaceLength(input, startIndex1); if (index < input.Length && input[index] == ';') { MediaTypeHeaderValue mediaTypeHeaderValue = mediaTypeCreator(); mediaTypeHeaderValue._mediaType = mediaType; int startIndex2 = index + 1; int nameValueListLength = NameValueHeaderValue.GetNameValueListLength(input, startIndex2, ';', (ObjectCollection <NameValueHeaderValue>)mediaTypeHeaderValue.Parameters); if (nameValueListLength == 0) { return(0); } parsedValue = mediaTypeHeaderValue; return(startIndex2 + nameValueListLength - startIndex); } MediaTypeHeaderValue mediaTypeHeaderValue1 = mediaTypeCreator(); mediaTypeHeaderValue1._mediaType = mediaType; parsedValue = mediaTypeHeaderValue1; return(index - startIndex); }
internal static int GetDispositionTypeLength( string input, int startIndex, out object parsedValue) { parsedValue = (object)null; if (string.IsNullOrEmpty(input) || startIndex >= input.Length) { return(0); } string dispositionType = (string)null; int expressionLength = ContentDispositionHeaderValue.GetDispositionTypeExpressionLength(input, startIndex, out dispositionType); if (expressionLength == 0) { return(0); } int startIndex1 = startIndex + expressionLength; int index = startIndex1 + HttpRuleParser.GetWhitespaceLength(input, startIndex1); ContentDispositionHeaderValue dispositionHeaderValue = new ContentDispositionHeaderValue(); dispositionHeaderValue._dispositionType = dispositionType; if (index < input.Length && input[index] == ';') { int startIndex2 = index + 1; int nameValueListLength = NameValueHeaderValue.GetNameValueListLength(input, startIndex2, ';', (ObjectCollection <NameValueHeaderValue>)dispositionHeaderValue.Parameters); if (nameValueListLength == 0) { return(0); } parsedValue = (object)dispositionHeaderValue; return(startIndex2 + nameValueListLength - startIndex); } parsedValue = (object)dispositionHeaderValue; return(index - startIndex); }