KWStringPrefixMatcher.m 818 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #import "KWStringPrefixMatcher.h"
  9. @interface KWStringPrefixMatcher(){}
  10. @property (nonatomic, copy) NSString *prefix;
  11. @end
  12. @implementation KWStringPrefixMatcher
  13. + (id)matcherWithPrefix:(NSString *)aPrefix {
  14. return [[self alloc] initWithPrefix:aPrefix];
  15. }
  16. - (id)initWithPrefix:(NSString *)aPrefix {
  17. self = [super init];
  18. if (self) {
  19. _prefix = [aPrefix copy];
  20. }
  21. return self;
  22. }
  23. - (BOOL)matches:(id)item {
  24. if (![item respondsToSelector:@selector(hasPrefix:)])
  25. return NO;
  26. return [item hasPrefix:self.prefix];
  27. }
  28. - (NSString *)description {
  29. return [NSString stringWithFormat:@"a string with prefix '%@'", self.prefix];
  30. }
  31. @end