keyMatch function

bool keyMatch(
  1. String key1,
  2. String key2
)

keyMatch determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a . For example, '/foo/bar' matches '/foo/'

Implementation

bool keyMatch(String key1, String key2) {
  var i = key2.indexOf('*');
  if (i == -1) {
    return key1 == key2;
  }
  if (key1.length > i) {
    return key1.substring(0, i) == key2.substring(0, i);
  }
  return key1 == key2.substring(0, i);
}