1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
15 using System.Collections.Generic;
\r
18 internal static class DictionaryHelpers {
\r
20 public static IEnumerable<KeyValuePair<string, TValue>> FindKeysWithPrefix<TValue>(IDictionary<string, TValue> dictionary, string prefix) {
\r
21 TValue exactMatchValue;
\r
22 if (dictionary.TryGetValue(prefix, out exactMatchValue)) {
\r
23 yield return new KeyValuePair<string, TValue>(prefix, exactMatchValue);
\r
26 foreach (var entry in dictionary) {
\r
27 string key = entry.Key;
\r
29 if (key.Length <= prefix.Length) {
\r
33 if (!key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) {
\r
37 char charAfterPrefix = key[prefix.Length];
\r
38 switch (charAfterPrefix) {
\r
47 public static bool DoesAnyKeyHavePrefix<TValue>(IDictionary<string, TValue> dictionary, string prefix) {
\r
48 return FindKeysWithPrefix(dictionary, prefix).Any();
\r