/// <summary> /// Parse a query string into its component key and value parts. /// </summary> /// <param name="queryString">The raw query string value, with or without the leading '?'.</param> /// <returns>A collection of parsed keys and values, null if there are no entries.</returns> public static Dictionary <string, StringValues>?ParseNullableQuery(string?queryString) { var accumulator = new KeyValueAccumulator(); var enumerable = new QueryStringEnumerable(queryString); foreach (var pair in enumerable) { accumulator.Append(pair.DecodeName().ToString(), pair.DecodeValue().ToString()); } if (!accumulator.HasValues) { return(null); } return(accumulator.GetResults()); }
internal static AdaptiveCapacityDictionary <string, StringValues>?ParseNullableQueryInternal(string?queryString) { if (string.IsNullOrEmpty(queryString) || (queryString.Length == 1 && queryString[0] == '?')) { return(null); } var accumulator = new KvpAccumulator(); var enumerable = new QueryStringEnumerable(queryString); foreach (var pair in enumerable) { accumulator.Append(pair.DecodeName().Span, pair.DecodeValue().Span); } return(accumulator.HasValues ? accumulator.GetResults() : null); }
private void ParseQuery( string queryString, out Dictionary <string, StringValues> processingCommands, out Dictionary <string, StringValues> otherCommands) { processingCommands = null; otherCommands = null; var accumulator = new KeyValueAccumulator(); var otherCommandAccumulator = new KeyValueAccumulator(); var enumerable = new QueryStringEnumerable(queryString); foreach (var pair in enumerable) { var key = pair.DecodeName().ToString(); var value = pair.DecodeValue().ToString(); if (_knownCommands.Contains(key)) { accumulator.Append(key, value); } else { otherCommandAccumulator.Append(key, value); } } if (accumulator.HasValues) { processingCommands = accumulator.GetResults(); } if (otherCommandAccumulator.HasValues) { otherCommands = otherCommandAccumulator.GetResults(); } }