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 ValueProviderUtil {
\r
20 // Given "foo.bar[baz].quux", this method will return:
\r
21 // - "foo.bar[baz].quux"
\r
25 public static IEnumerable<string> GetPrefixes(string key) {
\r
27 for (int i = key.Length - 1; i >= 0; i--) {
\r
31 yield return key.Substring(0, i);
\r
37 public static bool CollectionContainsPrefix(IEnumerable<string> collection, string prefix) {
\r
38 foreach (string key in collection) {
\r
40 if (prefix.Length == 0) {
\r
41 return true; // shortcut - non-null key matches empty prefix
\r
44 if (key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) {
\r
45 if (key.Length == prefix.Length) {
\r
46 return true; // exact match
\r
49 switch (key[prefix.Length]) {
\r
50 case '.': // known separator characters
\r
59 return false; // nothing found
\r