/// <summary>Determines whether a string is valid <see cref="T:NMasters.Silverlight.Net.Http.Headers.StringWithQualityHeaderValue" /> information.</summary> /// <returns>Returns <see cref="T:System.Boolean" />.true if <paramref name="input" /> is valid <see cref="T:NMasters.Silverlight.Net.Http.Headers.StringWithQualityHeaderValue" /> information; otherwise, false.</returns> /// <param name="input">The string to validate.</param> /// <param name="parsedValue">The <see cref="T:NMasters.Silverlight.Net.Http.Headers.StringWithQualityHeaderValue" /> version of the string.</param> public static bool TryParse(string input, out StringWithQualityHeaderValue parsedValue) { object obj2; int index = 0; parsedValue = null; if (GenericHeaderParser.SingleValueStringWithQualityParser.TryParseValue(input, null, ref index, out obj2)) { parsedValue = (StringWithQualityHeaderValue) obj2; return true; } return false; }
private static bool TryReadQuality(string input, StringWithQualityHeaderValue result, ref int index) { int startIndex = index; if ((startIndex == input.Length) || ((input[startIndex] != 'q') && (input[startIndex] != 'Q'))) { return false; } startIndex++; startIndex += HttpRuleParser.GetWhitespaceLength(input, startIndex); if ((startIndex == input.Length) || (input[startIndex] != '=')) { return false; } startIndex++; startIndex += HttpRuleParser.GetWhitespaceLength(input, startIndex); if (startIndex == input.Length) { return false; } int length = HttpRuleParser.GetNumberLength(input, startIndex, true); if (length == 0) { return false; } double num3 = 0.0; if (!double.TryParse(input.Substring(startIndex, length), NumberStyles.AllowDecimalPoint, (IFormatProvider) NumberFormatInfo.InvariantInfo, out num3)) { return false; } if ((num3 < 0.0) || (num3 > 1.0)) { return false; } result.quality = new double?(num3); startIndex += length; startIndex += HttpRuleParser.GetWhitespaceLength(input, startIndex); index = startIndex; return true; }
private StringWithQualityHeaderValue(StringWithQualityHeaderValue source) { this.value = source.value; this.quality = source.quality; }
internal static int GetStringWithQualityLength(string input, int startIndex, out object parsedValue) { parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return 0; } int tokenLength = HttpRuleParser.GetTokenLength(input, startIndex); if (tokenLength == 0) { return 0; } StringWithQualityHeaderValue result = new StringWithQualityHeaderValue { value = input.Substring(startIndex, tokenLength) }; int num2 = startIndex + tokenLength; num2 += HttpRuleParser.GetWhitespaceLength(input, num2); if ((num2 == input.Length) || (input[num2] != ';')) { parsedValue = result; return (num2 - startIndex); } num2++; num2 += HttpRuleParser.GetWhitespaceLength(input, num2); if (!TryReadQuality(input, result, ref num2)) { return 0; } parsedValue = result; return (num2 - startIndex); }