main
 1//
 2//  StringPrefixMatcher.m
 3//  Kiwi
 4//
 5//  Created by Luke Redpath on 17/01/2011.
 6//  Copyright 2011 Allen Ding. All rights reserved.
 7//
 8
 9#import "KWStringPrefixMatcher.h"
10
11
12@implementation KWStringPrefixMatcher
13
14+ (id)matcherWithPrefix:(NSString *)aPrefix;
15{
16  return [[[self alloc] initWithPrefix:aPrefix] autorelease];
17}
18
19- (id)initWithPrefix:(NSString *)aPrefix;
20{
21  if ((self = [super init])) {
22    prefix = [aPrefix copy];
23  }
24  return self;
25}
26
27- (void)dealloc
28{
29  [prefix release];
30  [super dealloc];
31}
32
33- (BOOL)matches:(id)item
34{
35  if (![item respondsToSelector:@selector(hasPrefix:)])
36    return NO;
37
38  return [item hasPrefix:prefix];
39}
40
41- (NSString *)description
42{
43  return [NSString stringWithFormat:@"a string with prefix '%@'", prefix];
44}
45
46@end